ruby-on-rails - 设计忘记密码不起作用

标签 ruby-on-rails ruby-on-rails-3 authentication devise

我在 rails 3 上使用 devise 进行身份验证。登录、注销、注册工作正常,但在忘记密码的情况下没有任何反应。当我点击忘记密码链接时,它会将我带到 http://localhost:3000/users/password/new 链接,然后我会收到一个询问我的电子邮件地址的表格和一个向我发送重置密码说明按钮,但是当我单击该按钮时,它会将我带到 http://localhost:3000/users/sign_in 但我没有收到有关重置密码的邮件。

在控制台上我可以看到以下内容:

Sent mail to nikitasalunkhe.3@gmail.com (968ms)
Date: Tue, 05 Jun 2012 13:14:22 +0530
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: nikitasalunkhe.3@gmail.com
Message-ID: <4fcdb8d6de776_dd624e71f0a78a7@user-G41MT-S2.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello nikitasalunkhe.3@gmail.com!</p>

<p>Someone has requested a link to change your password, and you can do this through the link below.</p>

<p><a href="http://localhost:3000/users/password/edit?reset_password_token=gUB8L9nWNikjVJpnhbDW">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

但是我的收件箱里没有邮件。

以下是我的 config/initializer/devise.rb 文件的代码:

Devise.setup do |config| 
config.mailer_sender = "nikitasalunkhe.3@gmail.com"  
config.mailer = "Devise::Mailer" 
require 'devise/orm/active_record' 
config.case_insensitive_keys = [ :email ] 
config.stretches = 10 
config.use_salt_as_remember_token = true 
config.reset_password_keys = [ :email ] 

这是 development.rb 文件代码:

Alumnicell::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_view.debug_rjs             = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin
    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end

我应该做哪些更改才能使其正常工作?

最佳答案

您是否安装了本地邮件守护程序?我最好的解决方案是像这样使用 gmail smtp(使用您的设置):

在 config/environments/development.rb 中:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'mondomaine.com',
  :user_name            => 'smtp@mondomaine.com',
  :password             => 'mypassword',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

并删除你的行:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

在生产模式下,您将有一个本地邮件服务器作为后缀。

关于ruby-on-rails - 设计忘记密码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10893552/

相关文章:

mongodb - 无法使用 --db 创建备份 mongodump。身份验证失败

ruby-on-rails - 我如何在 Rails 中测试 belongs_to 和 has_many?

ruby-on-rails - (Rails + Redmine) 根据用户角色在顶部菜单中显示选项卡

ruby-on-rails - Heroku值得吗?

javascript - rails 3.1 : The new way to use 'respond_to ... format.js' without the 'page' variable

mysql - 使用 Rails 3 的报价生成器应用

javascript - 面向公众的 REST 身份验证机制

ruby-on-rails - FactoryGirl 父类工厂随机选择其 STI 子类之一

ruby - 如何使用 Mongoid 删除特定数据库?

python - 模块 "mymodule"未定义 "MyBackend"身份验证后端