【问题标题】:Forgot password works in development, not production. Rails 4 auth from scratch忘记密码适用于开发,而不是生产。 Rails 4 从头开始​​认证
【发布时间】:2014-05-27 20:15:03
【问题描述】:

有没有办法让我忘记密码而无需使用 Gem?我已经从头开始设置了用户和我喜欢的一切。当我在我的生产应用程序中时,我输入所有内容,就好像我忘记了密码一样,它告诉我我的密码已发送,但没有显示。

Heroku 日志:

 2014-04-14T01:03:32.595045+00:00 heroku[router]: at=info method=GET path=/password_resets/new host=boiling-garden-2168.herokuapp.com request_id=2b759363-24f6- 4053-87f4-81c62b98374c fwd="162.232.157.38" dyno=web.1 connect=2ms service=21ms status=304  bytes=807
2014-04-14T01:03:32.578274+00:00 app[web.1]: Started GET "/password_resets/new" for  162.232.157.38 at 2014-04-14 01:03:32 +0000
2014-04-14T01:03:32.578213+00:00 app[web.1]: Started GET "/password_resets/new" for  162.232.157.38 at 2014-04-14 01:03:32 +0000
2014-04-14T01:03:30.919303+00:00 heroku[router]: at=info method=GET path=/login  host=boiling-garden-2168.herokuapp.com request_id=6b2c98d1-a2cc-4294-bdd3-a66d34f54572  fwd="162.232.157.38" dyno=web.1 connect=4ms service=29ms status=304 bytes=847
2014-04-14T01:03:42.538025+00:00 heroku[router]: at=info method=POST  path=/password_resets host=boiling-garden-2168.herokuapp.com request_id=db763e58-ae0e-46e9-bf86-b930932c94c3 fwd="162.232.157.38" dyno=web.1 connect=2ms service=74ms status=302 bytes=1167
2014-04-14T01:03:42.640229+00:00 heroku[router]: at=info method=GET path=/  host=boiling-garden-2168.herokuapp.com request_id=8579ce48-075a-48c6-976e-2a5a6b9460c9  fwd="162.232.157.38" dyno=web.1 connect=3ms service=17ms status=200 bytes=5316
2014-04-14T01:03:42.520887+00:00 app[web.1]: Started POST "/password_resets" for  162.232.157.38 at 2014-04-14 01:03:42 +0000
2014-04-14T01:03:42.520899+00:00 app[web.1]: Started POST "/password_resets" for  162.232.157.38 at 2014-04-14 01:03:42 +0000
2014-04-14T01:03:42.627901+00:00 app[web.1]: Started GET "/" for 162.232.157.38 at  2014-04-14 01:03:42 +0000
2014-04-14T01:03:42.627964+00:00 app[web.1]: Started GET "/" for 162.232.157.38 at 2014-04-14 01:03:42 +0000
johns-mbp:Jetpack johncurry$ 

生产.rb:

config.action_mailer.default_url_options = { :host => "http://boiling-garden-2168.herokuapp.com/" }

  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.perform_deliveries = true
  ActionMailer::Base.raise_delivery_errors = true
  ActionMailer::Base.smtp_settings = 
  {

   :address            => 'smtp.gmail.com',
   :port               => 587,
   :domain             => 'gmail.com', #you can also use google.com
   :authentication     => :plain,
   :user_name          => 'myemail@gmail.com',
   :password           => 'Gmailpasswordhere'
  }

但是,当我使用 Localhost 时,它工作正常。

开发日志:

Started GET "/password_resets/new" for 127.0.0.1 at 2014-04-13 18:50:19 -0600
Processing by PasswordResetsController#new as HTML
      Rendered password_resets/new.html.erb within layouts/application (1.2ms)

          [1m[35mCategory Load (0.1ms)[0m  SELECT "categories".* FROM "categories"
          Rendered layouts/_navigation.html.erb (1.2ms)
          Rendered layouts/_messages.html.erb (0.1ms)
        Completed 200 OK in 16ms (Views: 14.6ms | ActiveRecord: 0.1ms)


Started POST "/password_resets" for 127.0.0.1 at 2014-04-13 18:50:27 -0600
Processing by PasswordResetsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"5Sy0bTXcSU8ndvQUj21dKEP1h7gVtfXtiefqrrydydA=", "email"=>"john.steven.curry@gmail.com", "commit"=>"Reset Password"}
  [1m[36mUser Load (0.2ms)[0m  [1mSELECT "users".* FROM "users" WHERE "users"."email" = 'john.steven.curry@gmail.com' LIMIT 1[0m
  [1m[35mUser Exists (0.2ms)[0m  SELECT 1 AS one FROM "users" WHERE "users"."password_reset_token" = '7ImtuiJmf7G_LksyoC8Ftg' LIMIT 1
  [1m[36m (0.1ms)[0m  [1mbegin transaction[0m
  [1m[35mUser Exists (0.2ms)[0m  SELECT 1 AS one FROM "users" WHERE ("users"."username" = 'Curry' AND "users"."id" != 1) LIMIT 1
  [1m[36mUser Exists (0.1ms)[0m  [1mSELECT 1 AS one FROM "users" WHERE ("users"."email" = 'john.steven.curry@gmail.com' AND "users"."id" != 1) LIMIT 1[0m
  [1m[35mSQL (19.7ms)[0m  UPDATE "users" SET "password_reset_token" = ?, "password_reset_sent_at" = ?, "updated_at" = ? WHERE "users"."id" = 1   [["password_reset_token", "7ImtuiJmf7G_LksyoC8Ftg"], ["password_reset_sent_at", Mon, 14 Apr  2014 00:50:27 UTC +00:00], ["updated_at", Mon, 14 Apr 2014 00:50:27 UTC +00:00]]
  [1m[36m (1.4ms)[0m  [1mcommit transaction[0m
  Rendered user_mailer/password_reset.text.erb (0.7ms)

Sent mail to john.steven.curry@gmail.com (11.4ms)
Date: Sun, 13 Apr 2014 18:50:27 -0600
From: john.steven.curry@gmail.com
To: john.steven.curry@gmail.com
Message-ID: <534b30d3ec249_2bda3ff2e297e6a845448@johns-mbp.mail>
Subject: Password Reset
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

To reset your password, click the URL below.

http://localhost:3000/password_resets/7ImtuiJmf7G_LksyoC8Ftg/edit

If you did not request your password to be reset, just ignore this email and your password will continue to stay the same. Have a great day!
Redirected to http://localhost:3000/
Completed 302 Found in 821ms (ActiveRecord: 21.8ms)

开发.rb

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

【问题讨论】:

    标签: ruby-on-rails authentication heroku forgot-password


    【解决方案1】:

    您必须在您的 production.rb 文件中使用完整的 url。

    config.action_mailer.default_url_options = { :host => "boiling-garden-2168.herokuapp.com" }
    

    尝试将 SendGrid 用作事务性邮件程序。这是一个 Heroku 插件。

    heroku addons:add sendgrid
    

    然后,检查以确保已将密钥添加到 heroku 配置中。

    heroku config
    

    然后将您的 config/environment.rb 代码更改为以下内容:

    # Load the rails application
    require File.expand_path('../application', __FILE__)
    
    # Initialize the rails application
    MyApp::Application.initialize!
    
      ActionMailer::Base.smtp_settings = {
       :address        => 'smtp.sendgrid.net',
       :port           => '587',
       :authentication => :plain,
       :user_name      => ENV['SENDGRID_USERNAME'],
       :password       => ENV['SENDGRID_PASSWORD'],
       :domain         => 'heroku.com',
       :enable_starttls_auto => true
      }
    

    【讨论】:

    • 它似乎仍然无法正常工作。我已经按照您的建议对其进行了编辑,但没有任何改变。在我的日志文件中似乎什么都没有发生。我想知道它是否正在处理发送电子邮件的请求。看看我原来的问题我已经改变了我的production.rb文件
    • 您有交易邮件插件设置吗?您需要在 heroku 中设置 SendGrid 或邮件系统。
    • 我不知道。 SendGrid 是否适用于 heroku?如果不是,您对 Heroku 中的邮件程序有什么建议?我正在尝试不使用需要我更改所有用户注册和登录设置等的东西。因为我已经拥有了我喜欢的东西..
    • 谢谢,我正在试一试,但我的帐户仍在验证中,所以我还不能发送任何电子邮件。设置好了,明天试试。谢谢。
    • 不,它没有用。这非常令人沮丧。我稍后会回到它,当有一个 rails cast 视频和一家为简化它而获得报酬的公司时,它不应该是这么愚蠢的困难。我在那里有发送网格,什么都没有发生。日志甚至看起来根本没有发送任何电子邮件。它不仅失败了,就像 heroku 甚至没有尝试一样......
    猜你喜欢
    • 2013-11-26
    • 2012-03-27
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多