thincloud-authentication 0.5.0 → 0.5.1
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.
- data/app/controllers/thincloud/authentication/passwords_controller.rb +44 -0
- data/app/mailers/thincloud/authentication/passwords_mailer.rb +12 -0
- data/app/models/thincloud/authentication/identity.rb +11 -0
- data/app/services/thincloud/authentication/password_reset_workflow.rb +10 -0
- data/app/services/thincloud/authentication/update_identity_password.rb +17 -0
- data/app/views/thincloud/authentication/passwords/edit.html.erb +35 -0
- data/app/views/thincloud/authentication/passwords/new.html.erb +31 -0
- data/app/views/thincloud/authentication/passwords_mailer/password_reset.html.erb +5 -0
- data/app/views/thincloud/authentication/sessions/_login_form.html.erb +4 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20130505230811_add_password_reset_token_and_password_reset_sent_at_to_identities.rb +8 -0
- data/lib/thincloud/authentication/authenticatable_controller.rb +6 -0
- data/lib/thincloud/authentication/version.rb +1 -1
- metadata +11 -3
@@ -0,0 +1,44 @@
|
|
1
|
+
module Thincloud::Authentication
|
2
|
+
# Public: Handle password reset management
|
3
|
+
class PasswordsController < ApplicationController
|
4
|
+
|
5
|
+
before_filter :find_identity, only: [:edit, :update]
|
6
|
+
|
7
|
+
layout Thincloud::Authentication.configuration.layout
|
8
|
+
|
9
|
+
def new
|
10
|
+
render
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
PasswordResetWorkflow.call(params[:email])
|
15
|
+
redirect_to login_url,
|
16
|
+
notice: "Email sent with password reset instructions."
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit
|
20
|
+
render
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
if UpdateIdentityPassword.call(@identity, identity_params)
|
25
|
+
login_as @identity.user
|
26
|
+
redirect_to after_password_update_path
|
27
|
+
else
|
28
|
+
render :edit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def find_identity
|
36
|
+
@identity = Identity.find_by_password_reset_token!(params[:id])
|
37
|
+
end
|
38
|
+
|
39
|
+
def identity_params
|
40
|
+
params.require(:identity).permit(:password, :password_confirmation)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Thincloud::Authentication
|
2
|
+
# Public: Email methods for Password events
|
3
|
+
class PasswordsMailer < ActionMailer::Base
|
4
|
+
default from: Thincloud::Authentication.configuration.mailer_sender
|
5
|
+
|
6
|
+
# Password reset notification
|
7
|
+
def password_reset(identity_id)
|
8
|
+
@identity = Identity.find(identity_id)
|
9
|
+
mail to: @identity.email, subject: "Password Reset"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -77,5 +77,16 @@ module Thincloud::Authentication
|
|
77
77
|
self.email = info["email"] if info["email"] && self.email.blank?
|
78
78
|
self
|
79
79
|
end
|
80
|
+
|
81
|
+
# Public: Generate a password reset token
|
82
|
+
#
|
83
|
+
# Returns: true
|
84
|
+
#
|
85
|
+
# Raises: ActiveRecord::RecordInvalid
|
86
|
+
def generate_password_token!
|
87
|
+
self.password_reset_token = SecureRandom.urlsafe_base64
|
88
|
+
self.password_reset_sent_at = Time.zone.now
|
89
|
+
save!
|
90
|
+
end
|
80
91
|
end
|
81
92
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Thincloud::Authentication
|
2
|
+
# Public: Execute the workflow steps to reset a password for an Identity
|
3
|
+
class PasswordResetWorkflow
|
4
|
+
def self.call(email)
|
5
|
+
return unless identity = Identity.find_by_email(email)
|
6
|
+
identity.generate_password_token!
|
7
|
+
PasswordsMailer.password_reset(identity.id).deliver
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Thincloud::Authentication
|
2
|
+
# Public: Execute the workflow steps to reset a password for an Identity
|
3
|
+
class UpdateIdentityPassword
|
4
|
+
|
5
|
+
def self.call(identity, params)
|
6
|
+
identity.password = params[:password]
|
7
|
+
identity.password_confirmation = params[:password_confirmation]
|
8
|
+
identity.password_reset_token = nil
|
9
|
+
identity.password_reset_sent_at = nil
|
10
|
+
identity.save!
|
11
|
+
rescue ActiveRecord::RecordInvalid
|
12
|
+
identity.reload
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<%= form_for @identity, url: password_url(id: @identity.password_reset_token), method: :put do |f| %>
|
2
|
+
<fieldset>
|
3
|
+
<legend>Password Reset</legend>
|
4
|
+
|
5
|
+
<div class="control-group">
|
6
|
+
<%= f.label :password, "Password", class: "control-label" %>
|
7
|
+
|
8
|
+
<div class="controls">
|
9
|
+
<div class="input-prepend">
|
10
|
+
<span class="add-on"><i class="icon-envelope"></i></span>
|
11
|
+
<%= f.password_field :password %>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="control-group">
|
17
|
+
<%= f.label :password_confirmation, "Password Confirmation", class: "control-label" %>
|
18
|
+
|
19
|
+
<div class="controls">
|
20
|
+
<div class="input-prepend">
|
21
|
+
<span class="add-on"><i class="icon-envelope"></i></span>
|
22
|
+
<%= f.password_field :password_confirmation %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="control-group">
|
28
|
+
<div class="controls">
|
29
|
+
<%= button_tag type: "submit", class: "btn btn-large btn-primary" do %>
|
30
|
+
<i class="icon-ok icon-white"></i> Submit
|
31
|
+
<% end %>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</fieldset>
|
35
|
+
<% end %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<%= form_tag passwords_url, method: :post do %>
|
2
|
+
<fieldset>
|
3
|
+
<legend>Password Reset</legend>
|
4
|
+
|
5
|
+
<div class="control-group">
|
6
|
+
<%= label_tag :email, "Email", class: "control-label" %>
|
7
|
+
|
8
|
+
<div class="controls">
|
9
|
+
<div class="input-prepend">
|
10
|
+
<span class="add-on"><i class="icon-envelope"></i></span>
|
11
|
+
<%= email_field_tag :email %>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="control-group">
|
17
|
+
<div class="controls">
|
18
|
+
<%= button_tag type: "submit", class: "btn btn-large btn-primary" do %>
|
19
|
+
<i class="icon-ok icon-white"></i> Submit
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
or
|
23
|
+
|
24
|
+
<%= link_to login_url, class: "btn btn-large" do %>
|
25
|
+
<i class="icon-user"></i> Login
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
</fieldset>
|
31
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -10,5 +10,7 @@ Thincloud::Authentication::Engine.routes.draw do
|
|
10
10
|
get "signup", to: "registrations#new", as: "signup"
|
11
11
|
get "verify/:token", to: "registrations#verify", as: "verify_token"
|
12
12
|
|
13
|
+
resources :passwords, only: [:new, :edit, :create, :update]
|
14
|
+
|
13
15
|
root to: "sessions#new"
|
14
16
|
end
|
data/db/migrate/20130505230811_add_password_reset_token_and_password_reset_sent_at_to_identities.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddPasswordResetTokenAndPasswordResetSentAtToIdentities < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :thincloud_authentication_identities, :password_reset_token,
|
4
|
+
:string, default: nil
|
5
|
+
add_column :thincloud_authentication_identities, :password_reset_sent_at,
|
6
|
+
:datetime, default: nil
|
7
|
+
end
|
8
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thincloud-authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -102,12 +102,19 @@ extra_rdoc_files: []
|
|
102
102
|
files:
|
103
103
|
- app/assets/javascripts/thincloud/authentication/application.js
|
104
104
|
- app/assets/stylesheets/thincloud/authentication/application.css
|
105
|
+
- app/controllers/thincloud/authentication/passwords_controller.rb
|
105
106
|
- app/controllers/thincloud/authentication/registrations_controller.rb
|
106
107
|
- app/controllers/thincloud/authentication/sessions_controller.rb
|
107
108
|
- app/helpers/thincloud/authentication/registrations_helper.rb
|
109
|
+
- app/mailers/thincloud/authentication/passwords_mailer.rb
|
108
110
|
- app/mailers/thincloud/authentication/registrations_mailer.rb
|
109
111
|
- app/models/thincloud/authentication/identity.rb
|
112
|
+
- app/services/thincloud/authentication/password_reset_workflow.rb
|
113
|
+
- app/services/thincloud/authentication/update_identity_password.rb
|
110
114
|
- app/views/thincloud/authentication/layouts/application.html.erb
|
115
|
+
- app/views/thincloud/authentication/passwords/edit.html.erb
|
116
|
+
- app/views/thincloud/authentication/passwords/new.html.erb
|
117
|
+
- app/views/thincloud/authentication/passwords_mailer/password_reset.html.erb
|
111
118
|
- app/views/thincloud/authentication/registrations/_registration_form.html.erb
|
112
119
|
- app/views/thincloud/authentication/registrations/new.html.erb
|
113
120
|
- app/views/thincloud/authentication/registrations_mailer/verification_token.text.erb
|
@@ -115,6 +122,7 @@ files:
|
|
115
122
|
- app/views/thincloud/authentication/sessions/new.html.erb
|
116
123
|
- config/routes.rb
|
117
124
|
- db/migrate/20120918233329_create_thincloud_authentication_identities.rb
|
125
|
+
- db/migrate/20130505230811_add_password_reset_token_and_password_reset_sent_at_to_identities.rb
|
118
126
|
- lib/tasks/thincloud-authentication_tasks.rake
|
119
127
|
- lib/thincloud/authentication/authenticatable_controller.rb
|
120
128
|
- lib/thincloud/authentication/configuration.rb
|
@@ -139,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
147
|
version: '0'
|
140
148
|
segments:
|
141
149
|
- 0
|
142
|
-
hash:
|
150
|
+
hash: 3741516582425724511
|
143
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
152
|
none: false
|
145
153
|
requirements:
|
@@ -148,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
156
|
version: '0'
|
149
157
|
segments:
|
150
158
|
- 0
|
151
|
-
hash:
|
159
|
+
hash: 3741516582425724511
|
152
160
|
requirements: []
|
153
161
|
rubyforge_project:
|
154
162
|
rubygems_version: 1.8.23
|