volt-user_templates 0.4.0 → 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 +1 -0
- data/VERSION +1 -1
- data/app/user_templates/controllers/login_controller.rb +1 -1
- data/app/user_templates/controllers/password_reset_controller.rb +22 -3
- data/app/user_templates/lib/password_reset_token.rb +23 -0
- data/app/user_templates/tasks/password_reset_tasks.rb +16 -0
- data/app/user_templates/tasks/user_template_tasks.rb +12 -13
- data/app/user_templates/views/mailers/forgot.email +1 -0
- data/app/user_templates/views/password_reset/index.html +20 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef97ee96b9b07032420a48e92daf33344d57735
|
4
|
+
data.tar.gz: 7e4403bf01ddb8327290915c9753fa0fad7c9d46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d560a321793d17042556aac4db166e410dec2240012259cb732cbc466ec02e98d0be62f3458a82678e576c8073bf68d86602d7058f458a51b4ee92f37cfeff05
|
7
|
+
data.tar.gz: 8d681d3ff453aab5b317fe178f79346cdbc79671cf9377f416b6d3e23727bbec509a6fa5246858b1b147c5ccb8b27f9e9dcdae34d00dca4a703cdc96c4f414ae
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ client '/signup', component: 'user_templates', controller: 'signup'
|
|
31
31
|
client '/password_reset', component: 'user_templates', controller: 'password_reset', action: 'index'
|
32
32
|
client '/forgot', component: 'user_templates', controller: 'login', action: 'forgot'
|
33
33
|
client '/login', component: 'user_templates', controller: 'login', action: 'index'
|
34
|
+
client '/account', component: 'user_templates', controller: 'account', action: 'index'
|
34
35
|
```
|
35
36
|
|
36
37
|
Now you can link to /signup and /login
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -1,10 +1,29 @@
|
|
1
1
|
module UserTemplates
|
2
2
|
class PasswordResetController < Volt::ModelController
|
3
|
-
reactive_accessor :
|
3
|
+
reactive_accessor :user, :errors
|
4
|
+
|
5
|
+
def index
|
6
|
+
self.user = store.users.buffer
|
7
|
+
user.password = ''
|
8
|
+
end
|
4
9
|
|
5
10
|
def reset_password
|
11
|
+
self.errors = nil
|
12
|
+
user.mark_all_fields!
|
13
|
+
user.validate!.fail do |errs|
|
14
|
+
# .validate! changed with the sql branch, so we support both versions
|
15
|
+
# here
|
16
|
+
unless errs[:password]
|
17
|
+
PasswordResetTasks.reset_password(params._user_id, params._token, user.password).then do
|
18
|
+
flash._notices << 'Password updated'
|
19
|
+
user.password = ''
|
6
20
|
|
21
|
+
redirect_to '/'
|
22
|
+
end.fail do |err|
|
23
|
+
self.errors = err
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
7
27
|
end
|
8
|
-
|
9
28
|
end
|
10
|
-
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module UserTemplates
|
4
|
+
module PasswordResetToken
|
5
|
+
def self.for_user(user_id, time_offset=0)
|
6
|
+
# Get a token with the hour as part of the hash.
|
7
|
+
time_num = time_offset.hours.ago.beginning_of_hour.to_i
|
8
|
+
|
9
|
+
Digest::SHA256.hexdigest("#{user_id}||#{Volt.config.app_secret}||#{time_num}")
|
10
|
+
end
|
11
|
+
|
12
|
+
# Checks for the current hour or the previous for the valid token
|
13
|
+
def self.valid_token_for_user?(user_id, token)
|
14
|
+
if for_user(user_id, 0) == token
|
15
|
+
true
|
16
|
+
elsif for_user(user_id, 1) == token
|
17
|
+
true
|
18
|
+
else
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,21 @@
|
|
1
|
+
require 'user_templates/lib/password_reset_token'
|
2
|
+
|
1
3
|
class PasswordResetTasks < Volt::Task
|
2
4
|
def reset_password(user_id, token, new_password)
|
5
|
+
valid = UserTemplates::PasswordResetToken.valid_token_for_user?(user_id, token)
|
6
|
+
|
7
|
+
if valid
|
8
|
+
Volt.skip_permissions do
|
9
|
+
user = store.users.where(id: user_id).first.sync.buffer
|
3
10
|
|
11
|
+
user.password = new_password
|
12
|
+
user.save!.then do
|
13
|
+
login_as(user)
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
else
|
18
|
+
raise "The password reset link has expired."
|
19
|
+
end
|
4
20
|
end
|
5
21
|
end
|
@@ -1,31 +1,30 @@
|
|
1
|
-
require '
|
1
|
+
require 'user_templates/lib/password_reset_token'
|
2
2
|
|
3
3
|
class UserTemplateTasks < Volt::Task
|
4
4
|
def send_reset_email(email)
|
5
5
|
# Find user by e-mail
|
6
6
|
Volt.skip_permissions do
|
7
|
-
store._users.where(email: email).
|
7
|
+
store._users.where(email: email).first.then do |user|
|
8
8
|
if user
|
9
|
-
reset_token =
|
9
|
+
reset_token = UserTemplates::PasswordResetToken.for_user(user.id)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
reset_url, _ = url_for(
|
12
|
+
component: 'user_templates',
|
13
|
+
controller: 'password_reset',
|
14
|
+
action: 'index',
|
15
|
+
user_id: user.id,
|
16
|
+
token: reset_token
|
17
|
+
)
|
16
18
|
|
17
19
|
Mailer.deliver('user_templates/mailers/forgot',
|
18
20
|
{to: email, name: user._name, reset_url: reset_url}
|
19
21
|
)
|
22
|
+
|
23
|
+
nil
|
20
24
|
else
|
21
25
|
raise "There is no account with the e-mail of #{email}."
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def password_reset_token(user_id)
|
29
|
-
Digest::SHA256.hexdigest("#{user_id}||#{Volt.config.app_secret}")
|
30
|
-
end
|
31
30
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
Reset your Password
|
3
3
|
|
4
4
|
<:Html>
|
5
|
+
<a href="{{ reset_url }}">Some Url</a>
|
5
6
|
<html>
|
6
7
|
<body>
|
7
8
|
<table cellspacing="0" cellpadding="0" border="0" style="color: #333; background: #fff; padding: 0; margin: 0; width: 100%; font: 15px/1.25em 'Helvetica Neue', Arial, Helvetica;">
|
@@ -2,9 +2,24 @@
|
|
2
2
|
Reset Password
|
3
3
|
|
4
4
|
<:Body>
|
5
|
-
|
5
|
+
<div class="row">
|
6
|
+
<div class="col-md-6 col-md-offset-3">
|
7
|
+
<div class="span4 offset4 well">
|
8
|
+
<legend>Reset Your Password</legend>
|
9
|
+
|
10
|
+
<form e-submit="reset_password">
|
11
|
+
{{ if errors.present? }}
|
12
|
+
<div class="alert alert-danger">{{ errors }}</div>
|
13
|
+
{{ end }}
|
14
|
+
|
15
|
+
<div class="form-group">
|
16
|
+
<label class="control-label">New Password</label>
|
17
|
+
<:fields:text type="password" label="false" value="{{ user.password }}" />
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<button class="btn btn-info btn-block">Reset Password</button>
|
21
|
+
</form>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</div>
|
6
25
|
|
7
|
-
<form e-click="reset_password">
|
8
|
-
<:fields:password label="New Password" value="{{ new_password }}" />
|
9
|
-
<button>Reset Password</button>
|
10
|
-
</form>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt-user_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: volt-fields
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- app/user_templates/controllers/menu_controller.rb
|
72
72
|
- app/user_templates/controllers/password_reset_controller.rb
|
73
73
|
- app/user_templates/controllers/signup_controller.rb
|
74
|
+
- app/user_templates/lib/password_reset_token.rb
|
74
75
|
- app/user_templates/tasks/password_reset_tasks.rb
|
75
76
|
- app/user_templates/tasks/user_template_tasks.rb
|
76
77
|
- app/user_templates/views/account/index.html
|