【发布时间】:2018-09-09 01:34:53
【问题描述】:
自从我升级到 Rails 5 后,密码重置电子邮件不再有效。正如对所有相关问题的回复所表明的那样,我的 gmail 设置为接受来自不太安全的应用程序的登录,验证码已关闭
当我在 localhost 上单击向我发送重置密码指令时(在生产中也不起作用,但我先在本地调试),错误消息是
Net::SMTPAuthenticationError in Users::PasswordsController#create 535-5.7.8 Username and Password not accepted.
Extracted source (around line #19):
17 puts resource_class
18 puts resource_params
19 self.resource = resource_class.send_reset_password_instructions(resource_params)
路线:
devise_for :users, :skip => [:sessions, :passwords], controllers: {registrations: "users/registrations", passwords: "users/passwords"} as :user do
get 'login' => 'devise/sessions#new', :as => :new_user_session
post 'login' => 'devise/sessions#create', :as => :user_session
delete 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
get "signup", :to => 'devise/registrations#new', :as => :new_user_signup
post "signup", :to => 'devise/registrations#create', :as => :user_signup
get "password", :to => 'devise/passwords#new', :as => :reset_password
get "password", :to => 'devise/passwords#edit', :as => :edit_user_password
match '/password' => 'users/passwords#create', as: :user_password, via: [:post]
match '/password' => 'devise/passwords#update', via: [:put, :patch]
end
设计/密码/新:
<%= form_for(resource, :as => resource_name, :url => user_password_path, :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true, :size => 40 %></div>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
<%= render "devise/shared/links" %>
开发.rb:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "me@gmail.com",
:password => "GMAIL_PWD",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
config.action_mailer.default_url_options = {
:host => 'localhost:3000', :protocol => 'http'
}
user.rb:
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable
控制器/用户/passwords_controller.rb:
class Users::PasswordsController < Devise::PasswordsController
include ApplicationHelper
prepend_before_action :require_no_authentication
def create
puts resource_class
puts resource_params
self.resource = resource_class.send_reset_password_instructions(resource_params)
yield resource if block_given?
if successfully_sent?(resource)
respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
else
respond_with(resource)
end
end
end
application_helper.rb:
module ApplicationHelper
def resource_name
:user
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
这不是 100 个其他类似问题的重复,其中 gmail 不允许从应用程序登录。我曾经遇到过这个问题,但总是会收到来自 gmail 的通知,说外国应用程序正在访问 gmail 帐户。在这种情况下,我的应用似乎还不足以请求 Gmail 的访问权限。
我已经清除了验证码,启用了 POP/IMAP,在 gmail 中打开了不太安全的应用程序。它在开发和生产中都不起作用。正如我所提到的,我认为它甚至不会访问 gmail。我认为这是 Rails 5 和 Devise 4 之间的兼容性问题。当我升级时,注册和密码停止工作。我能够找到一个有效的示例 registrations_controller,但没有找到有关如何处理 passwords_controller 的任何文档。
【问题讨论】:
-
不,这不是其他 100 个具有相同答案的问题的重复。我已经清除了验证码,启用了 POP/IMAP。它在开发和生产中都不起作用。正如我所提到的,我认为它甚至不会访问 passwords_controller。我认为这是 Rails 5 和 Devise 4 之间的兼容性问题。当我升级时,注册和密码停止工作。我能够找到一个有效的示例 registrations_controller,但没有找到有关如何处理 passwords_controller 的任何文档。
标签: ruby-on-rails devise passwords gmail ruby-on-rails-5