diff --git a/Handler/Buy.hs b/Handler/Buy.hs index 22b3bfe..9965e17 100644 --- a/Handler/Buy.hs +++ b/Handler/Buy.hs @@ -55,12 +55,10 @@ postBuyR uId bId = do notifyUser :: User -> Beverage -> Int -> App -> IO () notifyUser user bev price master = do - case userNotify user of - True -> - case userEmail user of - Just email -> - liftIO $ sendMail email "Einkauf beim Matematen" - [stext| + case userEmail user of + Just email -> + liftIO $ sendMail email "Einkauf beim Matematen" + [stext| Hallo #{userIdent user}, Du hast gerade beim Matematen für #{formatIntCurrency price}#{appCurrency $ appSettings master} #{beverageIdent bev} eingekauft. @@ -68,10 +66,8 @@ Du hast gerade beim Matematen für #{formatIntCurrency price}#{appCurrency $ app Viele Grüsse, Der Matemat - |] - Nothing -> - return () - False -> + |] + Nothing -> return () getBuyCashR :: BeverageId -> Handler Html diff --git a/Handler/NewUser.hs b/Handler/NewUser.hs index f4a2f84..0e79cec 100644 --- a/Handler/NewUser.hs +++ b/Handler/NewUser.hs @@ -32,8 +32,7 @@ newUserForm secs = renderDivs $ User <$> areq textField "Nickname" Nothing <*> pure 0 <*> pure secs - <*> aopt emailField "E-mail" Nothing - <*> areq boolField "Benachrichtigung bei Kauf" (Just False) + <*> aopt emailField "E-mail eintragen, falls Benachrichtigungen erwünscht" Nothing data UserConf = UserConf { userConfEmail :: Maybe Text @@ -59,12 +58,11 @@ postModifyUserR uId = do Just user -> do ((res, _), _) <- runFormPost $ modifyUserForm user case res of - FormSuccess conf -> do + FormSuccess email -> do runDB $ update uId - [ UserEmail =. userConfEmail conf - , UserNotify =. userConfNotify conf + [ UserEmail =. email ] - liftIO $ notify user conf + liftIO $ notify user email setMessage "Nutzerdaten aktualisiert" redirect $ SelectR uId _ -> do @@ -74,16 +72,15 @@ postModifyUserR uId = do setMessage "Nutzer unbekannt" redirect $ HomeR -modifyUserForm :: User -> Form UserConf -modifyUserForm user = renderDivs $ UserConf - <$> aopt emailField "E-Mail" (Just $ userEmail user) - <*> areq boolField "Benachrichtigung bei Kauf" (Just $ userNotify user) +modifyUserForm :: User -> Form (Maybe Text) +modifyUserForm user = renderDivs $ + aopt emailField "E-Mail eintragen, falls Benchrichtigungen erwünscht" (Just $ userEmail user) -notify :: User -> UserConf -> IO () -notify user conf - | (userEmail user) == (userConfEmail conf) && (userNotify user) == (userConfNotify conf) = return () +notify :: User -> Maybe Text -> IO () +notify user email + | (userEmail user) == email = return () | otherwise = case userEmail user of - Just email -> sendMail email "Profiländerung" + Just address -> sendMail address "Profiländerung" [stext| Hallo #{userIdent user}, diff --git a/config/models b/config/models index f9dcb17..4ed043b 100644 --- a/config/models +++ b/config/models @@ -3,7 +3,6 @@ User balance Int timestamp Int email Text Maybe - notify Bool default=False UniqueUser ident deriving Typeable Show Beverage