made user ident modifyable
This commit is contained in:
parent
ffd327e077
commit
fdfe41ac4a
4 changed files with 31 additions and 13 deletions
|
@ -39,9 +39,15 @@ postNewUserR = do
|
||||||
$ newUserForm secs
|
$ newUserForm secs
|
||||||
case res of
|
case res of
|
||||||
FormSuccess user -> do
|
FormSuccess user -> do
|
||||||
runDB $ insert_ user
|
namesakes <- runDB $ selectList [UserIdent ==. userIdent user] []
|
||||||
setMessageI MsgUserCreated
|
if null namesakes
|
||||||
redirect HomeR
|
then do
|
||||||
|
runDB $ insert_ user
|
||||||
|
setMessageI MsgUserCreated
|
||||||
|
redirect HomeR
|
||||||
|
else do
|
||||||
|
setMessageI MsgUserIdentNotUnique
|
||||||
|
redirect NewUserR
|
||||||
_ -> do
|
_ -> do
|
||||||
setMessageI MsgUserNotCreated
|
setMessageI MsgUserNotCreated
|
||||||
redirect NewUserR
|
redirect NewUserR
|
||||||
|
@ -60,7 +66,8 @@ newUserForm secs = User
|
||||||
optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents
|
optionsPairs $ map (\ent -> ((avatarIdent $ entityVal ent), entityKey ent)) ents
|
||||||
|
|
||||||
data UserConf = UserConf
|
data UserConf = UserConf
|
||||||
{ userConfEmail :: Maybe Text
|
{ userConfIdent :: Text
|
||||||
|
, userConfEmail :: Maybe Text
|
||||||
, userConfAvatar :: Maybe AvatarId
|
, userConfAvatar :: Maybe AvatarId
|
||||||
, userConfBarcode :: Maybe [Text]
|
, userConfBarcode :: Maybe [Text]
|
||||||
}
|
}
|
||||||
|
@ -95,14 +102,21 @@ postModifyUserR uId = do
|
||||||
$ modifyUserForm user bs
|
$ modifyUserForm user bs
|
||||||
case res of
|
case res of
|
||||||
FormSuccess uc -> do
|
FormSuccess uc -> do
|
||||||
runDB $ update uId
|
namesakes <- runDB $ selectList [UserIdent ==. userConfIdent uc] []
|
||||||
[ UserEmail =. userConfEmail uc
|
if null namesakes
|
||||||
, UserAvatar =. userConfAvatar uc
|
then do
|
||||||
]
|
runDB $ update uId
|
||||||
liftIO $ notify user (userConfEmail uc)
|
[ UserIdent =. userConfIdent uc
|
||||||
handleBarcodes (Left uId) (fromMaybe [] $ userConfBarcode uc)
|
, UserEmail =. userConfEmail uc
|
||||||
setMessageI MsgUserEdited
|
, UserAvatar =. userConfAvatar uc
|
||||||
redirect $ SelectR uId
|
]
|
||||||
|
liftIO $ notify user (userConfEmail uc)
|
||||||
|
handleBarcodes (Left uId) (fromMaybe [] $ userConfBarcode uc)
|
||||||
|
setMessageI MsgUserEdited
|
||||||
|
redirect $ SelectR uId
|
||||||
|
else do
|
||||||
|
setMessageI MsgUserIdentNotUnique
|
||||||
|
redirect $ ModifyUserR uId
|
||||||
_ -> do
|
_ -> do
|
||||||
setMessageI MsgUserNotEdited
|
setMessageI MsgUserNotEdited
|
||||||
redirect $ SelectR uId
|
redirect $ SelectR uId
|
||||||
|
@ -112,7 +126,8 @@ postModifyUserR uId = do
|
||||||
|
|
||||||
modifyUserForm :: User -> [Text] -> AForm Handler UserConf
|
modifyUserForm :: User -> [Text] -> AForm Handler UserConf
|
||||||
modifyUserForm user bs = 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 (selectField avatars) (bfs MsgSelectAvatar) (Just $ userAvatar user)
|
||||||
<*> aopt barcodeField (bfs MsgBarcodeField) (Just $ Just bs)
|
<*> aopt barcodeField (bfs MsgBarcodeField) (Just $ Just bs)
|
||||||
<* bootstrapSubmit (msgToBSSubmit MsgSubmit)
|
<* bootstrapSubmit (msgToBSSubmit MsgSubmit)
|
||||||
|
|
|
@ -141,3 +141,4 @@ BuyValue: K placení
|
||||||
CustomerId: Kód zákazníka
|
CustomerId: Kód zákazníka
|
||||||
TotalCrates: Celkový počet přepravek
|
TotalCrates: Celkový počet přepravek
|
||||||
Modify: upravit
|
Modify: upravit
|
||||||
|
UserIdentNotUnique: Uživatelské jméno není jedinečný
|
||||||
|
|
|
@ -141,3 +141,4 @@ BuyValue: Zahlbetrag
|
||||||
CustomerId: Kundennummer
|
CustomerId: Kundennummer
|
||||||
TotalCrates: Gesamtanzahl Kästen
|
TotalCrates: Gesamtanzahl Kästen
|
||||||
Modify: bearbeiten
|
Modify: bearbeiten
|
||||||
|
UserIdentNotUnique: Benutzername ist nicht einzigartig
|
||||||
|
|
|
@ -141,3 +141,4 @@ BuyValue: Payment amount
|
||||||
CustomerId: Customer id
|
CustomerId: Customer id
|
||||||
TotalCrates: Total crates
|
TotalCrates: Total crates
|
||||||
Modify: modify
|
Modify: modify
|
||||||
|
UserIdentNotUnique: Username is not unique
|
||||||
|
|
Loading…
Reference in a new issue