I want be able to get token via api. Used for mobile applications
This commit is contained in:
parent
37817cc31d
commit
9aafe77e70
6 changed files with 90 additions and 2 deletions
|
@ -18,5 +18,6 @@ module Gitlab
|
|||
mount Issues
|
||||
mount Milestones
|
||||
mount Keys
|
||||
mount Session
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,10 @@ module Gitlab
|
|||
expose :id, :email, :name, :blocked, :created_at
|
||||
end
|
||||
|
||||
class UserLogin < Grape::Entity
|
||||
expose :id, :email, :name, :private_token, :blocked, :created_at
|
||||
end
|
||||
|
||||
class Hook < Grape::Entity
|
||||
expose :id, :url
|
||||
end
|
||||
|
@ -52,8 +56,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
class Key < Grape::Entity
|
||||
expose :id,
|
||||
:title,
|
||||
expose :id,
|
||||
:title,
|
||||
:key
|
||||
end
|
||||
end
|
||||
|
|
21
lib/api/session.rb
Normal file
21
lib/api/session.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Gitlab
|
||||
# Users API
|
||||
class Session < Grape::API
|
||||
# Login to get token
|
||||
#
|
||||
# Example Request:
|
||||
# POST /session
|
||||
post "/session" do
|
||||
resource = User.find_for_database_authentication(email: params[:email])
|
||||
|
||||
return forbidden! unless resource
|
||||
|
||||
if resource.valid_password?(params[:password])
|
||||
present resource, with: Entities::UserLogin
|
||||
else
|
||||
forbidden!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue