cought case of double usernames pending activation
This commit is contained in:
parent
a7589cd494
commit
12a6595b5d
1 changed files with 21 additions and 12 deletions
|
@ -47,11 +47,15 @@ postActivateR token = do
|
|||
newUser <- runDB $ selectFirst [ActivatorToken ==. token] []
|
||||
case newUser of
|
||||
Just (Entity aId activ) -> do
|
||||
namesakes <- runDB $ selectList [UserName ==. (userName $ activatorUser activ)] []
|
||||
case namesakes == [] of
|
||||
True -> do
|
||||
-- putting user in active state
|
||||
uId <- runDB $ insert $ activatorUser activ
|
||||
runDB $ update uId [UserSalted =. salted]
|
||||
-- create user directory
|
||||
liftIO $ createDirectoryIfMissing True $ "static" </> "data" </> (unpack $ extractKey uId)
|
||||
liftIO $ createDirectoryIfMissing True $
|
||||
"static" </> "data" </> (unpack $ extractKey uId)
|
||||
-- cleanup
|
||||
runDB $ delete aId
|
||||
runDB $ delete uTokenId
|
||||
|
@ -59,6 +63,11 @@ postActivateR token = do
|
|||
setSession "userId" (extractKey uId)
|
||||
welcomeLink <- ($ ProfileR uId) <$> getUrlRender
|
||||
returnJson ["welcome" .= welcomeLink]
|
||||
False -> do
|
||||
-- cleanup
|
||||
runDB $ delete aId
|
||||
runDB $ delete uTokenId
|
||||
returnJsonError "Somebody already activated your username. Your token has been deleted"
|
||||
Nothing -> do
|
||||
returnJsonError "Invalid token"
|
||||
False -> do
|
||||
|
|
Loading…
Reference in a new issue