简体   繁体   中英

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.

Note: Secret code and password are two different things in my application.

Devise has an internal module called Confirmable that does exactly this.

In order to use it, all you need to do is:

  • Make sure your devise model is :confirmable and :registerable

     class User # ... devise :confirmable, :registerable ... # ... end 
  • Run a migration that creates confirmation_token fields

     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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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