Commit 970c46ec
Changed files (3)
app
app/controllers/passwords_controller.rb
@@ -14,7 +14,12 @@ class PasswordsController < ApplicationController
end
def update
- PasswordReset.reset(params[:id], params[:user][:password])
- redirect_to new_session_path
+ user = PasswordReset.reset(params[:id], params[:user][:password])
+ if user.valid?
+ redirect_to new_session_path
+ else
+ flash[:error] = user.errors.full_messages
+ redirect_to edit_password_path(params[:id])
+ end
end
end
app/models/password_reset.rb
@@ -9,7 +9,9 @@ class PasswordReset
def self.reset(reset_token, new_password)
user = User.find_by(reset_password_token: reset_token)
return if user.nil?
- user.change_password(new_password)
- user.update(reset_password_token: nil, reset_password_sent_at: nil)
+ if user.change_password(new_password)
+ user.update(reset_password_token: nil, reset_password_sent_at: nil)
+ end
+ user
end
end
app/views/passwords/edit.html.erb
@@ -1,21 +1,15 @@
<div class="row-fluid">
<div class="span12">
- <h1>Reset My Password</h1>
+ <h1>Reset Password</h1>
<%= form_for(@user, url: password_path(@user.reset_password_token), html: { method: :put }, class: "form-horizontal") do |f| %>
<fieldset>
- <legend>Enter your new password and confirm it</legend>
+ <legend>Enter your new password</legend>
<div class="control-group">
<%= f.label :password, "New password", class: "control-label" %>
<div class="controls">
<%= f.password_field :password, class: "input-xlarge" %>
</div>
</div>
- <div class="control-group">
- <%= f.label :password_confirmation, "Confirm new password", class: "control-label" %>
- <div class="controls">
- <%= f.password_field :password_confirmation, class: "input-xlarge" %>
- </div>
- </div>
<div class="form-actions">
<%= f.hidden_field :reset_password_token %>
<%= f.submit "Change my password", class: 'btn btn-primary' %>