relocated commons to helper

This commit is contained in:
nek0 2014-12-28 00:30:53 +01:00
parent aaaedd4f15
commit 1d8adf6ebc
9 changed files with 42 additions and 68 deletions

View file

@ -1,7 +1,7 @@
module Handler.Admin where
import Import
import Handler.Commons
import Helper
getAdminR :: Handler Html
getAdminR = do

View file

@ -1,7 +1,7 @@
module Handler.AdminAlbumSettings where
import Import
import Handler.Commons
import Helper
import qualified Data.Text as T
import qualified Data.List as L
import System.FilePath

View file

@ -1,7 +1,7 @@
module Handler.AdminComments where
import Import
import Handler.Commons
import Helper
import Data.Maybe
import Data.Time
import System.Locale

View file

@ -1,7 +1,7 @@
module Handler.AdminMediumSettings where
import Import
import Handler.Commons
import Helper
import System.FilePath
import System.Directory
import Data.List (tail)

View file

@ -1,7 +1,7 @@
module Handler.AdminProfileSettings where
import Import
import Handler.Commons
import Helper
import qualified Data.Text as T
import qualified Data.List as L
import Data.Maybe

View file

@ -1,40 +0,0 @@
module Handler.Commons where
import Import
import Yesod
import Helper
import Data.String
loginIsAdmin :: IsString t => Handler (Either (t, Route App) ())
loginIsAdmin = do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
userId <- return $ getUserIdFromText tempUserId
user <- runDB $ getJust userId
case userAdmin user of
True ->
return $ Right ()
False ->
return $ Left ("You have no admin rights", HomeR)
Nothing ->
return $ Left ("You are not logged in", LoginR)
profileCheck :: IsString t => UserId -> Handler (Either (t, Route App) User)
profileCheck userId = do
tempUser <- runDB $ get userId
case tempUser of
Just user -> do
msu <- lookupSession "userId"
case msu of
Just tempLoginId -> do
loginId <- return $ getUserIdFromText tempLoginId
case loginId == userId of
True ->
return $ Right user
False ->
return $ Left ("You can only change your own profile settings", UserR $ userName user)
Nothing ->
return $ Left ("You nedd to be logged in to change settings", LoginR)
Nothing ->
return $ Left ("This user does not exist", HomeR)

View file

@ -1,7 +1,7 @@
module Handler.ProfileDelete where
import Import
import Handler.Commons
import Helper
import qualified Data.Text as T
import Data.Maybe
import qualified Data.List as L

View file

@ -1,7 +1,7 @@
module Handler.ProfileSettings where
import Import
import Handler.Commons
import Helper
getProfileSettingsR :: UserId -> Handler Html
getProfileSettingsR userId = do

View file

@ -1,24 +1,4 @@
module Helper
( getUserIdFromText
, extractKey
, fromHex
, fromHex'
, toHex
, makeRandomToken
, generateSalt
, tagField
, userField
, sendMail
, generateString
, removeItem
, acceptedTypes
, iso8601
, localTimeToZonedTime
, rfc822
, mediumStaticImageRoute
, mediumStaticThumbRoute
)
where
module Helper where
import Prelude
import Yesod.Static
@ -185,3 +165,37 @@ mediumStaticImageRoute medium =
mediumStaticThumbRoute :: Medium -> Route Static
mediumStaticThumbRoute medium =
StaticRoute (drop 2 $ T.splitOn "/" $ T.pack $ mediumThumb medium) []
loginIsAdmin :: IsString t => Handler (Either (t, Route App) ())
loginIsAdmin = do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
userId <- return $ getUserIdFromText tempUserId
user <- runDB $ getJust userId
case userAdmin user of
True ->
return $ Right ()
False ->
return $ Left ("You have no admin rights", HomeR)
Nothing ->
return $ Left ("You are not logged in", LoginR)
profileCheck :: IsString t => UserId -> Handler (Either (t, Route App) User)
profileCheck userId = do
tempUser <- runDB $ get userId
case tempUser of
Just user -> do
msu <- lookupSession "userId"
case msu of
Just tempLoginId -> do
loginId <- return $ getUserIdFromText tempLoginId
case loginId == userId of
True ->
return $ Right user
False ->
return $ Left ("You can only change your own profile settings", UserR $ userName user)
Nothing ->
return $ Left ("You nedd to be logged in to change settings", LoginR)
Nothing ->
return $ Left ("This user does not exist", HomeR)