module Adminka
( adminka
) where
import ClassyPrelude
import qualified Database
import qualified Log
import Database.Persist.Sql (runMigration)
import Database.Persist.Sqlite (withSqliteConn)
import Startup (AdminConfig (..))
import Yesod.Auth.Util.PasswordStore (makePassword)
adminka :: AdminConfig -> IO ()
adminka = \case
CreateUser{username, password, database} -> withSqliteConn database $ \conn ->
flip runReaderT conn $ do
Log.info "Perform initial migrations"
runMigration Database.migrateAll
hashedPassword <- liftIO $ makePassword (encodeUtf8 password) 14
_user <-
Database.insertOrIgnoreUser
Database.User
{ userUsername = username
, userPassword = decodeUtf8 hashedPassword
}
pure ()