module IHP.LoginSupport.Helper.View ( currentUser , currentUserId , currentUserOrNothing , currentAdmin , currentAdminOrNothing ) where import IHP.Prelude import IHP.Controller.Context import IHP.LoginSupport.Helper.Controller (CurrentUserRecord, CurrentAdminRecord) currentUser :: (?context :: ControllerContext, user ~ CurrentUserRecord, Typeable user) => user currentUser :: forall user. (?context::ControllerContext, user ~ CurrentUserRecord, Typeable user) => user currentUser = user -> Maybe user -> user forall a. a -> Maybe a -> a fromMaybe (Text -> user forall a. Text -> a error Text "Application.Helper.View.currentUser: Not logged in") Maybe user forall user. (?context::ControllerContext, user ~ CurrentUserRecord, Typeable user) => Maybe user currentUserOrNothing currentUserId :: forall user userId. (?context :: ControllerContext, HasField "id" user userId, Typeable user, user ~ CurrentUserRecord) => userId currentUserId :: forall user userId. (?context::ControllerContext, HasField "id" user userId, Typeable user, user ~ CurrentUserRecord) => userId currentUserId = (forall user. (?context::ControllerContext, user ~ CurrentUserRecord, Typeable user) => user currentUser @user).id currentUserOrNothing :: forall user. (?context :: ControllerContext, user ~ CurrentUserRecord, Typeable user) => Maybe user currentUserOrNothing :: forall user. (?context::ControllerContext, user ~ CurrentUserRecord, Typeable user) => Maybe user currentUserOrNothing = forall value. (?context::ControllerContext, Typeable value) => value fromFrozenContext @(Maybe user) currentAdmin :: (?context :: ControllerContext, admin ~ CurrentAdminRecord, Typeable admin) => admin currentAdmin :: forall admin. (?context::ControllerContext, admin ~ CurrentAdminRecord, Typeable admin) => admin currentAdmin = admin -> Maybe admin -> admin forall a. a -> Maybe a -> a fromMaybe (Text -> admin forall a. Text -> a error Text "Application.Helper.View.currentAdmin: Not logged in") Maybe admin forall admin. (?context::ControllerContext, admin ~ CurrentAdminRecord, Typeable admin) => Maybe admin currentAdminOrNothing currentAdminOrNothing :: forall admin. (?context :: ControllerContext, admin ~ CurrentAdminRecord, Typeable admin) => Maybe admin currentAdminOrNothing :: forall admin. (?context::ControllerContext, admin ~ CurrentAdminRecord, Typeable admin) => Maybe admin currentAdminOrNothing = forall value. (?context::ControllerContext, Typeable value) => value fromFrozenContext @(Maybe admin)