eidolon/Handler/NewAlbum.hs

41 lines
1.2 KiB
Haskell
Raw Normal View History

2014-08-13 22:49:37 +00:00
module Handler.NewAlbum where
import Import
2014-08-14 00:26:02 +00:00
import Data.Text
import System.Directory
import System.FilePath
2014-08-13 22:49:37 +00:00
getNewAlbumR :: Handler Html
2014-08-14 00:26:02 +00:00
getNewAlbumR = do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
userId <- lift $ pure $ getUserIdFromText tempUserId
(albumWidget, enctype) <- generateFormPost (albumForm $ Key userId)
defaultLayout $ do
$(widgetFile "newAlbum")
Nothing -> do
setMessage $ [shamlet|<pre>You need to be lgged in|]
redirect $ LoginR
2014-08-13 22:49:37 +00:00
postNewAlbumR :: Handler Html
2014-08-14 00:26:02 +00:00
postNewAlbumR = do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
userId <- lift $ pure $ getUserIdFromText tempUserId
((result, albumWidget), enctype) <- runFormPost (albumForm $ Key userId)
case result of
FormSuccess album -> do
albumId <- runDB $ insert album
2014-08-14 01:05:02 +00:00
liftIO $ createDirectory $ "data" </> (unpack $ extractKey $ Key userId) </> (unpack $ extractKey albumId)
2014-08-14 00:26:02 +00:00
setMessage $ [shamlet|<pre>Album successfully created|]
redirect $ ProfileR $ Key userId
albumForm :: UserId -> Form Album
albumForm userId = renderDivs $ Album
<$> areq textField "Title" Nothing
<*> pure userId
<*> pure []
2014-08-15 11:24:14 +00:00
<*> pure Nothing