Advertisement
Guest User

handler error login

a guest
Oct 17th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. {-# LANGUAGE NoImplicitPrelude #-}
  2. {-# LANGUAGE OverloadedLabels #-}
  3. {-# LANGUAGE OverloadedStrings #-}
  4. {-# LANGUAGE BlockArguments #-}
  5. {-# LANGUAGE DeriveGeneric #-}
  6.  
  7. module Handler.Login where
  8.  
  9. import Import
  10. import Data.Aeson
  11. import Database.Persist.Postgresql
  12. import Data.Aeson.Types
  13. import Data.Maybe (fromJust)
  14. import Data.Text
  15.  
  16. -- Login data
  17. data Login = Login {
  18. email :: Text
  19. , pass :: Text
  20.  
  21. } deriving (Show, Generic)
  22.  
  23. instance FromJSON Login
  24. instance ToJSON Login
  25.  
  26. -- Yesod Post User Login Request
  27. {-
  28. e.g.
  29. {
  30. "email":"foo@mail.com",
  31. "pass":"bar"
  32. }
  33. -}
  34. postUserLoginR :: Handler Value
  35. postUserLoginR = do
  36. login <- requireCheckJsonBody :: Handler Login
  37. -- As a test, just for now obtain the value of the "email" key
  38. let email = login .: "email"
  39. sendStatusJSON ok200 (object [ "login" .= email ] ) --Respond back with the email value ("foo@mail.com")
  40.  
  41. ----GHC ERROR I am getting-----
  42.  
  43.  
  44. • Couldn't match type ‘Login’ with ‘HashMap Text Value’
  45. Expected type: Object
  46. Actual type: Login
  47. • In the first argument of ‘(.:)’, namely ‘login’
  48. In the expression: login .: "email"
  49. In an equation for ‘email’: email = login .: "email"
  50. |
  51. 48 | let email = login .: "email"
  52. | ^^^^^
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement