From a0d42f915973c14b9e219bc4b89c19404d42ae59 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 22 May 2016 21:24:55 +0000 Subject: [PATCH] New sharer ident checked for CI-uniqueness --- src/Vervis/Field/Person.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Vervis/Field/Person.hs b/src/Vervis/Field/Person.hs index 01ee9e5..fcd5a97 100644 --- a/src/Vervis/Field/Person.hs +++ b/src/Vervis/Field/Person.hs @@ -19,9 +19,11 @@ module Vervis.Field.Person ) where -import Vervis.Import +import Vervis.Import hiding ((==.)) import Data.Char (isDigit) +import Database.Esqueleto + import Data.Char.Local (isAsciiLetter) checkLoginTemplate :: Field Handler Text -> Field Handler Text @@ -40,13 +42,12 @@ checkLoginTemplate = in checkBool ok msg checkLoginUnique :: Field Handler Text -> Field Handler Text -checkLoginUnique = checkM $ \ login -> runDB $ do - let sharer = Sharer - { sharerIdent = login - , sharerName = Nothing - } - mus <- checkUnique sharer - return $ if isNothing mus +checkLoginUnique = checkM $ \ login -> do + sames <- runDB $ select $ from $ \ sharer -> do + where_ $ lower_ (sharer ^. SharerIdent) ==. lower_ (val login) + limit 1 + return () + return $ if null sames then Right login else Left ("This username is already in use" :: Text) @@ -63,7 +64,7 @@ checkPassLength = \alternative, such as a client TLS certificate, that can work \ \somewhat like SSH and GPG keys." minlen = 8 - in checkBool ((>= minlen) . length) msg + in checkBool ((>= minlen) . length) msg passConfirmField :: Field Handler Text passConfirmField = Field