您正在重新发明轮子。 Devise 已经有一个 Invitable module 可以满足您的需求。
按照安装说明操作后,您只需添加一个指向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。您可以在email view 中看到。
edit_password_url(@resource, reset_password_token: @token)