仅使用设计和电子邮件注册电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仅使用设计和电子邮件注册电子邮件相关的知识,希望对你有一定的参考价值。

我正在尝试实现一个类似于Medium的用户身份验证系统,用户只需在注册时输入他们的电子邮件地址,并在邮件中获得确认链接,点击该链接后,他们会被重定向回网站然后被要求填写密码和其他详细信息。我正在使用Devise并找到了2篇文章,但没有一篇正在发挥作用。 Stackoverflow发布了类似的问题,但没有很好的解决方案。 https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up https://github.com/plataformatec/devise/wiki/How-To:-Override-confirmations-so-users-can-pick-their-own-passwords-as-part-of-confirmation-activation 这些文章有问题吗?

答案

为了在没有密码的情况下注册用户,我们要做的第一件事就是确保我们可以访问这样的设计视图

rails generate devise:views

我目前最关心的观点是app / views / devise / registrations / new.html.erb *,但你一定要仔细查看它们,确保它们符合你的应用*

你想找到并删除它。如果一切都是默认的话,这应该是11到22行

  <div class="field">
    <%= f.label :password %>
    <% if @minimum_password_length %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %><br />
    <%= f.password_field :password, autocomplete: "off" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
  </div>

现在表单将提交给控制器,但没有密码。这将触发错误密码不能为空

所以我现在所做的就是给它一个像这样的密码

1)将设备qazxsw poi复制到您的应用程序中

registrations_controller.rb

我希望这有助于你找到我的代码#app/controllers/devise/registrations_controller.rb class Devise::RegistrationsController < DeviseController ... def create build_resource(sign_up_params) resource.password = SecureRandom.hex(10) # sets the password resource.save yield resource if block_given? if resource.persisted? resource.send_reset_password_instructions # send them instructions how to reset password if resource.active_for_authentication? set_flash_message! :notice, :signed_up sign_up(resource_name, resource) respond_with resource, location: after_sign_up_path_for(resource) else set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}" expire_data_after_sign_in! respond_with resource, location: after_inactive_sign_up_path_for(resource) end else clean_up_passwords resource set_minimum_password_length respond_with resource end end ... end

以上是关于仅使用设计和电子邮件注册电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

我应该如何使用 Outlook 发送代码片段?

用户池允许两个用户使用相同的电子邮件,尽管配置

如何设计布局以在注册期间获取图像作为输入?

这些角度电子邮件指令代码片段如何连接

是否可以仅对部分用户启用电子邮件验证?

Swift - 如何将 SwiftValidator 集成到我的项目中