简体   繁体   English

设计Rails中的ruby定制

[英]devise customization in ruby on rails

I am implementing devise for user registration but some customizations and it is below. 我正在实施针对用户注册的设计,但下面进行了一些自定义。

  • When user registers with username,email and password, an email will go to user 当用户使用用户名,电子邮件和密码注册时,一封电子邮件将发送给用户
  • In email user will get a secret code which is required to complete sign up process. 在电子邮件中,用户将获得完成注册过程所需的密码。
  • When user clicks "Go to App" button, It will redirect user to App and here user has to use that secret code to complete sign up process. 当用户单击“转到应用程序”按钮时,它将重定向用户到应用程序,此时用户必须使用该密码来完成注册过程。
  • Once user completes sign up process, there would be one to one relationship between user and that secret code. 用户完成注册过程后,用户与该密码之间将存在一对一的关系。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM