oauth2.0 为可确认设备生成自定义令牌

rbl8hiat  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(102)

我正在使用devise:confirmable,并且希望使用自定义令牌,因为我需要在确认令牌本身中附加一些数据。如何配置它?
用户型号:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :password_archivable

字符串

mpbci0fu

mpbci0fu1#

在创建回调之前设计用于生成令牌。

before_create :generate_confirmation_token, if: :confirmation_required?

字符串
您可以在User模型中覆盖devise中的generate_confirmation_token方法。
波纹管是方法的默认行为。

# Generates a new random token for confirmation, and stores
    # the time this token is being generated in confirmation_sent_at
    def generate_confirmation_token
      if self.confirmation_token && !confirmation_period_expired?
        @raw_confirmation_token = self.confirmation_token
      else
        self.confirmation_token = @raw_confirmation_token = Devise.friendly_token
        self.confirmation_sent_at = Time.now.utc
      end
    end


查看此模块了解更多信息。

相关问题