[英]devise customization in ruby on rails
I am implementing devise for user registration but some customizations and it is below. 我正在实施针对用户注册的设计,但下面进行了一些自定义。
I searched a lot on internet but could not find answer. 我在互联网上搜索了很多,但找不到答案。
Problem: I do not know how to create secret code in rails and then send it to user thourgh email and then match it with code that user got. 问题:我不知道如何在Rails中创建秘密代码,然后将其发送给用户thourgh电子邮件,然后将其与用户获得的代码匹配。
Note: Secret code and password are two different things in my application. 注意:密码和密码是我的应用程序中的两件事。
Devise has an internal module called Confirmable
that does exactly this. Devise有一个称为
Confirmable
的内部模块,可以完成此操作。
In order to use it, all you need to do is: 为了使用它,您需要做的是:
Make sure your devise model is :confirmable
and :registerable
确保您的设计模型是
:confirmable
和:registerable
class User # ... devise :confirmable, :registerable ... # ... end
Run a migration that creates confirmation_token fields 运行迁移以创建Confirmation_token字段
class AddConfirmableToUsers < ActiveRecord::Migration def self.up change_table(:users) do |t| t.confirmable end add_index :users, :confirmation_token, :unique => true end def self.down remove_column :users, :confirmable end end
If you already have users, and don't want them to follow this confirmation process, than you need to make them confirmed. 如果您已经有用户,并且不希望他们遵循此确认过程,则需要进行确认。 You can do that doing
你可以那样做
User.update_all ["confirmed_at = ?", Time.now]
on the console. 在控制台上。
More references: Confirable Module , Adding confirmable to Users in Devise 更多参考: Confirable Module , 在Devise中向用户添加确认
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.