token_authenticate_me 0.8.0 → 0.9.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7b2ede59ef0d8683ee691ef1ac5385a97ce4f26
|
4
|
+
data.tar.gz: e5d3060d4b33899c235436eae1ac414e248eae1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0d97695c2086c03a87fc94307418e715aa6a1a56289e5ee7effb7479004a9c956509ca7b192563a290282aecc040507472808f2dcced574cb2e79b2a9af6888
|
7
|
+
data.tar.gz: 5c34ad2d849f2b69d29a32a0dc64b8e5351c1602b3f385b710d3848dca8e8d942b24b22da70c258ac17c975883a85cd54a30545a19f6d7392c07423f4b72fd9a
|
data/README.md
CHANGED
@@ -58,14 +58,66 @@ The model has 4 concerns:
|
|
58
58
|
* [Authenticatable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/authenticatable.rb)
|
59
59
|
* [Invitable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/invitable.rb)
|
60
60
|
* [Sessionable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/sessionable.rb)
|
61
|
-
*
|
62
|
-
[Passwordable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/passwordable.rb)
|
61
|
+
* [Passwordable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/passwordable.rb)
|
63
62
|
|
64
|
-
|
63
|
+
## Usage
|
64
|
+
```rb
|
65
|
+
class MyUser
|
66
|
+
include TokenAuthenticateMe::Concerns::Models::Authenticatable
|
67
|
+
end
|
68
|
+
```
|
69
|
+
### Default rules and behavior.
|
65
70
|
* `email` is required, can't be blank, is unique (case insensitive), and must look like an email address.
|
66
71
|
* `password` is required, can not be blank, it must be confirmed (`password_confirmation`), and must be between 8 and 72 characters long. If the model has been persisted `password` can be blank or `nil` which indicates that it should not be changed and will be ignored.
|
67
72
|
* `username` is required, can't be blank, is unique (case insensitive), and only allows alphanumeric values.
|
68
73
|
* To change the `password` or `email` after the model has been persisted, you will need to provide the current password as `current_password`.
|
74
|
+
* To change the `email` after the model has been persisted, you will need to be confirmed (`email_confirmation`) to change.
|
75
|
+
|
76
|
+
### Custom Validation Rules
|
77
|
+
If you don't like the validation rules you can customize some of them by using the following override methods and/or writing your own rules. Note that they are additive with the existing rules.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class MyUser
|
81
|
+
def ignore_password_length_validations?
|
82
|
+
true # defaults to false
|
83
|
+
end
|
84
|
+
|
85
|
+
def ignore_username_format_validation?
|
86
|
+
true # defaults to false
|
87
|
+
end
|
88
|
+
|
89
|
+
def ignore_email_format_validation?
|
90
|
+
true # defaults to false
|
91
|
+
end
|
92
|
+
|
93
|
+
def ignore_email_confirmation_on_change?
|
94
|
+
false # defaults to true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
Custom Validation Rules Example
|
100
|
+
```Ruby
|
101
|
+
class MyUser
|
102
|
+
### Other Code
|
103
|
+
validates(
|
104
|
+
:password,
|
105
|
+
format: {
|
106
|
+
with: /\A[a-zA-Z0-9]+\Z/,
|
107
|
+
message: 'only letters and numbers are allowed.'
|
108
|
+
} # We wanted to have alphanumeric passwords.
|
109
|
+
if: :password_required? # This triggers the requirements when token_authenticate_me requires them
|
110
|
+
)
|
111
|
+
### More Code
|
112
|
+
def ignore_password_length_validations? # We didn't want a password length constraints, but wanted only alphanumeric characters.
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
def ignore_email_confirmation_on_change? # We want users to have to confirm emails to reduce mistakes.
|
117
|
+
false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
69
121
|
|
70
122
|
## Code Of Conduct
|
71
123
|
Wildland Open Source [Code Of Conduct](https://github.com/wildland/code-of-conduct)
|
@@ -19,19 +19,34 @@ module TokenAuthenticateMe
|
|
19
19
|
:email,
|
20
20
|
presence: true,
|
21
21
|
uniqueness: { case_sensitive: false },
|
22
|
+
)
|
23
|
+
|
24
|
+
with_options if: :email_confirmation_required? do |model|
|
25
|
+
model.validates :email, confirmation: true
|
26
|
+
model.validates :email_confirmation, presence: true
|
27
|
+
end
|
28
|
+
|
29
|
+
validates(
|
30
|
+
:email,
|
22
31
|
format: {
|
23
32
|
with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i,
|
24
33
|
message: 'invalid e-mail address'
|
25
|
-
}
|
34
|
+
},
|
35
|
+
unless: :ignore_email_format_validation?
|
26
36
|
)
|
27
37
|
|
28
38
|
validates(
|
29
39
|
:username,
|
30
|
-
format: { with: /\A[a-zA-Z0-9]+\Z/ },
|
31
40
|
presence: true,
|
32
41
|
uniqueness: { case_sensitive: false }
|
33
42
|
)
|
34
43
|
|
44
|
+
validates(
|
45
|
+
:username,
|
46
|
+
format: { with: /\A[a-zA-Z0-9]+\Z/ },
|
47
|
+
unless: :ignore_username_format_validation?
|
48
|
+
)
|
49
|
+
|
35
50
|
def attributes
|
36
51
|
{
|
37
52
|
'id' => id,
|
@@ -46,8 +61,28 @@ module TokenAuthenticateMe
|
|
46
61
|
{ user: super(options) }
|
47
62
|
end
|
48
63
|
|
64
|
+
def ignore_username_format_validation?
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def ignore_email_format_validation?
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def ignore_email_confirmation_on_change?
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
49
76
|
protected
|
50
77
|
|
78
|
+
def email_confirmation_required?
|
79
|
+
!ignore_email_confirmation_on_change? && attempting_to_change_email?
|
80
|
+
end
|
81
|
+
|
82
|
+
def attempting_to_change_email?
|
83
|
+
email_changed? && persisted?
|
84
|
+
end
|
85
|
+
|
51
86
|
def downcase_email_and_username
|
52
87
|
self.email = email.downcase
|
53
88
|
self.username = username.downcase
|
@@ -7,18 +7,29 @@ module TokenAuthenticateMe
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
included do
|
10
|
-
|
11
10
|
has_secure_password validations: false
|
12
11
|
attr_accessor :current_password
|
13
12
|
|
14
13
|
validates(
|
15
14
|
:password,
|
16
15
|
presence: true,
|
17
|
-
length: { in: 8..72 },
|
18
16
|
confirmation: true,
|
19
17
|
if: :password_required?
|
20
18
|
)
|
21
19
|
|
20
|
+
validates(
|
21
|
+
:password_confirmation,
|
22
|
+
presence: true,
|
23
|
+
if: :password_required?
|
24
|
+
)
|
25
|
+
|
26
|
+
validates(
|
27
|
+
:password,
|
28
|
+
length: { in: 8..72 },
|
29
|
+
if: :password_required?,
|
30
|
+
unless: :ignore_password_length_validations?
|
31
|
+
)
|
32
|
+
|
22
33
|
validate(
|
23
34
|
:current_password_correct,
|
24
35
|
if: :current_password_required?
|
@@ -56,6 +67,10 @@ module TokenAuthenticateMe
|
|
56
67
|
reset_password_token_changed? && reset_password_token_exp_changed?
|
57
68
|
end
|
58
69
|
|
70
|
+
def ignore_password_length_validations?
|
71
|
+
false
|
72
|
+
end
|
73
|
+
|
59
74
|
def password_required?
|
60
75
|
attempting_to_change_password? || new_record?
|
61
76
|
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
|
+
version: 0.9.0
|
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: 2018-
|
12
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -165,7 +165,6 @@ files:
|
|
165
165
|
- test/dummy/config/locales/en.yml
|
166
166
|
- test/dummy/config/routes.rb
|
167
167
|
- test/dummy/config/secrets.yml
|
168
|
-
- test/dummy/log/development.log
|
169
168
|
- test/dummy/log/test.log
|
170
169
|
- test/dummy/public/404.html
|
171
170
|
- test/dummy/public/422.html
|
@@ -200,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
199
|
version: '0'
|
201
200
|
requirements: []
|
202
201
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.5.
|
202
|
+
rubygems_version: 2.5.2
|
204
203
|
signing_key:
|
205
204
|
specification_version: 4
|
206
205
|
summary: This gem adds simple token authentication to users.
|
@@ -233,7 +232,6 @@ test_files:
|
|
233
232
|
- test/dummy/config/routes.rb
|
234
233
|
- test/dummy/config/secrets.yml
|
235
234
|
- test/dummy/config.ru
|
236
|
-
- test/dummy/log/development.log
|
237
235
|
- test/dummy/log/test.log
|
238
236
|
- test/dummy/public/404.html
|
239
237
|
- test/dummy/public/422.html
|
File without changes
|