PageRenderTime 29ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/api/session.rb

https://gitlab.com/vicvega/gitlab-ce
Ruby | 20 lines | 19 code | 1 blank | 0 comment | 2 complexity | 271b8552b02f7e4d2a54f28c573b2a08 MD5 | raw file
 1module API
 2  class Session < Grape::API
 3    desc 'Login to get token' do
 4      success Entities::UserLogin
 5    end
 6    params do
 7      optional :login, type: String, desc: 'The username'
 8      optional :email, type: String, desc: 'The email of the user'
 9      requires :password, type: String, desc: 'The password of the user'
10      at_least_one_of :login, :email
11    end
12    post "/session" do
13      user = Gitlab::Auth.find_with_user_password(params[:email] || params[:login], params[:password])
14
15      return unauthorized! unless user
16      return render_api_error!('401 Unauthorized. You have 2FA enabled. Please use a personal access token to access the API', 401) if user.two_factor_enabled?
17      present user, with: Entities::UserLogin
18    end
19  end
20end