cought case of double usernames pending activation

This commit is contained in:
nek0 2014-12-06 14:00:31 +01:00
parent a7589cd494
commit 12a6595b5d

View file

@ -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