设计确认邮件再次发送

时间:2017-03-15 05:26:44

标签: mysql ruby-on-rails devise

即使在确认电子邮件后,确认邮件仍会重新发送。即使confirm_at属性显示已确认的时间,设备用户属性unconfirmed_email也不会更改为NULL值。

我正在使用rails 5并设计gem版本4.2

这是确认控制器

 def create
  begin
  email = params[resource_name][:email]
  rescue
  email = ""
end
user = User.find_by_email(email)
if poster and ["blocked", "deactivated"].include?(user.status)
  poster.errors.add(:email, "has been #{user.status}")
  self.resource = user
  respond_with(self.resource)
  return false
end
super
end

这是注册控制器中的功能验证电子邮件。

 def verify_email
   @user = User.find_by_confirmation_token(params[:token])
if @user
  if @user.confirmed?
    flash[:error] = "Your Account is already verified please try to login"
    redirect_to new_poster_session_path
  else
    @user.confirmed_at = Time.now
    #@user.confirmation_token = nil
    @user.save
    sign_in @user
    token = Devise.friendly_token
    current_user.update_attribute :current_sign_in_token, token
    session[:sign_in_token] = token
    redirect_to root_path
  end
else
  @user = User.new
  @company = Company.new
  @city = City.new
  #      @region = Location::Region.new
  flash.now[:error] =       I18n.t("applicant.confirmations.invalid_or_expired_token")
  flash[:regenerate_token] = I18n.t("applicant.confirmations.invalid_or_expired_token_regenerate", :path => new_user_confirmation_path)
  respond_with_navigational(resource) { render :new }
end

上述代码适用于其他模型,因为没有显示错误。我不知道该怎么做。请帮忙!

1 个答案:

答案 0 :(得分:1)

如果这是实际代码,则表示您有错误。

更改此行

user = user.find_by_email(email)

到这一行

user = User.find_by_email(email) # use the class!