diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index 91071e51..38ed82b9 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -1,9 +1,13 @@ class ConfirmationsController < ApplicationController before_filter :require_no_authentication + # GET /confirmation/new + # def new end + # POST /confirmation + # def create @confirmation = User.send_confirmation_instructions(params[:confirmation]) if @confirmation.errors.empty? @@ -14,6 +18,8 @@ class ConfirmationsController < ApplicationController end end + # GET /confirmation?perishable_token=abcdef + # def show @confirmation = User.confirm!(:perishable_token => params[:perishable_token]) if @confirmation.errors.empty? diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index 8d7a1804..de1d37e2 100644 --- a/app/controllers/passwords_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -1,9 +1,13 @@ class PasswordsController < ApplicationController before_filter :require_no_authentication + # GET /password/new + # def new end + # POST /password + # def create @password = User.send_reset_password_instructions(params[:password]) if @password.errors.empty? @@ -14,11 +18,15 @@ class PasswordsController < ApplicationController end end + # GET /password/edit?perishable_token=abcdef + # def edit @password = User.new @password.perishable_token = params[:perishable_token] end + # PUT /password + # def update @password = User.reset_password!(params[:password]) if @password.errors.empty? diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index f481914f..7d8678d8 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -2,13 +2,19 @@ class SessionsController < ApplicationController before_filter :authenticate!, :except => :new before_filter :require_no_authentication, :only => :new + # GET /session/new + # def new end + # POST /session + # def create redirect_to root_path if authenticated? end + # DELETE /session + # def destroy redirect_to :action => :new if logout end diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 077ea87c..a220aae4 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -5,14 +5,14 @@ class Notifier < ::ActionMailer::Base # is manually requested # def confirmation_instructions(record) - subject I18n.t(:confirmation_instructions, :scope => [:devise, :notifier], :default => 'Confirmation instructions') + subject translate(:confirmation_instructions, :default => 'Confirmation instructions') setup_mail(record) end # Deliver reset password instructions when manually requested # def reset_password_instructions(record) - subject I18n.t(:reset_password_instructions, :scope => [:devise, :notifier], :default => 'Reset password instructions') + subject translate(:reset_password_instructions, :default => 'Reset password instructions') setup_mail(record) end @@ -25,4 +25,8 @@ class Notifier < ::ActionMailer::Base content_type 'text/html' body record.class.name.downcase.to_sym => record end + + def translate(key, options={}) + I18n.t(key, {:scope => [:devise, :notifier]}.merge(options)) + end end diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index acc2fdee..90cd0ba5 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -52,12 +52,8 @@ module Devise # Options must contain the user email # def send_confirmation_instructions(options={}) - confirmable = find_or_initialize_by_email(options[:email]) - unless confirmable.new_record? - confirmable.send_confirmation_instructions - else - confirmable.errors.add(:email, :not_found, :default => 'not found') - end + confirmable = find_or_initialize_with_error_by_email(options[:email]) + confirmable.send_confirmation_instructions unless confirmable.new_record? confirmable end diff --git a/lib/devise/models/perishable.rb b/lib/devise/models/perishable.rb index d99f4ee7..9c4595f3 100644 --- a/lib/devise/models/perishable.rb +++ b/lib/devise/models/perishable.rb @@ -29,7 +29,18 @@ module Devise def find_or_initialize_with_error_by_perishable_token(perishable_token) perishable = find_or_initialize_by_perishable_token(perishable_token) if perishable.new_record? - perishable.errors.add(:perishable_token, :invalid, :default => "invalid confirmation") + perishable.errors.add(:perishable_token, :invalid, :default => 'invalid confirmation') + end + perishable + end + + # Attempt to find a user by it's email. If not user is found, returns a + # new user with an email not found error. + # + def find_or_initialize_with_error_by_email(email) + perishable = find_or_initialize_by_email(email) + if perishable.new_record? + perishable.errors.add(:email, :not_found, :default => 'not found') end perishable end diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index 52c166af..fc14047d 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -37,12 +37,8 @@ module Devise # Options must contain the user email # def send_reset_password_instructions(options={}) - recoverable = find_or_initialize_by_email(options[:email]) - unless recoverable.new_record? - recoverable.send_reset_password_instructions - else - recoverable.errors.add(:email, :not_found, :default => 'not found') - end + recoverable = find_or_initialize_with_error_by_email(options[:email]) + recoverable.send_reset_password_instructions unless recoverable.new_record? recoverable end