Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. {
  2. "status": "success",
  3. "request_time": 0.108006,
  4. "records": 1,
  5. "msg": "some msg",
  6. "user": {
  7. "id": "someidstringformongodb",
  8. "created_at": "2017-07-10T17:15:15.334-07:00",
  9. "updated_at": "2017-07-10T17:15:15.334-07:00",
  10. "active": true,
  11. "email": "email@test.com",
  12. "first_name": "John",
  13. "last_name": "Doe",
  14. "suffix": null,
  15. "title": "Cool Title",
  16. "admin": false,
  17. "phone": "777-777-7777"
  18. },
  19. "access_key": {
  20. "token": "xxxsomerandomtokenxxx"
  21. }
  22. }
  23.  
  24. post '/' do
  25. email_pattern = /^#{ sanitize_user_input(params[:email]) }$/i
  26. user = SomeModule::User.find_by(email: email_pattern)
  27. error!('Invalid email/password combination') if user.nil?
  28. error!('Invalid email/password combination') unless user.password == params[:password]
  29. error!('This account is no longer active') unless user.active
  30. access_key = SomeModule::AccessKey.new_key_for_user(user)
  31. access_key.save
  32. present_success user, "some msg"
  33. present :user, user, with: SomeModule::Entities::UserBase
  34.  
  35. ## what should happen to this, in order to return only the value instead of an object?
  36. present :access_key, access_key, with: SomeModule::Entities::AccessKey
  37. end
  38.  
  39. class AccessKey < Grape::Entity
  40. expose :token
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement