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"
case msu of
Just tempUserId -> do
userId <- lift $ getUserIdFromText tempUserId
(uploadWidget, enctype) <- generateFormPost (uploadForm userId)
userId <- lift $ pure $ getUserIdFromText tempUserId
(uploadWidget, enctype) <- generateFormPost (uploadForm $ Key userId)
defaultLayout $ do
$(widgetFile "upload")
Nothing -> do
setMessage $ [shamlet|<pre>You need to be logged in|]
redirect $ LoginR
--getUserIdFromText :: Text -> UserId
getUserIdFromText tempUserId =
Key $ PersistInt64 $ fromIntegral $ read $ unpack tempUserId
postUploadR :: Handler Html
postUploadR = do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
userId <- lift $ getUserIdFromText tempUserId
((result, uploadWidget), enctype) <- runFormPost (uploadForm userId)
userId <- lift $ pure $ getUserIdFromText tempUserId
((result, uploadWidget), enctype) <- runFormPost (uploadForm $ Key userId)
case result of
FormSuccess temp -> do
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
import Helper as Import
-- end custom imports