refactor(auth): UserConversionException -> DecodeUserException

This commit is contained in:
Sarah Vaupel 2024-03-08 10:40:49 +01:00
parent c9fa627651
commit a2903da109
3 changed files with 32 additions and 33 deletions

View File

@ -103,14 +103,14 @@ PWHashLoginTitle: Spezieller Funktionsnutzer Login
PWHashLoginNote: Verwenden Sie dieses Formular nur, wenn Sie explizit dazu aufgefordert wurden. Alle anderen sollten das andere Login Formular verwenden!
DummyLoginTitle: Development-Login
InternalLoginError: Interner Fehler beim Login
UserInvalidIdent: Konnte anhand des Fraport Büko-Logins keine eindeutige Identifikation ermitteln
UserInvalidEmail: Konnte anhand des Fraport Büko-Logins keine E-Mail-Addresse ermitteln
UserInvalidDisplayName: Konnte anhand des Fraport Büko-Logins keinen vollen Namen ermitteln
UserInvalidGivenName: Konnte anhand des Fraport Büko-Logins keinen Vornamen ermitteln
UserInvalidSurname: Konnte anhand des Fraport Büko-Logins keinen Nachname ermitteln
UserInvalidTitle: Konnte anhand des Fraport Büko-Logins keinen akademischen Titel ermitteln
UserInvalidFeaturesOfStudy parseErr@Text: Konnte anhand des Fraport Büko-Logins keine Studiengänge ermitteln
UserInvalidAssociatedSchools parseErr@Text: Konnte anhand des Fraport Büko-Logins keine Bereiche ermitteln
DecodeUserInvalidIdent: Konnte anhand des Fraport Büko-Logins keine eindeutige Identifikation ermitteln
DecodeUserInvalidEmail: Konnte anhand des Fraport Büko-Logins keine E-Mail-Addresse ermitteln
DecodeUserInvalidDisplayName: Konnte anhand des Fraport Büko-Logins keinen vollen Namen ermitteln
DecodeUserInvalidGivenName: Konnte anhand des Fraport Büko-Logins keinen Vornamen ermitteln
DecodeUserInvalidSurname: Konnte anhand des Fraport Büko-Logins keinen Nachname ermitteln
DecodeUserInvalidTitle: Konnte anhand des Fraport Büko-Logins keinen akademischen Titel ermitteln
DecodeUserInvalidFeaturesOfStudy parseErr@Text: Konnte anhand des Fraport Büko-Logins keine Studiengänge ermitteln
DecodeUserInvalidAssociatedSchools parseErr@Text: Konnte anhand des Fraport Büko-Logins keine Bereiche ermitteln
InvalidCredentialsADNoSuchObject: Benutzereintrag existiert nicht
InvalidCredentialsADLogonFailure: Ungültiges Passwort
InvalidCredentialsADAccountRestriction: Beschränkungen des Fraport Accounts verhindern Login

View File

@ -104,14 +104,14 @@ PWHashLoginTitle: Special function user login
PWHashLoginNote: Only use this login form if you have received special instructions to do so. All others should use the other login field.
DummyLoginTitle: Development login
InternalLoginError: Internal error during login
UserInvalidIdent: Could not determine unique identification during Fraport Büko login
UserInvalidEmail: Could not determine email address during Fraport Büko login
UserInvalidDisplayName: Could not determine display name during Fraport Büko login
UserInvalidGivenName: Could not determine given name during Fraport Büko login
UserInvalidSurname: Could not determine surname during Fraport Büko login
UserInvalidTitle: Could not determine title during Fraport Büko login
UserInvalidFeaturesOfStudy parseErr: Could not determine features of study during Fraport Büko login
UserInvalidAssociatedSchools parseErr: Could not determine associated departments during Fraport Büko login
DecodeUserInvalidIdent: Could not determine unique identification during Fraport Büko login
DecodeUserInvalidEmail: Could not determine email address during Fraport Büko login
DecodeUserInvalidDisplayName: Could not determine display name during Fraport Büko login
DecodeUserInvalidGivenName: Could not determine given name during Fraport Büko login
DecodeUserInvalidSurname: Could not determine surname during Fraport Büko login
DecodeUserInvalidTitle: Could not determine title during Fraport Büko login
DecodeUserInvalidFeaturesOfStudy parseErr: Could not determine features of study during Fraport Büko login
DecodeUserInvalidAssociatedSchools parseErr: Could not determine associated departments during Fraport Büko login
InvalidCredentialsADNoSuchObject: User entry does not exist
InvalidCredentialsADLogonFailure: Invalid password
InvalidCredentialsADAccountRestriction: Restrictions on your Fraport account prevent a login

View File

@ -7,7 +7,7 @@ module Foundation.Yesod.Auth
, userLookupAndUpsert
, upsertUser
, decodeUserTest
, UserConversionException(..)
, DecodeUserException(..)
, updateUserLanguage
) where
@ -89,10 +89,10 @@ authenticate creds@Creds{..} = liftHandler . runDB . withReaderT projectBackend
$logErrorS "FetchUserException" $ tshow err
mr <- getMessageRender
excRecovery . ServerError $ mr MsgInternalLoginError
, C.Handler $ \(cExc :: UserConversionException) -> do
$logErrorS "Auth" $ tshow cExc
, C.Handler $ \(dExc :: DecodeUserException) -> do
$logErrorS "Auth" $ tshow dExc
mr <- getMessageRender
excRecovery . ServerError $ mr cExc
excRecovery . ServerError $ mr dExc
]
acceptExisting :: SqlPersistT (HandlerFor UniWorX) (AuthenticationResult UniWorX)
@ -132,16 +132,15 @@ authenticate creds@Creds{..} = liftHandler . runDB . withReaderT projectBackend
-> acceptExisting
-- TODO: rename to DecodeUserException (associate with function!)
data UserConversionException
= UserInvalidIdent
| UserInvalidEmail
| UserInvalidDisplayName
| UserInvalidGivenName
| UserInvalidSurname
| UserInvalidTitle
| UserInvalidFeaturesOfStudy Text
| UserInvalidAssociatedSchools Text
data DecodeUserException
= DecodeUserInvalidIdent
| DecodeUserInvalidEmail
| DecodeUserInvalidDisplayName
| DecodeUserInvalidGivenName
| DecodeUserInvalidSurname
| DecodeUserInvalidTitle
| DecodeUserInvalidFeaturesOfStudy Text
| DecodeUserInvalidAssociatedSchools Text
deriving (Eq, Ord, Read, Show, Generic)
deriving anyclass (Exception)
@ -304,7 +303,7 @@ decodeUser now UserDefaultConf{..} upsertData = do
, Just ldapPrimaryKey'' <- assertM' (not . Text.null) $ Text.strip ldapPrimaryKey'
-> return $ CI.mk ldapPrimaryKey''
| otherwise
-> throwM UserInvalidIdent
-> throwM DecodeUserInvalidIdent
let
(azureSurname, azureFirstName, azureDisplayName, azureEmail, azureTelephone, azureMobile, azureLanguages)
@ -437,7 +436,7 @@ decodeUserTest :: ( MonadHandler m
, MonadCatch m
)
=> NonEmpty UpsertUserData
-> m (Either UserConversionException (User, [Update User]))
-> m (Either DecodeUserException (User, [Update User]))
decodeUserTest decodeData = do
now <- liftIO getCurrentTime
userDefaultConf <- getsYesod $ view _appUserDefaults
@ -495,4 +494,4 @@ updateUserLanguage Nothing = runMaybeT $ do
setRegisteredCookie CookieLang lang
return lang
embedRenderMessage ''UniWorX ''UserConversionException id
embedRenderMessage ''UniWorX ''DecodeUserException id