made user ident modifyable

This commit is contained in:
nek0 2015-10-26 18:33:34 +01:00
parent ffd327e077
commit fdfe41ac4a
4 changed files with 31 additions and 13 deletions

View file

@ -39,9 +39,15 @@ postNewUserR = do
$ newUserForm secs
case res of
FormSuccess user -> do
runDB $ insert_ user
setMessageI MsgUserCreated
redirect HomeR
namesakes <- runDB $ selectList [UserIdent ==. userIdent user] []
if null namesakes
then do
runDB $ insert_ user
setMessageI MsgUserCreated
redirect HomeR
else do
setMessageI MsgUserIdentNotUnique
redirect NewUserR
_ -> do
setMessageI MsgUserNotCreated
redirect NewUserR
@ -60,7 +66,8 @@ newUserForm secs = User
optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents
data UserConf = UserConf
{ userConfEmail :: Maybe Text
{ userConfIdent :: Text
, userConfEmail :: Maybe Text
, userConfAvatar :: Maybe AvatarId
, userConfBarcode :: Maybe [Text]
}
@ -95,14 +102,21 @@ postModifyUserR uId = do
$ modifyUserForm user bs
case res of
FormSuccess uc -> do
runDB $ update uId
[ UserEmail =. userConfEmail uc
, UserAvatar =. userConfAvatar uc
]
liftIO $ notify user (userConfEmail uc)
handleBarcodes (Left uId) (fromMaybe [] $ userConfBarcode uc)
setMessageI MsgUserEdited
redirect $ SelectR uId
namesakes <- runDB $ selectList [UserIdent ==. userConfIdent uc] []
if null namesakes
then do
runDB $ update uId
[ UserIdent =. userConfIdent uc
, UserEmail =. userConfEmail uc
, UserAvatar =. userConfAvatar uc
]
liftIO $ notify user (userConfEmail uc)
handleBarcodes (Left uId) (fromMaybe [] $ userConfBarcode uc)
setMessageI MsgUserEdited
redirect $ SelectR uId
else do
setMessageI MsgUserIdentNotUnique
redirect $ ModifyUserR uId
_ -> do
setMessageI MsgUserNotEdited
redirect $ SelectR uId
@ -112,7 +126,8 @@ postModifyUserR uId = do
modifyUserForm :: User -> [Text] -> AForm Handler UserConf
modifyUserForm user bs = UserConf
<$> aopt emailField (bfs MsgEmailNotify) (Just $ userEmail user)
<$> areq textField (bfs MsgName) (Just $ userIdent user)
<*> aopt emailField (bfs MsgEmailNotify) (Just $ userEmail user)
<*> aopt (selectField avatars) (bfs MsgSelectAvatar) (Just $ userAvatar user)
<*> aopt barcodeField (bfs MsgBarcodeField) (Just $ Just bs)
<* bootstrapSubmit (msgToBSSubmit MsgSubmit)

View file

@ -141,3 +141,4 @@ BuyValue: K placení
CustomerId: Kód zákazníka
TotalCrates: Celkový počet přepravek
Modify: upravit
UserIdentNotUnique: Uživatelské jméno není jedinečný

View file

@ -141,3 +141,4 @@ BuyValue: Zahlbetrag
CustomerId: Kundennummer
TotalCrates: Gesamtanzahl Kästen
Modify: bearbeiten
UserIdentNotUnique: Benutzername ist nicht einzigartig

View file

@ -141,3 +141,4 @@ BuyValue: Payment amount
CustomerId: Customer id
TotalCrates: Total crates
Modify: modify
UserIdentNotUnique: Username is not unique