Register.hs 643 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
module API.Controllers.Register (
  registerUser
) where

import Control.Monad.IO.Class
import Web.Spock.Shared

import API.Models.Common
import API.Controllers.Common
import API.Database.Common
Allele Dev's avatar
Allele Dev committed
11
import API.Logging
12 13 14
import API.Responses.User
import qualified API.Database.User as DB

Allele Dev's avatar
Allele Dev committed
15 16
registerUser :: MonadIO m => Pool -> Log -> ActionT m b
registerUser sqlC logger = do
17 18 19 20 21
  email <- param' "email"
  pass <- param' "password"
  ret <- liftIO $ DB.register sqlC (Email email) (Pass pass)
  case ret of
    Left e  -> errorResponse e
Allele Dev's avatar
Allele Dev committed
22 23 24
    Right u -> do
      liftIO $ info logger Registration Post $ "Registered " <> email
      created (ViewUser u)