authr 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91245d77d3f23649d5bbeb4c8a9cd2c1ae43f4af
|
4
|
+
data.tar.gz: eb79b635a41c533e889e3c00fd2c30e49f9441c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/config/routes.rb
CHANGED
data/lib/authr/version.rb
CHANGED
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.
|
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-
|
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
|