0

我正在使用 Mailer 和 MailCatcher。

当管理员在系统中注册客户时,客户应该会收到一封电子邮件,其中包含恢复密码的链接

4

1 回答 1

1

你在重新发明轮子。Devise 已经有一个Invitable 模块,可以满足您的需求。

按照安装说明操作后,您只需添加一个链接new_user_invitation_path,管理员可以在其中邀请其他用户。如果您想锁定邀请以便只有管理员可以邀请用户,只需自定义控制器:

class MyInvitationsController < Devise::InvitationsController
  before_action :authorize_admin!, only: [:new, :create]

  def authorize_admin!
    # if you are using Pundit
    authorize resource_class, :invite?

    # or if you're reinventing the authorization wheel
    redirect_to '/somewhere'
  end
end

如果你真的想重新发明轮子,那就做对了。Devise 不会重置密码Devise::RegistrationsController——你也不应该这样做。

密码重置在Devise::PasswordsController

                               Prefix Verb   URI Pattern                                                                              Controller#Action                                                               
                    new_user_password GET    /users/password/new(.:format)                                                            devise/passwords#new
                   edit_user_password GET    /users/password/edit(.:format)                                                           devise/passwords#edit
                        user_password PATCH  /users/password(.:format)                                                                devise/passwords#update
                                      PUT    /users/password(.:format)                                                                devise/passwords#update
                                      POST   /users/password(.:format)                                                                devise/passwords#create

密码重置电子邮件中的链接是/users/password/edit。您可以在电子邮件视图中看到。

edit_password_url(@resource, reset_password_token: @token)
于 2020-03-19T18:39:35.193 回答