2014-09-02 18:07:02 +05:30
|
|
|
module API
|
|
|
|
class Session < Grape::API
|
2017-08-17 22:00:37 +05:30
|
|
|
desc 'Login to get token' do
|
|
|
|
success Entities::UserWithPrivateDetails
|
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
post "/session" do
|
2016-06-16 23:09:34 +05:30
|
|
|
user = Gitlab::Auth.find_with_user_password(params[:email] || params[:login], params[:password])
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
return unauthorized! unless user
|
2016-09-13 17:45:13 +05:30
|
|
|
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?
|
2017-08-17 22:00:37 +05:30
|
|
|
present user, with: Entities::UserWithPrivateDetails
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|