red_token_auth 0.4.1 → 0.5.0
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 +4 -4
- data/README.md +6 -1
- data/lib/red_token_auth.rb +2 -0
- data/lib/red_token_auth/configuration.rb +0 -3
- data/lib/red_token_auth/omniauthable.rb +14 -0
- data/lib/red_token_auth/omniauthable/callbacks_and_validations.rb +30 -0
- data/lib/red_token_auth/validations.rb +3 -3
- data/lib/red_token_auth/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce5a522be2ce9faff1ac0cc0f2843b612ccf05f0
|
4
|
+
data.tar.gz: 290c45a1389aaf3f494937ab9e8c7a11bc3d5820
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f733db0dc88207cde8c2606894060d0f8d66fc7267fff866ab678596f99ffaf63911e2af6a1d8f8905b4c89e16ab3b3dab9dd370ad9732d90c3ae0b478b2fa2
|
7
|
+
data.tar.gz: d5dc3ff3e970c4e9f2b1773ed4cab317df918bf128202f862a3358581a1cb1d3b3308ebf2a8dbd571ea2a2d9d3b0f7f97e5bac559ac178462c1fcc9ec182c611
|
data/README.md
CHANGED
@@ -36,6 +36,8 @@ You'll be able to include the module in the model like so.
|
|
36
36
|
class User
|
37
37
|
include Mongoid::Document
|
38
38
|
include RedTokenAuth
|
39
|
+
# Include this if you intend to use OmniAuth
|
40
|
+
include RedTokenAuth::Omniauthable
|
39
41
|
|
40
42
|
# Mandatory fields for this gem.
|
41
43
|
field :email, type: String
|
@@ -43,6 +45,10 @@ class User
|
|
43
45
|
field :reset_password_token, type: String
|
44
46
|
field :reset_password_token_sent_at, type: Time
|
45
47
|
field :authentication_token, type: String
|
48
|
+
# You'll need these fields if you are working with Omniauth.
|
49
|
+
field :uid, type: String
|
50
|
+
# Default must be "email".
|
51
|
+
field :provider, type: String, default: "email"
|
46
52
|
end
|
47
53
|
```
|
48
54
|
|
@@ -125,7 +131,6 @@ By using the `authenticate!(:user)` in your controller, you'll have access to `c
|
|
125
131
|
```ruby
|
126
132
|
RedTokenAuth.configure do |config|
|
127
133
|
config.email_regex = /\A[^@\s]+@[^@\s]+\z/
|
128
|
-
config.password_regex = /\A(?=.*?[a-z])(?=.*?[0-9]).{0,}\z/
|
129
134
|
config.password_length = 8..20
|
130
135
|
end
|
131
136
|
```
|
data/lib/red_token_auth.rb
CHANGED
@@ -5,9 +5,11 @@ require "red_token_auth/configuration"
|
|
5
5
|
|
6
6
|
require "red_token_auth/authentication"
|
7
7
|
require "red_token_auth/sign_in_out"
|
8
|
+
require "red_token_auth/omniauthable"
|
8
9
|
require "red_token_auth/password"
|
9
10
|
require "red_token_auth/validations"
|
10
11
|
|
12
|
+
|
11
13
|
require "red_token_auth/controllers/authentication"
|
12
14
|
|
13
15
|
module RedTokenAuth
|
@@ -1,14 +1,11 @@
|
|
1
1
|
module RedTokenAuth
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :email_regex
|
4
|
-
attr_accessor :password_regex
|
5
4
|
attr_accessor :password_length
|
6
5
|
|
7
6
|
def initialize
|
8
7
|
# Basically, just make sure there only one "@" in the email.
|
9
8
|
@email_regex = /\A[^@\s]+@[^@\s]+\z/
|
10
|
-
# Make sure there is at least one character and one number.
|
11
|
-
@password_regex = /\A(?=.*?[a-z])(?=.*?[0-9]).{0,}\z/
|
12
9
|
@password_length = 8..20
|
13
10
|
end
|
14
11
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RedTokenAuth
|
2
|
+
module Omniauthable
|
3
|
+
module CallbacksAndValidations
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
validates :email, presence: true, if: Proc.new { |resource| resource.provider == "email" }
|
8
|
+
validates_presence_of :uid, if: Proc.new { |resource| resource.provider != "email" }
|
9
|
+
|
10
|
+
# Only validate unique emails among email registered users.
|
11
|
+
validate :unique_email_user
|
12
|
+
|
13
|
+
# Syncronize UID and email if provider is the user's email.
|
14
|
+
before_save :syncronize_uid
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def unique_email_user
|
20
|
+
if provider == "email" && email_changed? && self.class.where(provider: "email", email: email).count > 0
|
21
|
+
errors.add(:email, :taken)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def syncronize_uid
|
26
|
+
self.uid = email if provider == "email"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -8,12 +8,12 @@ module RedTokenAuth
|
|
8
8
|
include ActiveModel::SecurePassword
|
9
9
|
|
10
10
|
validates :email,
|
11
|
-
format: RedTokenAuth.configuration.email_regex
|
11
|
+
format: RedTokenAuth.configuration.email_regex,
|
12
|
+
if: Proc.new { |resource| resource.email.present? || resource.provider == "email" }
|
12
13
|
validates :password,
|
13
|
-
format: RedTokenAuth.configuration.password_regex,
|
14
14
|
length: { in: RedTokenAuth.configuration.password_length },
|
15
15
|
confirmation: true,
|
16
|
-
if: Proc.new { |
|
16
|
+
if: Proc.new { |resource| resource.password.present? }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red_token_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Ergos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -155,6 +155,8 @@ files:
|
|
155
155
|
- lib/red_token_auth/configuration.rb
|
156
156
|
- lib/red_token_auth/controllers/authentication.rb
|
157
157
|
- lib/red_token_auth/engine.rb
|
158
|
+
- lib/red_token_auth/omniauthable.rb
|
159
|
+
- lib/red_token_auth/omniauthable/callbacks_and_validations.rb
|
158
160
|
- lib/red_token_auth/password.rb
|
159
161
|
- lib/red_token_auth/sign_in_out.rb
|
160
162
|
- lib/red_token_auth/validations.rb
|
@@ -179,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
181
|
version: '0'
|
180
182
|
requirements: []
|
181
183
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.6.
|
184
|
+
rubygems_version: 2.6.11
|
183
185
|
signing_key:
|
184
186
|
specification_version: 4
|
185
187
|
summary: Simple token based authentication for Mongoid.
|