Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "status": "success",
- "request_time": 0.108006,
- "records": 1,
- "msg": "some msg",
- "user": {
- "id": "someidstringformongodb",
- "created_at": "2017-07-10T17:15:15.334-07:00",
- "updated_at": "2017-07-10T17:15:15.334-07:00",
- "active": true,
- "email": "email@test.com",
- "first_name": "John",
- "last_name": "Doe",
- "suffix": null,
- "title": "Cool Title",
- "admin": false,
- "phone": "777-777-7777"
- },
- "access_key": {
- "token": "xxxsomerandomtokenxxx"
- }
- }
- post '/' do
- email_pattern = /^#{ sanitize_user_input(params[:email]) }$/i
- user = SomeModule::User.find_by(email: email_pattern)
- error!('Invalid email/password combination') if user.nil?
- error!('Invalid email/password combination') unless user.password == params[:password]
- error!('This account is no longer active') unless user.active
- access_key = SomeModule::AccessKey.new_key_for_user(user)
- access_key.save
- present_success user, "some msg"
- present :user, user, with: SomeModule::Entities::UserBase
- ## what should happen to this, in order to return only the value instead of an object?
- present :access_key, access_key, with: SomeModule::Entities::AccessKey
- end
- class AccessKey < Grape::Entity
- expose :token
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement