忘记密码在开发中工作,而不是生产。 Rails 4从头开始验证

时间:2014-04-14 01:12:56

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

有没有办法让我忘记密码的工作而不必使用宝石?我已经从头开始设置用户和所有内容。当我在我的制作应用程序中时,我输入所有内容,好像忘记了密码,它告诉我我的密码已经发送,但是没有显示出来。

Heroku Logs:

 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$ 

production.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)

development.rb

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

1 个答案:

答案 0 :(得分:0)

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

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
  }