mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
More work on edit.
This commit is contained in:
parent
2761a75437
commit
d7db5b1eea
6 changed files with 54 additions and 22 deletions
|
@ -1,3 +1,6 @@
|
|||
* deprecation
|
||||
* :old_password in update_with_password is deprecated, use :current_password instead
|
||||
|
||||
* enhancements
|
||||
* Added Registerable
|
||||
* Added Http Basic Authentication support
|
||||
|
|
24
app/views/registrations/edit.html.erb
Normal file
24
app/views/registrations/edit.html.erb
Normal file
|
@ -0,0 +1,24 @@
|
|||
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
||||
|
||||
<% form_for resource_name, resource, :url => registration_path(resource_name) do |f| -%>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<h4>Change your settings<h4>
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
|
||||
<h4>Change your password (leave blank if you don't want to)</h4>
|
||||
<p><%= f.label :password %></p>
|
||||
<p><%= f.password_field :password %></p>
|
||||
|
||||
<p><%= f.label :password_confirmation %></p>
|
||||
<p><%= f.password_field :password_confirmation %></p>
|
||||
|
||||
<h4>We need your current password to confirm your changes</h4>
|
||||
<p><%= f.label :current_password %></p>
|
||||
<p><%= f.password_field :current_password %></p>
|
||||
|
||||
<p><%= f.submit "Update" %></p>
|
||||
<% end -%>
|
||||
|
||||
<%= render :partial => "shared/devise_links" %>
|
|
@ -1,19 +1,17 @@
|
|||
<h2>Sign in</h2>
|
||||
|
||||
<%- if devise_mapping.authenticatable? %>
|
||||
<% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
<% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
|
||||
<p><%= f.label :email %></p>
|
||||
<p><%= f.text_field :email %></p>
|
||||
|
||||
<p><%= f.label :password %></p>
|
||||
<p><%= f.password_field :password %></p>
|
||||
<p><%= f.label :password %></p>
|
||||
<p><%= f.password_field :password %></p>
|
||||
|
||||
<% if devise_mapping.rememberable? -%>
|
||||
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
|
||||
<% end -%>
|
||||
|
||||
<p><%= f.submit "Sign in" %></p>
|
||||
<% if devise_mapping.rememberable? -%>
|
||||
<p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
|
||||
<% end -%>
|
||||
<% end%>
|
||||
|
||||
<p><%= f.submit "Sign in" %></p>
|
||||
<% end -%>
|
||||
|
||||
<%= render :partial => "shared/devise_links" %>
|
|
@ -32,11 +32,16 @@ module Devise
|
|||
base.class_eval do
|
||||
extend ClassMethods
|
||||
|
||||
attr_reader :password, :old_password
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
end
|
||||
end
|
||||
|
||||
def old_password
|
||||
ActiveSupport::Deprecation.warn "old_password is deprecated, please use current_password instead", caller
|
||||
@old_password
|
||||
end
|
||||
|
||||
# Regenerates password salt and encrypted password each time password is set,
|
||||
# and then trigger any "after_changed_password"-callbacks.
|
||||
def password=(new_password)
|
||||
|
@ -67,10 +72,12 @@ module Devise
|
|||
# Update record attributes when :old_password matches, otherwise returns
|
||||
# error on :old_password.
|
||||
def update_with_password(params={})
|
||||
if valid_password?(params[:old_password])
|
||||
params[:current_password] ||= params[:old_password] if params[:old_password]
|
||||
|
||||
if valid_password?(params[:current_password])
|
||||
update_attributes(params)
|
||||
else
|
||||
self.class.add_error_on(self, :old_password, :invalid, false)
|
||||
self.class.add_error_on(self, :current_password, :invalid, false)
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Devise
|
||||
VERSION = "0.9.2".freeze
|
||||
VERSION = "1.0.0".freeze
|
||||
end
|
||||
|
|
|
@ -130,28 +130,28 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|||
assert_not_nil Admin.authenticate(:email => admin.email, :password => admin.password)
|
||||
end
|
||||
|
||||
test 'should respond to old password' do
|
||||
assert new_user.respond_to?(:old_password)
|
||||
test 'should respond to current password' do
|
||||
assert new_user.respond_to?(:current_password)
|
||||
end
|
||||
|
||||
test 'should update password with valid old password' do
|
||||
user = create_user
|
||||
assert user.update_with_password(:old_password => '123456',
|
||||
assert user.update_with_password(:current_password => '123456',
|
||||
:password => 'pass321', :password_confirmation => 'pass321')
|
||||
assert user.reload.valid_password?('pass321')
|
||||
end
|
||||
|
||||
test 'should add an error to old password when it is invalid' do
|
||||
user = create_user
|
||||
assert_not user.update_with_password(:old_password => 'other',
|
||||
assert_not user.update_with_password(:current_password => 'other',
|
||||
:password => 'pass321', :password_confirmation => 'pass321')
|
||||
assert user.reload.valid_password?('123456')
|
||||
assert_match /invalid/, user.errors[:old_password]
|
||||
assert_match /invalid/, user.errors[:current_password]
|
||||
end
|
||||
|
||||
test 'should not update password with invalid confirmation' do
|
||||
user = create_user
|
||||
assert_not user.update_with_password(:old_password => '123456',
|
||||
assert_not user.update_with_password(:current_password => '123456',
|
||||
:password => 'pass321', :password_confirmation => 'other')
|
||||
assert user.reload.valid_password?('123456')
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue