我正在尝试设置一个电子邮件,其中推荐人将以关于裁判的形式填写一些信息。裁判将收到一封电子邮件,用两条不同的消息订阅我的服务,具体取决于他是否已经存在于数据库中(重影状态)。但是,当发送电子邮件时,不会自动生成密码。为什么?
发送电子邮件:
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
答案 0 :(得分:0)
为什么不向他们发送一个链接,让他们可以在您的安全网站上创建自己的密码,而不是向他们发送带密码的电子邮件(不是最佳做法)?
下面的示例将创建一个重置链接,供他们点击并为他们提供一个临时密码,以便设计很满意,然后发送包含链接的电子邮件(原始令牌)。
f = Frame(None,1,"Test",None)