rails_jwt_auth 0.15.3 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/app/mailers/rails_jwt_auth/mailer.rb +17 -0
- data/app/models/concerns/rails_jwt_auth/recoverable.rb +16 -0
- data/app/views/rails_jwt_auth/mailer/set_password_instructions.html.erb +5 -0
- data/config/locales/en.yml +4 -2
- data/lib/rails_jwt_auth.rb +3 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db8f2a0ef2121ee0f1c4f5ff80b11b1c4bdb8cc
|
4
|
+
data.tar.gz: 6ffc4e0922ef4f7c228d2224e943030c06fa0e1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6533f3b2d2518403af392c6698c7193eb847bf3588c2d15387aed664362371fd0ef1410c3b7953bd358c5b77d3e641ad9bf62972e525546fec373284ff85d53c
|
7
|
+
data.tar.gz: efca9a928a49a399d463bf0c7fc9e9ce617ab035f75670ec1bccd7e6be8825af271e31f167c5deacd563f09aa4eaa03f1e556e9ff5477ce116bd3ecd8a34abf6
|
data/README.md
CHANGED
@@ -45,6 +45,7 @@ You can edit configuration options into `config/initializers/auth_token_auth.rb`
|
|
45
45
|
| confirmation_expiration_time | 1.day | Confirmation token expiration time |
|
46
46
|
| reset_password_url | password_path | Url used to create email link with reset password token |
|
47
47
|
| reset_password_expiration_time | 1.day | Confirmation token expiration time |
|
48
|
+
| set_password_url | password_path | Url used to create email link with set password token |
|
48
49
|
| deliver_later | false | Uses `deliver_later` method to send emails |
|
49
50
|
|
50
51
|
## Authenticatable
|
@@ -414,7 +415,28 @@ class CurrentUserController < ApplicationController
|
|
414
415
|
params.require(:user).permit(:email, :current_password, :password)
|
415
416
|
end
|
416
417
|
end
|
418
|
+
```
|
419
|
+
|
420
|
+
## Register users with random password
|
417
421
|
|
422
|
+
This is a controller example that allows admins to register users with random password and send email to reset it.
|
423
|
+
If registration is sucess it will send email to `set_password_url` with reset password token.
|
424
|
+
|
425
|
+
```ruby
|
426
|
+
class UsersController < ApplicationController
|
427
|
+
before_action 'authenticate!'
|
428
|
+
|
429
|
+
def create
|
430
|
+
user = User.new(create_params)
|
431
|
+
user.set_and_send_password_instructions ? render_204 : render_422(user.errors)
|
432
|
+
end
|
433
|
+
|
434
|
+
private
|
435
|
+
|
436
|
+
def create_params
|
437
|
+
params.require(:user).permit(:email)
|
438
|
+
end
|
439
|
+
end
|
418
440
|
```
|
419
441
|
|
420
442
|
## Custom responses
|
@@ -35,5 +35,22 @@ if defined?(ActionMailer)
|
|
35
35
|
subject = I18n.t('rails_jwt_auth.mailer.reset_password_instructions.subject')
|
36
36
|
mail(to: @user.email, subject: subject)
|
37
37
|
end
|
38
|
+
|
39
|
+
def set_password_instructions(user)
|
40
|
+
@user = user
|
41
|
+
|
42
|
+
if RailsJwtAuth.set_password_url
|
43
|
+
url, params = RailsJwtAuth.set_password_url.split('?')
|
44
|
+
params = params ? params.split('&') : []
|
45
|
+
params.push("reset_password_token=#{@user.reset_password_token}")
|
46
|
+
|
47
|
+
@reset_password_url = "#{url}?#{params.join('&')}"
|
48
|
+
else
|
49
|
+
@reset_password_url = password_url(reset_password_token: @user.reset_password_token)
|
50
|
+
end
|
51
|
+
|
52
|
+
subject = I18n.t('rails_jwt_auth.mailer.set_password_instructions.subject')
|
53
|
+
mail(to: @user.email, subject: subject)
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
@@ -14,6 +14,22 @@ module RailsJwtAuth
|
|
14
14
|
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
15
15
|
end
|
16
16
|
|
17
|
+
def set_and_send_password_instructions
|
18
|
+
return if password.present?
|
19
|
+
|
20
|
+
self.password = SecureRandom.base58(48)
|
21
|
+
self.password_confirmation = self.password
|
22
|
+
self.skip_confirmation! if self.class.ancestors.include?(RailsJwtAuth::Confirmable)
|
23
|
+
|
24
|
+
self.reset_password_token = SecureRandom.base58(24)
|
25
|
+
self.reset_password_sent_at = Time.now
|
26
|
+
return false unless save
|
27
|
+
|
28
|
+
mailer = Mailer.set_password_instructions(self)
|
29
|
+
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
17
33
|
def self.included(base)
|
18
34
|
if base.ancestors.include? Mongoid::Document
|
19
35
|
# include GlobalID::Identification to use deliver_later method
|
data/config/locales/en.yml
CHANGED
@@ -3,8 +3,10 @@ en:
|
|
3
3
|
mailer:
|
4
4
|
confirmation_instructions:
|
5
5
|
subject: "Confirmation instructions"
|
6
|
-
reset_password_instructions
|
6
|
+
reset_password_instructions:
|
7
7
|
subject: "Reset password instructions"
|
8
|
+
set_password_instructions:
|
9
|
+
subject: "Set password instructions"
|
8
10
|
errors:
|
9
11
|
unconfirmed: "unconfirmed email"
|
10
12
|
already_confirmed: "was already confirmed, please try signing in"
|
@@ -14,7 +16,7 @@ en:
|
|
14
16
|
blank: "blank"
|
15
17
|
not_found: "not found"
|
16
18
|
email:
|
17
|
-
|
19
|
+
invalid: "is not an email"
|
18
20
|
current_password:
|
19
21
|
blank: "blank"
|
20
22
|
invalid: "invalid"
|
data/lib/rails_jwt_auth.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- app/validators/email_validator.rb
|
94
94
|
- app/views/rails_jwt_auth/mailer/confirmation_instructions.html.erb
|
95
95
|
- app/views/rails_jwt_auth/mailer/reset_password_instructions.html.erb
|
96
|
+
- app/views/rails_jwt_auth/mailer/set_password_instructions.html.erb
|
96
97
|
- config/locales/en.yml
|
97
98
|
- lib/generators/rails_jwt_auth/install_generator.rb
|
98
99
|
- lib/generators/templates/initializer.rb
|
@@ -125,9 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
126
|
version: '0'
|
126
127
|
requirements: []
|
127
128
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.5.2
|
129
130
|
signing_key:
|
130
131
|
specification_version: 4
|
131
132
|
summary: Rails jwt authentication.
|
132
133
|
test_files: []
|
133
|
-
has_rdoc:
|