1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge and fix conflicts.

This commit is contained in:
Carlos Antonio da Silva 2009-12-14 23:02:10 -02:00
commit 82ab50f774
7 changed files with 44 additions and 5 deletions

View file

@ -1,3 +1,7 @@
* enhancements
* Do not care about blank passwords on update
* Mail views are scoped as well
== 0.7.2 == 0.7.2
* deprecation * deprecation

View file

@ -26,7 +26,7 @@ class DeviseMailer < ::ActionMailer::Base
# Configure default email options # Configure default email options
def setup_mail(record, key) def setup_mail(record, key)
mapping = Devise.mappings.values.find { |m| m.to == record.class } mapping = Devise::Mapping.find_by_class(record.class)
raise "Invalid devise resource #{record}" unless mapping raise "Invalid devise resource #{record}" unless mapping
subject translate(mapping, key) subject translate(mapping, key)
@ -34,7 +34,19 @@ class DeviseMailer < ::ActionMailer::Base
recipients record.email recipients record.email
sent_on Time.now sent_on Time.now
content_type 'text/html' content_type 'text/html'
body mapping.name => record, :resource => record body render_with_scope(key, mapping, mapping.name => record, :resource => record)
end
def render_with_scope(key, mapping, assigns)
if Devise.scoped_views
begin
render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
rescue ActionView::MissingTemplate
render :file => "devise_mailer/#{key}", :body => assigns
end
else
render :file => "devise_mailer/#{key}", :body => assigns
end
end end
# Setup subject namespaced by model. It means you're able to setup your # Setup subject namespaced by model. It means you're able to setup your

View file

@ -41,8 +41,9 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in DeviseMailer. # Configure the e-mail address which will be shown in DeviseMailer.
# config.mailer_sender = "foo.bar@yourapp.com" # config.mailer_sender = "foo.bar@yourapp.com"
# Configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper. # Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
# config.orm = :active_record # require 'devise/orm/mongo_mapper'
# config.orm = :mongo_mapper
# Turn scoped views on. Before rendering "sessions/new", it will first check for # Turn scoped views on. Before rendering "sessions/new", it will first check for
# "sessions/users/new". It's turned off by default because it's slower if you # "sessions/users/new". It's turned off by default because it's slower if you

View file

@ -62,7 +62,7 @@ module Devise
end end
end end
# Verifies whether an incoming_password (ie from login) is the user password. # Verifies whether an incoming_password (ie from sign in) is the user password.
def valid_password?(incoming_password) def valid_password?(incoming_password)
password_digest(incoming_password) == encrypted_password password_digest(incoming_password) == encrypted_password
end end
@ -78,6 +78,14 @@ module Devise
end end
end end
# Overwrite update_attributes to not care for blank passwords.
def update_attributes(attributes)
[:password, :password_confirmation].each do |k|
attributes.delete(k) unless attributes[k].present?
end
super
end
protected protected
# Digests the password using the configured encryptor. # Digests the password using the configured encryptor.

View file

@ -56,4 +56,10 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">} confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
assert_match confirmation_url_regexp, mail.body assert_match confirmation_url_regexp, mail.body
end end
test 'renders a scoped if scoped_views is set to true' do
swap Devise, :scoped_views => true do
assert_equal user.email, mail.body
end
end
end end

View file

@ -27,6 +27,13 @@ class AuthenticatableTest < ActiveSupport::TestCase
assert_equal salt, user.password_salt assert_equal salt, user.password_salt
end end
test 'should not care about empty password on update' do
user = create_user
user.update_attributes(:email => "jose.valim+updated@gmail.com", :password => "")
user.reload
assert_equal user.email, "jose.valim+updated@gmail.com"
end
test 'should generate a base64 hash using SecureRandom for password salt' do test 'should generate a base64 hash using SecureRandom for password salt' do
ActiveSupport::SecureRandom.expects(:base64).with(15).returns('friendly_token') ActiveSupport::SecureRandom.expects(:base64).with(15).returns('friendly_token')
assert_equal 'friendly_token', new_user.password_salt assert_equal 'friendly_token', new_user.password_salt

View file

@ -0,0 +1 @@
<%= @resource.email %>