【发布时间】:2016-02-20 19:27:03
【问题描述】:
我有一个用户模型(由$ rails g devise User 创建),它被设置为使用可确认(在模型和迁移中)。
创建用户时,未设置确认令牌(并且未发送确认电子邮件)。
这里是app/models/user.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable
def password_required?
super if confirmed?
end
def password_match?
self.errors[:password] << "can't be blank" if password.blank?
self.errors[:password_confirmation] << "can't be blank" if password_confirmation.blank?
self.errors[:password_confirmation] << "does not match password" if password != password_confirmation
password == password_confirmation && !password.blank?
end
# new function to set the password without knowing the current
# password used in our confirmation controller.
def attempt_set_password(params)
p = {}
p[:password] = params[:password]
p[:password_confirmation] = params[:password_confirmation]
update_attributes(p)
end
# new function to return whether a password has been set
def has_no_password?
self.encrypted_password.blank?
end
# Devise::Models:unless_confirmed` method doesn't exist in Devise 2.0.0 anymore.
# Instead you should use `pending_any_confirmation`.
def only_if_unconfirmed
pending_any_confirmation {yield}
end
protected
def confirmation_required?
false
end
end
有什么想法吗?
【问题讨论】:
-
您能展示您的
user.rb内容吗?还有助于了解您正在使用哪个 ORM(Mongoid、ActiveRecord) -
我已经添加了
user.rb的内容。我正在使用 ActiveRecord。
标签: ruby-on-rails ruby devise devise-confirmable