Files
inter-hub/Web/Controller/Sessions.hs
Bernd Worsch 58cad31042 fix(WP-0017/E1): Layer 2 + Sessions fixes
- CrossHubPropagation: IHP.Prelude.head returns Maybe a; use List.head
  (Data.List.head, already imported qualified) for non-empty-guarded lists
- Sessions: currentUserOrNothing is pure Maybe, not IO; use case...of instead of >>=

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 08:37:04 +00:00

35 lines
1.1 KiB
Haskell

module Web.Controller.Sessions where
import Web.Types
import Web.View.Sessions.New
import Generated.Types
import IHP.LoginSupport.Helper.Controller
import IHP.AuthSupport.Controller.Sessions (SessionsControllerConfig (..))
import IHP.AuthSupport.Authentication (verifyPassword)
import IHP.Prelude
import IHP.ControllerPrelude
instance Controller SessionsController where
action NewSessionAction = do
let user = newRecord @User
render NewView { user }
action CreateSessionAction = do
maybeUser <- query @User
|> filterWhere (#email, param "email")
|> fetchOneOrNothing
case maybeUser of
Just user | verifyPassword user (param "password") -> do
login user
redirectTo HubsAction
_ -> do
setErrorMessage "Invalid email or password"
redirectTo NewSessionAction
action DeleteSessionAction = do
case currentUserOrNothing @User of
Just user -> logout user >> redirectTo NewSessionAction
Nothing -> redirectTo NewSessionAction
instance SessionsControllerConfig User