helper module created
This commit is contained in:
parent
6cf9bebeed
commit
8bbe4d5d02
3 changed files with 17 additions and 8 deletions
|
@ -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
12
Helper.hs
Normal 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
|
|
@ -17,6 +17,7 @@ import Settings.StaticFiles as Import
|
|||
|
||||
-- custom imports
|
||||
|
||||
import Helper as Import
|
||||
|
||||
-- end custom imports
|
||||
|
||||
|
|
Loading…
Reference in a new issue