2019-08-14 16:04:16 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Control.Auth where
|
|
|
|
|
|
|
|
import Servant
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types
|
|
|
|
import Model
|
|
|
|
|
|
|
|
authGet :: Int -> MateHandler AuthInfo
|
2019-09-07 00:48:16 +00:00
|
|
|
authGet uid =
|
|
|
|
getUserAuthInfo uid
|
2019-08-14 16:04:16 +00:00
|
|
|
|
|
|
|
authSend :: AuthRequest -> MateHandler AuthResult
|
|
|
|
authSend = processAuthRequest
|
|
|
|
|
|
|
|
authLogout :: Maybe Int -> Int -> MateHandler ()
|
|
|
|
authLogout (Just muid) luid = do
|
|
|
|
if muid == luid
|
|
|
|
then
|
|
|
|
processLogout luid
|
|
|
|
else
|
2019-09-11 11:54:18 +00:00
|
|
|
throwError $ err401
|
|
|
|
{ errBody = "Unauthorized access"
|
2019-08-14 16:04:16 +00:00
|
|
|
}
|
|
|
|
authLogout Nothing _ = do
|
2019-09-11 11:54:18 +00:00
|
|
|
throwError $ err401
|
|
|
|
{ errBody = "Unauthorized access"
|
2019-08-14 16:04:16 +00:00
|
|
|
}
|