BigW Consortium Gitlab

session.rb 788 Bytes
Newer Older
1
module API
2
  class Session < Grape::API
3
    desc 'Login to get token' do
4
      success Entities::UserWithPrivateDetails
5 6 7 8 9 10 11
    end
    params do
      optional :login, type: String, desc: 'The username'
      optional :email, type: String, desc: 'The email of the user'
      requires :password, type: String, desc: 'The password of the user'
      at_least_one_of :login, :email
    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::UserWithPrivateDetails
18 19 20
    end
  end
end