How to Remove Devise Password Resetting During Email Confirmation

Devise and confirmation emails

You can override devise mailer to meet your requirements.

First of all create DeviseMailer

# app/mailers/devise/mailer.eb
if defined?(ActionMailer)
class Devise::Mailer < Devise.parent_mailer.constantize
include Devise::Mailers::Helpers

def confirmation_instructions(record, token, opts = {})
@token = token
if record.pending_reconfirmation?
devise_mail(record, :reconfirmation_instructions, opts)
else
devise_mail(record, :confirmation_instructions, opts)
end
end

def reset_password_instructions(record, token, opts = {})
@token = token
devise_mail(record, :reset_password_instructions, opts)
end

def unlock_instructions(record, token, opts = {})
@token = token
devise_mail(record, :unlock_instructions, opts)
end
end
end

Then just create needed views in app/views/devise/mailer/ for each of methods:

  • reconfirmation_instructions, will be called when user changes they email
  • confirmation_instructions, will be called when user confirms they email
  • unlock_instructions, when account is locked
  • reset_instructions, on password reset

Actually you can create any template you'd like.

Hope that will help.

How to prevent automatic signin after confirmation and setting password using devise

Change your config/initializers/devise.rb

you'll see...

  # When set to false, does not sign a user in automatically after their password is
# reset. Defaults to true, so a user is signed in automatically after a reset.
# config.sign_in_after_reset_password = true

Uncomment and change the last line to

  config.sign_in_after_reset_password = false

How to change Devise: password reset instruction email's subject

you can change it in devise.en.yml file in intilizer directory

And set your own subject for any mailer

                   mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'

Devise: Disable password confirmation during sign-up

To disable password confirmation you can simply remove the password_confirmation field from the registration form. This disables the need to confirm the password entirely!

  1. Generate devise views if you haven't: rails g devise:views
  2. Remove the password_confirmation section in app\views\devise\registrations\new.html.erb

The reason why this works lies in lib/devise/models/validatable.rb in the Devise source:

module Devise
module Models
module Validatable


def self.included(base)

base.class_eval do
#....SNIP...
validates_confirmation_of :password, :if => :password_required?
end
end

#...SNIP...

def password_required?
!persisted? || !password.nil? || !password_confirmation.nil?
end
end
end
end

Note that the validation is only triggered if password_required? returns true, and password_required? will return false if the password_confirmation field is nil.

Because where the password_confirmation field is present in the form, it will always be included in the parameters hash , as an empty string if it is left blank, the validation is triggered. However, if you remove the input from the form, the password_confirmation in the params will be nil, and therefore the validation will not be triggered.

Rails/Devise---Password Reset & Resend Confirmation How To Redirect to Homepage

  1. How to change redirect on reset password instructions to go to home page, not user sign in page.

just put this in your passwords controller

protected 
def after_sending_reset_password_instructions_path_for(resource_name)
root_path
end



  1. How to change redirect on resend confirmation instructions to go to home page, not user sign in page.

create new confirmations_controller.rb and put this

class ConfirmationsController < Devise::ConfirmationsController
protected
def after_resending_confirmation_instructions_path_for(resource_name)
root_path
end
end

and in routes

 devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }



  1. How to make it so users can no longer access users/sign_in page

Simple trick is to redirect the user to the home page since your website is in production. remove the path might cause some problem so best is to do this

 get 'users/sign_in' => redirect("/")


Side note:

If all you want to signin in root page, you could have used this

  root :to => "devise/sessions#new"


update

you have to remove this line from route.rb file

 devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }
get 'users/sign_in' => redirect("/")

and add this

  get 'users/sign_in' => redirect("/")
get '/users/sign_out' => 'devise/sessions#destroy'
devise_for :users, :controllers => { :passwords => "passwords" , :confirmations => "confirmations" }


Related Topics



Leave a reply



Submit