diff options
author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2012-09-20 18:44:44 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2012-09-20 18:45:07 +0400 |
commit | 9aafe77e708174aac697a8dcafc99b90e96be36e (patch) | |
tree | cb22fddcf3feeefb381a3ded1407ef11767395b5 /lib | |
parent | 37817cc31d890f1e79b31ae3d625fbace672451e (diff) |
I want be able to get token via api. Used for mobile applications
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 8 | ||||
-rw-r--r-- | lib/api/session.rb | 21 |
3 files changed, 28 insertions, 2 deletions
diff --git a/lib/api.rb b/lib/api.rb index 37e03849b96..3b62f31bf32 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -18,5 +18,6 @@ module Gitlab mount Issues mount Milestones mount Keys + mount Session end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 6241fc8f187..5d8cc2765b1 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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 diff --git a/lib/api/session.rb b/lib/api/session.rb new file mode 100644 index 00000000000..5bcdf93abe9 --- /dev/null +++ b/lib/api/session.rb @@ -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 + |