Commit 8525a8c2 authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

added seed.

parent f3d72f0a
......@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: fd7a7246f0613d88e47e6f2e5ce057afc082ed5215a32651d8e7e52850604853
-- hash: f0531eee1458086fe8489757aa53ee4e4990405053ccaac6e1d42cee760424a1
name: Cirkeltrek
version: 0.0.0
......@@ -88,3 +88,41 @@ executable Cirkeltrek
, yesod-form
, yesod-static
default-language: Haskell2010
executable Seed
main-is: Main.hs
other-modules:
Paths_Cirkeltrek
hs-source-dirs:
seed
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
Cirkeltrek
, aeson
, base
, classy-prelude
, classy-prelude-yesod
, data-default
, esqueleto
, fast-logger
, file-embed
, http-client
, http-client-tls
, monad-logger
, persistent
, persistent-postgresql
, persistent-template
, shakespeare
, template-haskell
, wai
, wai-extra
, wai-logger
, warp
, yaml
, yesod
, yesod-auth
, yesod-auth-hashdb
, yesod-core
, yesod-form
, yesod-static
default-language: Haskell2010
!nEfut!|ջ!ĎOÕp릉a#ڀ*C\v#H9PI<a_6A0VuT>
\ No newline at end of file
......@@ -46,3 +46,12 @@ executables:
- -with-rtsopts=-N
dependencies:
- Cirkeltrek
Seed:
main: Main.hs
source-dirs: seed
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- Cirkeltrek
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
import ClassyPrelude
import ClassyPrelude.Yesod
import Control.Monad.Logger
import Database.Persist.Postgresql
import Yesod.Auth.Util.PasswordStore
import Yesod.Default.Config2
import Foundation
import Model
import Model.Grouping
import Settings
insertGroup txt = insert $ Groups txt
createAdministrator gid username email password = do
now <- liftIO getCurrentTime
let usersGroupId = gid
usersUsername = username
usersEmail = email
usersPassword = password
usersJoinTime = now
usersTopicsStarted = 0
usersRepliesPosted = 0
insert_ $ Users {..}
main :: IO ()
main = do
settings <- loadYamlSettingsArgs [configSettingsYmlValue] useEnv
let conn = (pgConnStr $ appDatabaseConf settings)
username <- getLine
password <-
do something <- getLine
password <- makePassword (encodeUtf8 something) 17
return $ decodeUtf8 password
email <- getLine
runStderrLoggingT . withPostgresqlConn conn $
runSqlConn $ do
runMigration migrateAll
gid <- insertGroup Administrator
gin <- insertGroup Moderator
gim <- insertGroup Member
gib <- insertGroup Banned
createAdministrator gid username email (Just password)
......@@ -48,6 +48,7 @@ instance Yesod App where
case appRoot $ appSettings app of
Nothing -> getApprootText guessApproot app req
Just root -> root
makeSessionBackend _ = Just <$> defaultClientSessionBackend (60 * 5) "config/client-session-key.aes"
yesodMiddleware = defaultYesodMiddleware
defaultLayout widget = do
master <- getYesod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment