Skip to content

Instantly share code, notes, and snippets.

@milaz
Created February 10, 2012 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milaz/1793594 to your computer and use it in GitHub Desktop.
Save milaz/1793594 to your computer and use it in GitHub Desktop.
HashDB Authentication Working
diff --git a/Foundation.hs b/Foundation.hs
index e4385fb..48a0fd2 100644
--- a/Foundation.hs
+++ b/Foundation.hs
@@ -17,8 +17,9 @@ import Yesod
import Yesod.Static
import Settings.StaticFiles
import Yesod.Auth
-import Yesod.Auth.BrowserId
-import Yesod.Auth.GoogleEmail
+import Yesod.Auth.HashDB (authHashDB, getAuthIdHashDB)
+-- import Yesod.Auth.BrowserId
+-- import Yesod.Auth.GoogleEmail
import Yesod.Default.Config
import Yesod.Default.Util (addStaticContentExternal)
import Yesod.Logger (Logger, logMsg, formatLogText)
@@ -141,7 +142,7 @@ instance YesodAuth FCCS where
loginDest _ = RootR
-- Where to send a user after logout
logoutDest _ = RootR
-
+{-
getAuthId creds = runDB $ do
x <- getBy $ UniqueUser $ credsIdent creds
case x of
@@ -151,9 +152,14 @@ instance YesodAuth FCCS where
-- You can add other plugins like BrowserID, email or OAuth here
authPlugins _ = [authBrowserId, authGoogleEmail]
+-}
+
+ getAuthId = getAuthIdHashDB AuthR (Just . UniqueUser)
+ authPlugins _ = [authHashDB (Just . UniqueUser)]
authHttpManager = httpManager
+
-- Sends off your mail. Requires sendmail in production!
deliver :: FCCS -> L.ByteString -> IO ()
#ifdef DEVELOPMENT
diff --git a/Model.hs b/Model.hs
index 12f6697..045a986 100644
--- a/Model.hs
+++ b/Model.hs
@@ -2,6 +2,7 @@ module Model where
import Prelude
import Yesod
+import Yesod.Auth.HashDB (HashDBUser(..))
import Data.Text (Text)
import Database.Persist.Quasi
@@ -12,3 +13,12 @@ import Database.Persist.Quasi
-- http://www.yesodweb.com/book/persistent/
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
$(persistFileWith lowerCaseSettings "config/models")
+
+
+instance HashDBUser (UserGeneric backend) where
+ userPasswordHash = Just . userPassword
+ userPasswordSalt = Just . userSalt
+ setSaltAndPasswordHash s h u = u { userSalt = s
+ , userPassword = h
+ }
+
diff --git a/config/models b/config/models
index c6e732e..1d8893f 100644
--- a/config/models
+++ b/config/models
@@ -1,7 +1,8 @@
User
- ident Text
- password Text Maybe
- UniqueUser ident
+ username Text Eq
+ password Text
+ salt Text
+ UniqueUser username
Email
email Text
user UserId Maybe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment