generated from coulomb/repo-seed
- Sessions: replace raw authenticate/unsetSession with IHP login/logout/verifyPassword - Widgets/New, Widgets/Show: consolidate imports to Web.View.Prelude - Widgets/Show: unwrap Id newtype for childrenOf comparison, Double → Scientific in renderSignalValue Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
1.1 KiB
Haskell
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
|
|
currentUserOrNothing @User >>= \case
|
|
Just user -> logout user >> redirectTo NewSessionAction
|
|
Nothing -> redirectTo NewSessionAction
|
|
|
|
instance SessionsControllerConfig User
|