authr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01bae8421276679336b92557b04752db6a88211f
4
- data.tar.gz: ce29a346f6edc8ed3cf345aa169295b37b445281
3
+ metadata.gz: 91245d77d3f23649d5bbeb4c8a9cd2c1ae43f4af
4
+ data.tar.gz: eb79b635a41c533e889e3c00fd2c30e49f9441c8
5
5
  SHA512:
6
- metadata.gz: ea98fb3a10b68d81bb50dc8de0ceef3106e05c8341935460c2905edae5c253b324fdb84450802dd88e5cd308081888a33fa02bd01c404e31863d0ae7fe3a0e72
7
- data.tar.gz: 61ba2cf5ee57420d454ab15b2f1937ae671c8bced748cf226f3236e4245c16848eab5e05fcc360a1520ffb0532fc233e5bf5fc4a445b128c6a1363d2e429040d
6
+ metadata.gz: a97cef44dd4b2809775593463d4a8da695a1ce636cdbca2213d666fe31de4ae96bf8d802fcffcd807904711835514e7fd315f75f34fedf5d4abf66287376f2f1
7
+ data.tar.gz: 977d8627845fa39e95172b5450c0b25c94ec86db53edf5f66f2908fc2cf5f461677058718b16e6956444abe4e1f52e027e2fbf199b83a7d7d7ca2e64d1f1c7d3
@@ -0,0 +1,22 @@
1
+ module Authr
2
+ class SessionsController < Devise::SessionsController
3
+ def create
4
+ respond_to do |format|
5
+ format.html { super }
6
+ format.json do
7
+ if warden.authenticate(auth_options)
8
+ self.resource = warden.authenticate!(auth_options)
9
+ sign_in(resource_name, resource)
10
+ data = {
11
+ token: self.resource.authentication_token,
12
+ email: self.resource.email
13
+ }
14
+ render json: data, status: 201
15
+ else
16
+ render json: { error: :invalid }, status: 401
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Authr
2
+ module TokenAuthentable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_filter :authenticate_user_from_token!
7
+ end
8
+
9
+ private
10
+ def authenticate_user_from_token!
11
+ authenticate_with_http_token do |token, options|
12
+ user_email = options[:email].presence
13
+ user = user_email && Authr::User.find_by_email(user_email)
14
+
15
+ if user && Devise.secure_compare(user.authentication_token, token)
16
+ sign_in user, store: false
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,4 @@
1
1
  Authr::Engine.routes.draw do
2
- devise_for :users, class_name: "Authr::User", module: :devise
2
+ devise_for :users, class_name: "Authr::User", module: :devise,
3
+ controllers: { sessions: 'authr/sessions' }
3
4
  end
@@ -1,3 +1,3 @@
1
1
  module Authr
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiri Kolarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -119,6 +119,8 @@ files:
119
119
  - README.md
120
120
  - Rakefile
121
121
  - app/controllers/authr/application_controller.rb
122
+ - app/controllers/authr/sessions_controller.rb
123
+ - app/controllers/concerns/authr/token_authentable.rb
122
124
  - app/models/authr/user.rb
123
125
  - config/initializers/devise.rb
124
126
  - config/locales/devise.en.yml