eidolon/Handler/Activate.hs
2014-08-18 03:09:03 +02:00

20 lines
584 B
Haskell

module Handler.Activate where
import Import as I
import Data.Text
import System.Directory
import System.FilePath
getActivateR :: Text -> Handler Html
getActivateR token = do
t <- runDB $ selectFirst [TokenToken ==. token] []
case t of
Nothing -> do
setMessage "Invalid Token!"
redirect $ HomeR
Just x -> do
userId <- runDB $ insert $ tokenUser (entityVal x)
liftIO $ createDirectoryIfMissing True $ "static" </> "data" </> (unpack $ extractKey userId)
runDB $ delete (entityKey x)
setMessage $ "User activated"
redirect $ HomeR