Using-HashDB-In-a-Scaffolded-Site.md
September 9, 2015 ยท View on GitHub
Example with Yesod Scaffold and Your Own Model:
-
Your object representing clients must provide a unique identifier field, a field for the password hash, and a field for the password salt. Example:
-- in config/models Person email Text password Text UniqueEmail email deriving TypeableIn this example, 'email' will be the unique identifier.
-
You must provide
instance HashDBUser (<yourObject>Generic backend)in the module that shares your model. In the scaffolded site, that module is Model. Continuing the Person example,
-- in Model.hs import Yesod.Auth.HashDB (HashDBUser(..)) instance HashDBUser Person where userPasswordHash = Just . personPassword setPasswordHash h p = p { personPassword = h } -
Now, in Foundation.hs, we hook Auth.HashDB into your foundation. You must add an import of Yesod.Auth.HashDB, of course,
import Yesod.Auth.HashDB (authHashDB, getAuthIdHashDB)and then modify the YesodAuth instance like so:
-- in Foundation.hs instance YesodAuth <MySite> where type AuthId <MySite> = PersonId -- ... loginDest, etc. getAuthId creds = getAuthIdHashDB AuthR (Just . UniqueEmail) creds authPlugins _ = [authHashDB (Just . UniqueEmail)]
Further examples can be found in the module documentation