Authlogic turn off require_password_confirmation for a certain case

南楼画角 提交于 2019-12-11 10:42:26

问题


I have an app that uses authlogic for login mechanism.

My sign up page requires no password confirmation but password reset page does.

acts_as_authentic do |a|
  a.require_password_confirmation = true
end 

The above code turns on password confirmation for all the actions but which is not required in my case. It should be turned on when password reset is called and off when user signs up.

Is there a way to turn this on and off on a conditional basis ?

Thanks


回答1:


Set password confirmation to false.

acts_as_authentic do |a|
  a.require_password_confirmation = false
end 

Set the password_confirmation value in the create action of UsersController.

before_action :set_password_confirmation, :only => :create

def set_password_confirmation
  if params[:user] 
    params[:user][:password_confirmation] = params[:user][:password]
  end
end


来源:https://stackoverflow.com/questions/24675303/authlogic-turn-off-require-password-confirmation-for-a-certain-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!