BigW Consortium Gitlab

session.rb 665 Bytes
Newer Older
1
module API
2 3 4 5
  # Users API
  class Session < Grape::API
    # Login to get token
    #
6 7 8 9 10
    # Parameters:
    #   login (*required) - user login
    #   email (*required) - user email
    #   password (required) - user password
    #
11 12 13
    # Example Request:
    #  POST /session
    post "/session" do
14
      user = Gitlab::Auth.find_with_user_password(params[:email] || params[:login], params[:password])
15

16
      return unauthorized! unless user
17
      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?
18
      present user, with: Entities::UserLogin
19 20 21
    end
  end
end