token_authenticate_me 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +3 -0
- data/lib/generators/token_authenticate_me/controllers/controllers_generator.rb +41 -20
- data/lib/generators/token_authenticate_me/models/templates/authentication_model.rb +2 -2
- data/lib/generators/token_authenticate_me/models/templates/session_model.rb +2 -2
- data/lib/token_authenticate_me/models/authenticatable.rb +6 -2
- data/lib/token_authenticate_me/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b0b4986c15318e2b049d77c161bb49ddb54cd40
|
4
|
+
data.tar.gz: 753233dd4e2f98c51f5add6d3543a7c72e1744cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13c59c0d210c88e9b4de37b69c0bcd899670421202233f608228f09ce10412620ab12239937a8793ea5b690df811a3fb17c428cb594d227a9c9fa31ec23a8674
|
7
|
+
data.tar.gz: 2f0ba37bfd6c7d8f2065543e0ecde7e8f46cddfa87fb1ed0b4e77ae141b8bd015d143dc62ca458c8373187bc9dd978a8ed1dfece7a2007d68542bdc197d184f1
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -65,3 +65,6 @@ This model will have a set of [validators](https://github.com/inigo-llc/token_au
|
|
65
65
|
- [ ] Make it so any resource name can be used for authentication (initial thought is either specify the default or pass resource name in token string?).
|
66
66
|
- [ ] Allow users to specify the API namespace default.
|
67
67
|
- [ ] Add a way to override/change/configure validations.
|
68
|
+
|
69
|
+
## Code Of Conduct
|
70
|
+
Wildland Open Source [Code Of Conduct](https://github.com/wildland/code-of-conduct)
|
@@ -9,19 +9,12 @@ module TokenAuthenticateMe
|
|
9
9
|
template 'sessions.rb', 'app/controllers/api/sessions_controller.rb'
|
10
10
|
|
11
11
|
# Inject /api/sesssion route into routes file
|
12
|
-
|
13
|
-
namespace :api do
|
14
|
-
resource :session, only: [:create, :show, :destroy]
|
15
|
-
end
|
16
|
-
ROUTE
|
12
|
+
insert_after_api(" resource :session, only: [:create, :show, :destroy]\n")
|
17
13
|
end
|
18
14
|
|
19
15
|
def create_password_reset_controller # rubocop:disable Metrics/MethodLength
|
20
16
|
template 'password_reset.rb', 'app/controllers/api/password_resets_controller.rb'
|
21
|
-
|
22
|
-
# Inject /api/password_resets route into routes file
|
23
|
-
route <<-ROUTE
|
24
|
-
namespace :api do
|
17
|
+
insert_after_api(<<-ROUTE
|
25
18
|
resources(
|
26
19
|
:password_resets,
|
27
20
|
only: [:create, :update],
|
@@ -29,32 +22,60 @@ namespace :api do
|
|
29
22
|
id: TokenAuthenticateMe::UUID_REGEX
|
30
23
|
}
|
31
24
|
)
|
32
|
-
|
33
|
-
|
25
|
+
ROUTE
|
26
|
+
)
|
34
27
|
end
|
35
28
|
|
36
29
|
def create_users_controller
|
37
30
|
template 'users.rb', 'app/controllers/api/v1/users_controller.rb'
|
31
|
+
insert_after_version(" resources :users\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def insert_after_api(string)
|
37
|
+
maybe_create_api_v1_namespace
|
38
|
+
|
39
|
+
in_root do
|
40
|
+
insert_into_file(
|
41
|
+
'config/routes.rb',
|
42
|
+
string,
|
43
|
+
after: "namespace :api do\n"
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def insert_after_version(string)
|
49
|
+
maybe_create_api_v1_namespace
|
50
|
+
|
51
|
+
in_root do
|
52
|
+
insert_into_file(
|
53
|
+
'config/routes.rb',
|
54
|
+
string,
|
55
|
+
after: "namespace :v1 do\n"
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
38
59
|
|
39
|
-
|
40
|
-
|
60
|
+
def maybe_create_api_v1_namespace
|
61
|
+
in_root do
|
62
|
+
unless File.readlines('config/routes.rb').grep('namespace :api do')
|
63
|
+
route <<-ROUTE
|
41
64
|
namespace :api do
|
42
65
|
namespace :v1 do
|
43
|
-
resources :users
|
44
66
|
end
|
45
67
|
end
|
46
|
-
|
68
|
+
ROUTE
|
69
|
+
end
|
70
|
+
end
|
47
71
|
end
|
48
72
|
|
49
|
-
private
|
50
|
-
|
51
73
|
def inject_before_actions_into_users_controllers
|
52
74
|
inject_into_class(
|
53
75
|
Rails.root.join('app', 'controllers', 'api', 'v1', 'users_controller.rb'),
|
54
|
-
UsersController
|
55
|
-
) do
|
76
|
+
UsersController,
|
56
77
|
" skip_before_action :authenticate, only: [:create]\n"
|
57
|
-
|
78
|
+
)
|
58
79
|
end
|
59
80
|
end
|
60
81
|
end
|
@@ -3,9 +3,9 @@ require 'token_authenticate_me/models/authenticatable'
|
|
3
3
|
class User < ActiveRecord::Base
|
4
4
|
include TokenAuthenticateMe::Models::Authenticatable
|
5
5
|
|
6
|
-
has_many
|
6
|
+
has_many :<%= session_model_plural_name %>
|
7
7
|
|
8
8
|
def as_json(options=nil)
|
9
|
-
{
|
9
|
+
{ <%= authenticate_model_singular_name %>: super(options) }
|
10
10
|
end
|
11
11
|
end
|
@@ -3,10 +3,10 @@ require 'token_authenticate_me/models/sessionable'
|
|
3
3
|
class Session < ActiveRecord::Base
|
4
4
|
include TokenAuthenticateMe::Models::Sessionable
|
5
5
|
|
6
|
-
belongs_to
|
6
|
+
belongs_to :<%= authenticate_model_singular_name %>
|
7
7
|
|
8
8
|
def as_json(options={})
|
9
|
-
{
|
9
|
+
{ <%= session_model_singular_name %>: super({ include: :<%= authenticate_model_singular_name %> }.merge(options)) }
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -73,7 +73,11 @@ module TokenAuthenticateMe
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def current_password_required?
|
76
|
-
!new_record? && (email_changed? || attempting_to_change_password?)
|
76
|
+
!new_record? && (email_changed? || attempting_to_change_password?) && !password_resetting?
|
77
|
+
end
|
78
|
+
|
79
|
+
def password_resetting?
|
80
|
+
reset_password_token_changed? && reset_password_token_exp_changed?
|
77
81
|
end
|
78
82
|
|
79
83
|
def password_required?
|
@@ -81,7 +85,7 @@ module TokenAuthenticateMe
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def attempting_to_change_password?
|
84
|
-
!password.blank? || !password_confirmation.blank?
|
88
|
+
(!password.blank? || !password_confirmation.blank?) && password_digest_changed?
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: token_authenticate_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Clopton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -174,6 +174,7 @@ extra_rdoc_files: []
|
|
174
174
|
files:
|
175
175
|
- ".gitignore"
|
176
176
|
- ".rubocop.yml"
|
177
|
+
- CHANGELOG.md
|
177
178
|
- Gemfile
|
178
179
|
- LICENSE
|
179
180
|
- README.md
|
@@ -239,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
240
|
version: '0'
|
240
241
|
requirements: []
|
241
242
|
rubyforge_project:
|
242
|
-
rubygems_version: 2.4.
|
243
|
+
rubygems_version: 2.4.5
|
243
244
|
signing_key:
|
244
245
|
specification_version: 4
|
245
246
|
summary: This gem adds simple token authentication to users.
|