Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE NoImplicitPrelude #-}
- {-# LANGUAGE OverloadedLabels #-}
- {-# LANGUAGE OverloadedStrings #-}
- {-# LANGUAGE BlockArguments #-}
- {-# LANGUAGE DeriveGeneric #-}
- module Handler.Login where
- import Import
- import Data.Aeson
- import Database.Persist.Postgresql
- import Data.Aeson.Types
- import Data.Maybe (fromJust)
- import Data.Text
- -- Login data
- data Login = Login {
- email :: Text
- , pass :: Text
- } deriving (Show, Generic)
- instance FromJSON Login
- instance ToJSON Login
- -- Yesod Post User Login Request
- {-
- e.g.
- {
- "email":"foo@mail.com",
- "pass":"bar"
- }
- -}
- postUserLoginR :: Handler Value
- postUserLoginR = do
- login <- requireCheckJsonBody :: Handler Login
- -- As a test, just for now obtain the value of the "email" key
- let email = login .: "email"
- sendStatusJSON ok200 (object [ "login" .= email ] ) --Respond back with the email value ("foo@mail.com")
- ----GHC ERROR I am getting-----
- • Couldn't match type ‘Login’ with ‘HashMap Text Value’
- Expected type: Object
- Actual type: Login
- • In the first argument of ‘(.:)’, namely ‘login’
- In the expression: login .: "email"
- In an equation for ‘email’: email = login .: "email"
- |
- 48 | let email = login .: "email"
- | ^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement