设计 |自动生成的用户密码未显示在发送的电子邮件中

Devise | autogenerated user password does not show up in email sent

我正在尝试设置一封电子邮件,其中推荐人将在有关推荐人的表格中填写一些信息。裁判将收到一封电子邮件以订阅我的服务,其中包含 2 条不同的消息,具体取决于他是否已经存在于数据库中(幽灵状态)。但是发送电子邮件时,不会自动生成密码。为什么?

电子邮件已发送:

You have been registered as a teacher on XX.
Please confirm your account

<a href="http://localhost:3000/en/users/confirmation?confirmation_token=6Ac-y5Ymv1GNAkb5whUK">Confirm my account</a>
and connect with these credentials log in:<br /> 
login: bb@ee.fr<br /> 
password: 

我的控制器:

def new_teacher_registered(teacher, user = nil)
@teacher = teacher
@user = user
@password = user.generate_password
mail(from: 'XX', to: teacher.email, bcc: "YY", subject: 'You have been registered on XYZ')
end

我的看法:

<% if @user.ghost? %>
You have been registered as a teacher on XXX.
Please confirm your account

<%= link_to "Confirm my account",
confirmation_url(@user, I18n.locale, :confirmation_token => @user.confirmation_token) %>

and connect with these credentials log in:<br /> 
login: <%= @user.email %> <br /> 
password: <%= @password %>

<%else%>
You have been registered on XX by <%= @teacher.studios.first.user.contact.location.name %>

我的用户控制器中有 generate_password 方法

class User < ActiveRecord::Base
.....
def generate_password
 unless self.encrypted_password
  @password = Devise.friendly_token.first(8)
   if self.update(password: password, password_confirmation: password)
    @password
    else
     false
   end
 end
end
......
end

与其向他们发送带有密码的电子邮件(这不是最佳做法),为什么不向他们发送 link 以便他们可以在您的安全站点上创建自己的密码?

下面的示例将创建一个重置 link 供他们单击并给他们一个临时密码,以便设计满意,然后发送一封带有 link(原始令牌)的电子邮件.

raw_token, hashed_token = Devise.token_generator.generate(User, :reset_password_token)
self.reset_password_token = hashed_token
self.reset_password_sent_at = Time.now.utc
self.password = Devise.friendly_token.first(8)
self.save
UserMailer.add_to_website(course, self, raw_token).deliver_later