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,18 +47,27 @@ 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
-- putting user in active state namesakes <- runDB $ selectList [UserName ==. (userName $ activatorUser activ)] []
uId <- runDB $ insert $ activatorUser activ case namesakes == [] of
runDB $ update uId [UserSalted =. salted] True -> do
-- create user directory -- putting user in active state
liftIO $ createDirectoryIfMissing True $ "static" </> "data" </> (unpack $ extractKey uId) uId <- runDB $ insert $ activatorUser activ
-- cleanup runDB $ update uId [UserSalted =. salted]
runDB $ delete aId -- create user directory
runDB $ delete uTokenId liftIO $ createDirectoryIfMissing True $
-- login and redirect "static" </> "data" </> (unpack $ extractKey uId)
setSession "userId" (extractKey uId) -- cleanup
welcomeLink <- ($ ProfileR uId) <$> getUrlRender runDB $ delete aId
returnJson ["welcome" .= welcomeLink] runDB $ delete uTokenId
-- login and redirect
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 Nothing -> do
returnJsonError "Invalid token" returnJsonError "Invalid token"
False -> do False -> do