volt-user_templates 0.4.0 → 0.5.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: 145bf08ec26e29200d73efe316caeec2374efe25
4
- data.tar.gz: eb4990ffeb13fae9a9c107116b6cce6d26d1944b
3
+ metadata.gz: 7ef97ee96b9b07032420a48e92daf33344d57735
4
+ data.tar.gz: 7e4403bf01ddb8327290915c9753fa0fad7c9d46
5
5
  SHA512:
6
- metadata.gz: 69a7cca480dcb1d833dc0ca04341191388d2bb555e4bbc0cc90b4bf759e7784c01ec5fab592af922762b05bc376575b86745ae7d3afaf539310f7549383c7a8a
7
- data.tar.gz: 52daf097444a39267f1fe516daf7680dba838f976845cb8a41addd3d2aef12f08438ec4ead2badc036414003cc5763eba0635ceab285f76e3c9cb89f3dfc5417
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.4.0
1
+ 0.5.0
@@ -36,7 +36,7 @@ module UserTemplates
36
36
  flash._notices << 'Reset email sent.'
37
37
  redirect_to(attrs.post_forgot_url || '/login')
38
38
  end.fail do |err|
39
- flash._errors << err.to_s
39
+ flash._errors << err.message
40
40
  end
41
41
  end
42
42
 
@@ -1,10 +1,29 @@
1
1
  module UserTemplates
2
2
  class PasswordResetController < Volt::ModelController
3
- reactive_accessor :new_password
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 'digest'
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).fetch_first do |user|
7
+ store._users.where(email: email).first.then do |user|
8
8
  if user
9
- reset_token = password_reset_token(user.id)
9
+ reset_token = UserTemplates::PasswordResetToken.for_user(user.id)
10
10
 
11
- reset_base_url = url_for(component: 'user_templates',
12
- controller: 'password_reset', action: 'index')
13
-
14
- reset_url = "http://#{Volt.config.domain}/#{reset_base_url}/?"
15
- + "user_id=#{user_id}&token=#{reset_token}"
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
- <h1>Reset Password</h1>
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.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-06-05 00:00:00.000000000 Z
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