helper module created

This commit is contained in:
nek0 2014-08-14 00:52:57 +02:00
parent 6cf9bebeed
commit 8bbe4d5d02
3 changed files with 17 additions and 8 deletions

View file

@ -21,25 +21,21 @@ getUploadR = do
msu <- lookupSession "userId" msu <- lookupSession "userId"
case msu of case msu of
Just tempUserId -> do Just tempUserId -> do
userId <- lift $ getUserIdFromText tempUserId userId <- lift $ pure $ getUserIdFromText tempUserId
(uploadWidget, enctype) <- generateFormPost (uploadForm userId) (uploadWidget, enctype) <- generateFormPost (uploadForm $ Key userId)
defaultLayout $ do defaultLayout $ do
$(widgetFile "upload") $(widgetFile "upload")
Nothing -> do Nothing -> do
setMessage $ [shamlet|<pre>You need to be logged in|] setMessage $ [shamlet|<pre>You need to be logged in|]
redirect $ LoginR redirect $ LoginR
--getUserIdFromText :: Text -> UserId
getUserIdFromText tempUserId =
Key $ PersistInt64 $ fromIntegral $ read $ unpack tempUserId
postUploadR :: Handler Html postUploadR :: Handler Html
postUploadR = do postUploadR = do
msu <- lookupSession "userId" msu <- lookupSession "userId"
case msu of case msu of
Just tempUserId -> do Just tempUserId -> do
userId <- lift $ getUserIdFromText tempUserId userId <- lift $ pure $ getUserIdFromText tempUserId
((result, uploadWidget), enctype) <- runFormPost (uploadForm userId) ((result, uploadWidget), enctype) <- runFormPost (uploadForm $ Key userId)
case result of case result of
FormSuccess temp -> do FormSuccess temp -> do
path <- writeOnDrive $ tempMediumFile temp path <- writeOnDrive $ tempMediumFile temp

12
Helper.hs Normal file
View file

@ -0,0 +1,12 @@
module Helper
( getUserIdFromText
)
where
import Prelude
import Data.Text
import Database.Persist.Types
getUserIdFromText :: Text -> PersistValue
getUserIdFromText tempUserId =
PersistInt64 $ fromIntegral $ read $ unpack tempUserId

View file

@ -17,6 +17,7 @@ import Settings.StaticFiles as Import
-- custom imports -- custom imports
import Helper as Import
-- end custom imports -- end custom imports