2014-08-12 12:42:25 +00:00
|
|
|
module Handler.Activate where
|
|
|
|
|
|
|
|
import Import as I
|
2014-08-14 00:24:28 +00:00
|
|
|
import Data.Text
|
|
|
|
import System.Directory
|
|
|
|
import System.FilePath
|
2014-08-12 12:42:25 +00:00
|
|
|
|
2014-08-12 21:45:33 +00:00
|
|
|
getActivateR :: Text -> Handler Html
|
2014-08-12 12:42:25 +00:00
|
|
|
getActivateR token = do
|
2014-08-13 16:16:31 +00:00
|
|
|
t <- runDB $ selectFirst [TokenToken ==. token] []
|
2014-08-12 12:42:25 +00:00
|
|
|
case t of
|
2014-08-13 16:16:31 +00:00
|
|
|
Nothing -> do
|
2014-08-15 13:47:16 +00:00
|
|
|
setMessage "Invalid Token!"
|
2014-08-12 12:42:25 +00:00
|
|
|
redirect $ HomeR
|
2014-08-13 16:16:31 +00:00
|
|
|
Just x -> do
|
2014-08-14 00:24:28 +00:00
|
|
|
userId <- runDB $ insert $ tokenUser (entityVal x)
|
2014-08-18 01:09:03 +00:00
|
|
|
liftIO $ createDirectoryIfMissing True $ "static" </> "data" </> (unpack $ extractKey userId)
|
2014-08-17 21:00:35 +00:00
|
|
|
runDB $ delete (entityKey x)
|
2014-08-15 13:47:16 +00:00
|
|
|
setMessage $ "User activated"
|
2014-08-12 12:42:25 +00:00
|
|
|
redirect $ HomeR
|