How to make passwords optional using Devise?

拥有回忆 提交于 2020-01-13 05:35:07

问题


How can I make the password optional into the registration and login when authenticating a user (if no password then it will just use the e-mail) using Devise. Although if they register with a password (or update it later) it should then be require for login. How can I accomplish this using Devise?

Note: I'm using Rails 3.0.1 and Devise 1.1.rc0


回答1:


Found in the devise email group by Nat Budin:

class User < ActiveRecord::Base 
  devise :database_authenticatable, :validatable 
  protected 
  def password_required? 
    false 
  end 
end 



回答2:


This is old but I dealt recently with the same issue. My solution was to override the RegistrationsController to send an automatically generated password. It is not ideal as the password is sent in plain text but I really wanted to have a light-touch registration workflow. I've written a short tutorial how to do it.



来源:https://stackoverflow.com/questions/4056254/how-to-make-passwords-optional-using-devise

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