gitlab-org--gitlab-foss/lib/api/session.rb

21 lines
788 B
Ruby
Raw Normal View History

module API
class Session < Grape::API
2016-11-09 11:36:35 -05:00
desc 'Login to get token' do
success Entities::UserWithPrivateDetails
2016-11-09 11:36:35 -05:00
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
post "/session" do
user = Gitlab::Auth.find_with_user_password(params[:email] || params[:login], params[:password])
2013-07-16 04:28:19 -04:00
return unauthorized! unless user
2016-08-17 18:39:20 -04:00
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?
present user, with: Entities::UserWithPrivateDetails
end
end
end