How to change email address of a user in devise “safely”?

前端 未结 2 1728
情话喂你
情话喂你 2021-02-01 10:02

By default, devise uses an email address for sign up and sign in.

But I want that the email address should be allowed to be changed by the user.

If I allow the u

2条回答
  •  别跟我提以往
    2021-02-01 10:52

    You can force the user to confirm his account again if he changes his email.

    Once, you updated the password of the concerned user, you need to un-confirm the user, and then re-send the confirmation email.

    To unconfirm the user :

    user = User.find(1)
    if user.confirmed?
      user.confirmed_at = nil
      user.save(:validate => false)
    end
    

    To resend the email confirmation :

    user = User.find(1)
    user.send_confirmation_instructions
    

    Hope this help !

提交回复
热议问题