From 86e28f6f52f305721f9fc4fc4e6c3e2842053984 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 10 Jul 2018 11:57:03 +0200 Subject: [PATCH] Add dateTime-Format customization to Profile --- messages/de.msg | 4 +++- src/Handler/Profile.hs | 16 ++++++++++++++-- src/Handler/Utils/DateTime.hs | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/messages/de.msg b/messages/de.msg index 4188502e7..72239ce44 100644 --- a/messages/de.msg +++ b/messages/de.msg @@ -198,7 +198,9 @@ AdminFor: Administrator LecturerFor: Dozent UserListTitle: Komprehensive Benutzerliste -DateTimeFormatOption dateTimeExp@String dateExp@String timeExp@String: #{dateTimeExp} / #{dateExp} / #{timeExp} +DateTimeFormat: Datums- und Uhrzeitformat +DateFormat: Datumsformat +TimeFormat: Uhrzeitformat InvalidDateTimeFormat: Ungültiges Datums- und Zeitformat, JJJJ-MM-TTTHH:MM[:SS] Format erwartet AmbiguousUTCTime: Der angegebene Zeitpunkt lässt sich nicht eindeutig zu UTC konvertieren diff --git a/src/Handler/Profile.hs b/src/Handler/Profile.hs index 8a516562c..c5d92dc48 100644 --- a/src/Handler/Profile.hs +++ b/src/Handler/Profile.hs @@ -22,6 +22,9 @@ import Database.Esqueleto ((^.)) data SettingsForm = SettingsForm { stgMaxFavourties :: Int , stgTheme :: Theme + , stgDateTime :: DateTimeFormat + , stgDate :: DateTimeFormat + , stgTime :: DateTimeFormat } makeSettingForm :: Maybe SettingsForm -> Form SettingsForm @@ -32,6 +35,9 @@ makeSettingForm template = identForm FIDsettings $ \html -> do (fslpI MsgFavoriten "Anzahl Favoriten") (stgMaxFavourties <$> template) <*> areq (selectFieldList themeList) (fslpI MsgTheme "theme-select" ) (stgTheme <$> template) -- TODO: pass theme-select as id-attribute or similar. + <*> areq (selectField $ dateTimeFormatOptions SelFormatDateTime) (fslI MsgDateTimeFormat) (stgDateTime <$> template) + <*> areq (selectField $ dateTimeFormatOptions SelFormatDate) (fslI MsgDateFormat) (stgDate <$> template) + <*> areq (selectField $ dateTimeFormatOptions SelFormatTime) (fslI MsgTimeFormat) (stgTime <$> template) <* submitButton return (result, widget) -- no validation required here @@ -43,13 +49,19 @@ getProfileR = do let settingsTemplate = Just $ SettingsForm { stgMaxFavourties = userMaxFavourites , stgTheme = userTheme + , stgDateTime = userDateTimeFormat + , stgDate = userDateFormat + , stgTime = userTimeFormat } ((res,formWidget), formEnctype) <- runFormPost $ makeSettingForm settingsTemplate case res of (FormSuccess SettingsForm{..}) -> do runDB $ do - update uid [ UserMaxFavourites =. stgMaxFavourties - , UserTheme =. stgTheme + update uid [ UserMaxFavourites =. stgMaxFavourties + , UserTheme =. stgTheme + , UserDateTimeFormat =. stgDateTime + , UserDateFormat =. stgDate + , UserTimeFormat =. stgTime ] when (stgMaxFavourties < userMaxFavourites) $ do -- prune Favourites to user-defined size diff --git a/src/Handler/Utils/DateTime.hs b/src/Handler/Utils/DateTime.hs index e6088cd79..ced936b06 100644 --- a/src/Handler/Utils/DateTime.hs +++ b/src/Handler/Utils/DateTime.hs @@ -76,9 +76,13 @@ validDateTimeFormats :: TimeLocale -> SelDateTimeFormat -> Set DateTimeFormat -- ^ We use a whitelist instead of just letting the user specify their own format string since vulnerabilities in printf-like functions are not uncommon validDateTimeFormats _ SelFormatDateTime = Set.fromList $ [ DateTimeFormat "%a %d %b %Y %R" + , DateTimeFormat "%a %b %d %Y %R" , DateTimeFormat "%A, %d %B %Y %R" + , DateTimeFormat "%A, %B %d %Y %R" , DateTimeFormat "%a %d %b %Y %T" + , DateTimeFormat "%a %b %d %Y %T" , DateTimeFormat "%A, %d %B %Y %T" + , DateTimeFormat "%A, %B %d %Y %T" , DateTimeFormat "%d.%m.%Y %R" , DateTimeFormat "%d.%m.%Y %T" , DateTimeFormat "%R %d.%m.%Y" @@ -89,7 +93,9 @@ validDateTimeFormats _ SelFormatDateTime = Set.fromList $ ] validDateTimeFormats _ SelFormatDate = Set.fromList $ [ DateTimeFormat "%a %d %b %Y" + , DateTimeFormat "%a %b %d %Y" , DateTimeFormat "%A, %d %B %Y" + , DateTimeFormat "%A, %B %d %Y" , DateTimeFormat "%d.%m.%Y" , DateTimeFormat "%Y-%m-%d" ]