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] []
|
newUser <- runDB $ selectFirst [ActivatorToken ==. token] []
|
||||||
case newUser of
|
case newUser of
|
||||||
Just (Entity aId activ) -> do
|
Just (Entity aId activ) -> do
|
||||||
|
namesakes <- runDB $ selectList [UserName ==. (userName $ activatorUser activ)] []
|
||||||
|
case namesakes == [] of
|
||||||
|
True -> do
|
||||||
-- putting user in active state
|
-- putting user in active state
|
||||||
uId <- runDB $ insert $ activatorUser activ
|
uId <- runDB $ insert $ activatorUser activ
|
||||||
runDB $ update uId [UserSalted =. salted]
|
runDB $ update uId [UserSalted =. salted]
|
||||||
-- create user directory
|
-- create user directory
|
||||||
liftIO $ createDirectoryIfMissing True $ "static" </> "data" </> (unpack $ extractKey uId)
|
liftIO $ createDirectoryIfMissing True $
|
||||||
|
"static" </> "data" </> (unpack $ extractKey uId)
|
||||||
-- cleanup
|
-- cleanup
|
||||||
runDB $ delete aId
|
runDB $ delete aId
|
||||||
runDB $ delete uTokenId
|
runDB $ delete uTokenId
|
||||||
|
@ -59,6 +63,11 @@ postActivateR token = do
|
||||||
setSession "userId" (extractKey uId)
|
setSession "userId" (extractKey uId)
|
||||||
welcomeLink <- ($ ProfileR uId) <$> getUrlRender
|
welcomeLink <- ($ ProfileR uId) <$> getUrlRender
|
||||||
returnJson ["welcome" .= welcomeLink]
|
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
|
Nothing -> do
|
||||||
returnJsonError "Invalid token"
|
returnJsonError "Invalid token"
|
||||||
False -> do
|
False -> do
|
||||||
|
|
Loading…
Reference in a new issue