我需要修改 Devise 如何确定用户帐户是否被确认。
我设置了两步注册,用户输入电子邮件,然后在单击电子邮件中的链接后设置密码。
这工作正常,但我有一个场景,登录用户可以创建一个用户并向他们发送一个链接以确认他们的帐户。这是通过自定义邮件手动发送的(这包括请求其帐户的用户的电子邮件地址以及确认令牌),这意味着如果他们的帐户是通过另一个用户创建的,则用户将收到 2 封电子邮件,标准设计确认指令和自定义邮件“邀请”。
在此之后我设置了skip_confirmation!在保存之前,这意味着只有我发送的电子邮件才能发送给用户,但是由于这设置了 confimed_at 字段,因此用户无法设置密码,因为它会生成一个错误,说明帐户已确认。
如何更改已确认?方法来检查密码不为空?
这是我的 2 步注册过程的覆盖确认控制器:
class ConfirmationsController < Devise::ConfirmationsController
  def show
    self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token])
    super if resource.confirmed? 
  end
  def confirm
    self.resource = resource_class.find_by_confirmation_token(params[resource_name][:confirmation_token])
    if resource.update_attributes(params[resource_name].except(:confirmation_token)) && resource.password_match?
      self.resource = resource_class.confirm_by_token(params[resource_name][:confirmation_token])
      set_flash_message :notice, :confirmed
      sign_in_and_redirect(resource_name, resource)
    else
      render :action => "show"
    end
  end
end
这是自定义邮件:
class MyMailer < Devise::Mailer   
  helper :application # gives access to all helpers defined within `application_helper`.
   def invite(sender, recipient)
        @sender = sender
        @recipient = recipient
        mail( :to => recipient.email,
              :subject => "Account created by #{sender.email}",
              :from => "noreply@noreply.com"
            )
  end
end
登录用户创建新用户的控制器中的代码(显示适用的部分)
.
.
.
            newContact = User.create(:email => params[:contact_email])
            newContact.skip_confirmation!
            if newContact.save
                 MyMailer.invite(current_user, newContact).deliver
                 .
                 .
                 .
             end
.
.
.