------------------------------------------------------------------------------
-- | Initializer for the groundhog backend to the auth snaplet.
--
initGroundhogAuth
  :: SnapletLens b SessionManager  -- ^ Lens to the session snaplet
  -> Pool Postgresql -- ^ The groundhog snaplet
  -> SnapletInit b (AuthManager b)
initGroundhogAuth sess pool = makeSnaplet "groundhog-auth" desc datadir $ do
    authSettings :: AuthSettings <- authSettingsFromConfig
    key <- liftIO $ getKey (asSiteKey authSettings)
    let manager = GroundhogAuthManager pool
    -- let migrateDB = runMigration $ migrate (undefined :: AuthUser)
    -- liftIO $ runNoLoggingT (withPostgresqlPool (runDbPersist migrateDB) pool)
    -- liftIO $ withPostgresqlPool authSettings pool _
    rng <- liftIO mkRNG
    return $ AuthManager
      { backend = manager
      , session = sess
      , activeUser = Nothing
      , minPasswdLen = asMinPasswdLen authSettings
      , rememberCookieName = asRememberCookieName authSettings
      , rememberCookieDomain = Nothing
      , rememberPeriod = asRememberPeriod authSettings
      , siteKey = key
      , lockout = asLockout authSettings
      , randomNumberGenerator = rng
      }
  where
    desc = "A Groundhog backend for user authentication"
    datadir = Nothing --Just $ liftM (++"/resources/auth") getDataDir
initGroundhogAuth
  :: SnapletLens b SessionManager  -- ^ Lens to the session snaplet
  -> Pool Postgresql -- ^ The groundhog snaplet
  -> SnapletInit b (AuthManager b)
initGroundhogAuth sess pool = makeSnaplet "groundhog-auth" desc datadir $ do
    authSettings :: AuthSettings <- authSettingsFromConfig
    key <- liftIO $ getKey (asSiteKey authSettings)
    let manager = GroundhogAuthManager pool
    -- let migrateDB = runMigration $ migrate (undefined :: AuthUser)
    -- liftIO $ runNoLoggingT (withPostgresqlPool (runDbPersist migrateDB) pool)
    -- liftIO $ withPostgresqlPool authSettings pool _
    rng <- liftIO mkRNG
    return $ AuthManager
      { backend = manager
      , session = sess
      , activeUser = Nothing
      , minPasswdLen = asMinPasswdLen authSettings
      , rememberCookieName = asRememberCookieName authSettings
      , rememberCookieDomain = Nothing
      , rememberPeriod = asRememberPeriod authSettings
      , siteKey = key
      , lockout = asLockout authSettings
      , randomNumberGenerator = rng
      }
  where
    desc = "A Groundhog backend for user authentication"
    datadir = Nothing --Just $ liftM (++"/resources/auth") getDataDir
initGroundhogAuth sess pool = makeSnaplet "groundhog-auth" desc datadir $ do
    authSettings :: AuthSettings <- authSettingsFromConfig
    key <- liftIO $ getKey (asSiteKey authSettings)
    let manager = GroundhogAuthManager pool
    -- let migrateDB = runMigration $ migrate (undefined :: AuthUser)
    -- liftIO $ runNoLoggingT (withPostgresqlPool (runDbPersist migrateDB) pool)
    -- liftIO $ withPostgresqlPool authSettings pool _
    rng <- liftIO mkRNG
    return $ AuthManager
      { backend = manager
      , session = sess
      , activeUser = Nothing
      , minPasswdLen = asMinPasswdLen authSettings
      , rememberCookieName = asRememberCookieName authSettings
      , rememberCookieDomain = Nothing
      , rememberPeriod = asRememberPeriod authSettings
      , siteKey = key
      , lockout = asLockout authSettings
      , randomNumberGenerator = rng
      }
  where
    desc = "A Groundhog backend for user authentication"
    datadir = Nothing --Just $ liftM (++"/resources/auth") getDataDir