start building controller module

This commit is contained in:
nek0 2022-07-24 16:50:06 +02:00
parent 8cf5edb0bb
commit 9557b613f1

30
src/Control/Settings.hs Normal file
View file

@ -0,0 +1,30 @@
{-# LANGUAGE OverloadedStrings #-}
module Control.Settings where
import Control.Monad.Reader
import Servant
-- internal imports
import Types
import Model.Settings
import Util (checkCapability)
getSettings
:: Maybe (Int, AuthMethod)
-> MateHandler Settings
getSettings Nothing = do
throwError $ err401
{ errBody = "No authentication present"
}
getSettings (Just (uid, method)) = do
isManager <- checkCapability uid roleCanManageSettings
if method `elem` [PrimaryPass, ChallengeResponse] && isManager
then do
conn <- asks rsConnection
selectSettings conn
else
throwError $ err401
{ errBody = "Wrong Authentication present"
}