Permalink
Browse files

Code cleanup for aesthetics / readability

  • Loading branch information...
1 parent d9b2a8b commit 635004fb4d5bd59f2ba69fae1487a45cf32eb021 @gregorycollins gregorycollins committed Dec 9, 2011
View
@@ -8,9 +8,9 @@
It exports a number of high-level functions to be used directly in your
application handlers.
- We also export a number of mid-level functions that
- should be helpful when you are integrating with another way of confirming
- the authentication of login requests.
+ We also export a number of mid-level functions that should be helpful when
+ you are integrating with another way of confirming the authentication of
+ login requests.
-}
@@ -1,8 +1,7 @@
-
-{-# LANGUAGE ExistentialQuantification #-}
-{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE OverloadedStrings #-}
module Snap.Snaplet.Auth.AuthManager
@@ -18,35 +17,31 @@ module Snap.Snaplet.Auth.AuthManager
) where
-
+------------------------------------------------------------------------------
import Data.ByteString (ByteString)
import Data.Lens.Lazy
-import Data.Time
import Data.Text (Text)
+import Data.Time
import Web.ClientSession
import Snap.Snaplet
import Snap.Snaplet.Session
import Snap.Snaplet.Auth.Types
------------------------------------------------------------------------------
--- | Create a new user from just a username and password
+-- | Creates a new user from a username and password.
--
-- May throw a "DuplicateLogin" if given username is not unique
-buildAuthUser
- :: (IAuthBackend r)
- => r
- -- ^ An auth backend
- -> Text
- -- ^ Username
- -> ByteString
- -- ^ Password
- -> IO AuthUser
+buildAuthUser :: IAuthBackend r =>
+ r -- ^ An auth backend
+ -> Text -- ^ Username
+ -> ByteString -- ^ Password
+ -> IO AuthUser
buildAuthUser r unm pass = do
now <- getCurrentTime
let au = defAuthUser {
- userLogin = unm
- , userPassword = Nothing
+ userLogin = unm
+ , userPassword = Nothing
, userCreatedAt = Just now
, userUpdatedAt = Just now
}
@@ -59,44 +54,39 @@ buildAuthUser r unm pass = do
--
-- Backend operations may throw 'BackendError's
class IAuthBackend r where
-
-- | Needs to create or update the given 'AuthUser' record
- save :: r -> AuthUser -> IO AuthUser
-
- lookupByUserId :: r -> UserId -> IO (Maybe AuthUser)
-
- lookupByLogin :: r -> Text -> IO (Maybe AuthUser)
-
- lookupByRememberToken :: r -> Text -> IO (Maybe AuthUser)
-
- destroy :: r -> AuthUser -> IO ()
+ save :: r -> AuthUser -> IO AuthUser
+ lookupByUserId :: r -> UserId -> IO (Maybe AuthUser)
+ lookupByLogin :: r -> Text -> IO (Maybe AuthUser)
+ lookupByRememberToken :: r -> Text -> IO (Maybe AuthUser)
+ destroy :: r -> AuthUser -> IO ()
------------------------------------------------------------------------------
-- | Abstract data type holding all necessary information for auth operation
data AuthManager b = forall r. IAuthBackend r => AuthManager {
- backend :: r
- -- ^ Storage back-end
+ backend :: r
+ -- ^ Storage back-end
- , session :: Lens b (Snaplet SessionManager)
- -- ^ A lens pointer to a SessionManager
+ , session :: Lens b (Snaplet SessionManager)
+ -- ^ A lens pointer to a SessionManager
- , activeUser :: Maybe AuthUser
- -- ^ A per-request logged-in user cache
+ , activeUser :: Maybe AuthUser
+ -- ^ A per-request logged-in user cache
- , minPasswdLen :: Int
- -- ^ Password length range
+ , minPasswdLen :: Int
+ -- ^ Password length range
- , rememberCookieName :: ByteString
- -- ^ Cookie name for the remember token
+ , rememberCookieName :: ByteString
+ -- ^ Cookie name for the remember token
- , rememberPeriod :: Maybe Int
- -- ^ Remember period in seconds. Defaults to 2 weeks.
+ , rememberPeriod :: Maybe Int
+ -- ^ Remember period in seconds. Defaults to 2 weeks.
- , siteKey :: Key
- -- ^ A unique encryption key used to encrypt remember cookie
+ , siteKey :: Key
+ -- ^ A unique encryption key used to encrypt remember cookie
- , lockout :: Maybe (Int, NominalDiffTime)
- -- ^ Lockout after x tries, re-allow entry after y seconds
- }
+ , lockout :: Maybe (Int, NominalDiffTime)
+ -- ^ Lockout after x tries, re-allow entry after y seconds
+ }
Oops, something went wrong.

0 comments on commit 635004f

Please sign in to comment.