Safe Haskell | None |
---|
Synopsis
- currentUser :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user, user ~ CurrentUserRecord) => user
- currentUserOrNothing :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user, user ~ CurrentUserRecord) => Maybe user
- currentUserId :: (?context :: ControllerContext, HasNewSessionUrl user, HasField "id" user userId, Typeable user, user ~ CurrentUserRecord) => userId
- ensureIsUser :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user, user ~ CurrentUserRecord) => IO ()
- class HasNewSessionUrl (user :: k)
- currentAdmin :: (?context :: ControllerContext, HasNewSessionUrl admin, Typeable admin, admin ~ CurrentAdminRecord) => admin
- currentAdminOrNothing :: (?context :: ControllerContext, HasNewSessionUrl admin, Typeable admin, admin ~ CurrentAdminRecord) => Maybe admin
- currentAdminId :: (?context :: ControllerContext, HasNewSessionUrl admin, HasField "id" admin adminId, Typeable admin, admin ~ CurrentAdminRecord) => adminId
- ensureIsAdmin :: (?context :: ControllerContext, HasNewSessionUrl admin, Typeable admin, admin ~ CurrentAdminRecord) => IO ()
- login :: (?context :: ControllerContext, KnownSymbol (GetModelName user), HasField "id" user id, Show id) => user -> IO ()
- sessionKey :: KnownSymbol (GetModelName user) => ByteString
- logout :: (?context :: ControllerContext, KnownSymbol (GetModelName user)) => user -> IO ()
- type family CurrentUserRecord
- type family CurrentAdminRecord
- module IHP.AuthSupport.Authentication
- enableRowLevelSecurityIfLoggedIn :: (?context :: ControllerContext, Typeable CurrentUserRecord, HasNewSessionUrl CurrentUserRecord, HasField "id" CurrentUserRecord userId, ToField userId) => IO ()
- currentRoleOrNothing :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user) => Maybe user
- currentRole :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user) => user
- currentRoleId :: (?context :: ControllerContext, HasNewSessionUrl user, HasField "id" user userId, Typeable user) => userId
- ensureIsRole :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user) => IO ()
Documentation
currentUser :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user, user ~ CurrentUserRecord) => user Source #
currentUserOrNothing :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user, user ~ CurrentUserRecord) => Maybe user Source #
currentUserId :: (?context :: ControllerContext, HasNewSessionUrl user, HasField "id" user userId, Typeable user, user ~ CurrentUserRecord) => userId Source #
ensureIsUser :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user, user ~ CurrentUserRecord) => IO () Source #
class HasNewSessionUrl (user :: k) Source #
currentAdmin :: (?context :: ControllerContext, HasNewSessionUrl admin, Typeable admin, admin ~ CurrentAdminRecord) => admin Source #
currentAdminOrNothing :: (?context :: ControllerContext, HasNewSessionUrl admin, Typeable admin, admin ~ CurrentAdminRecord) => Maybe admin Source #
currentAdminId :: (?context :: ControllerContext, HasNewSessionUrl admin, HasField "id" admin adminId, Typeable admin, admin ~ CurrentAdminRecord) => adminId Source #
ensureIsAdmin :: (?context :: ControllerContext, HasNewSessionUrl admin, Typeable admin, admin ~ CurrentAdminRecord) => IO () Source #
login :: (?context :: ControllerContext, KnownSymbol (GetModelName user), HasField "id" user id, Show id) => user -> IO () Source #
Log's in a user
Examples:
action ExampleAction = do user <- query @User |> fetchOne login user redirectToPath "/"
sessionKey :: KnownSymbol (GetModelName user) => ByteString Source #
logout :: (?context :: ControllerContext, KnownSymbol (GetModelName user)) => user -> IO () Source #
Log's out a user
Example:
action LogoutAction = do let user = currentUser logout user redirectToPath "/"
type family CurrentUserRecord Source #
type family CurrentAdminRecord Source #
enableRowLevelSecurityIfLoggedIn :: (?context :: ControllerContext, Typeable CurrentUserRecord, HasNewSessionUrl CurrentUserRecord, HasField "id" CurrentUserRecord userId, ToField userId) => IO () Source #
After this call the security policies defined in your Schema.sql will be applied to the controller actions called after this
Example:
instance InitControllerContext WebApplication where initContext = do initAuthentication @User enableRowLevelSecurityIfLoggedIn
Let's assume we have a policy defined in our Schema.sql that only allows users to see and edit rows in the projects table that have projects.user_id = current_user_id
:
CREATE POLICY "Users can manage their projects" ON projects USING (user_id = ihp_user_id()) WITH CHECK (user_id = ihp_user_id());
Now any database queries to our projects
table will have this policy applied.
E.g. this action will now only show the users projects, even though no explicit filterWhere (#userId, currentUserId)
is specified on the query:
action ProjectsAction = do projects <- query @Project |> fetch
currentRoleOrNothing :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user) => Maybe user Source #
currentRole :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user) => user Source #
currentRoleId :: (?context :: ControllerContext, HasNewSessionUrl user, HasField "id" user userId, Typeable user) => userId Source #
ensureIsRole :: (?context :: ControllerContext, HasNewSessionUrl user, Typeable user) => IO () Source #