more unit-y unit tests

This commit is contained in:
Adam C. Baker
2014-10-01 15:42:57 -07:00
parent 7e9c224299
commit bfa6a968a6
2 changed files with 26 additions and 19 deletions
+5 -1
View File
@@ -10,6 +10,7 @@ module PgQuery (
signInRole,
pgSetRole,
pgResetRole,
checkPass,
RangedResult(..),
DbRole
) where
@@ -131,12 +132,15 @@ addUser identity pass role conn = do
]) conn
return ()
checkPass :: BS.ByteString -> BS.ByteString -> Bool
checkPass = validatePassword
signInRole :: BS.ByteString -> BS.ByteString -> Connection -> IO(Maybe DbRole)
signInRole user pass conn = do
u <- quickQuery conn "select pass, rolname from dbapi.auth where id = ?" [toSql user]
return $ case u of
[[hashed, role]] ->
if validatePassword (fromSql hashed) (cs pass)
if checkPass (fromSql hashed) (cs pass)
then Just $ fromSql role
else Nothing
_ -> Nothing