Implement basic password reset mailer

This commit is contained in:
James Espinosa
2013-11-25 19:36:33 -06:00
parent 93d7c2bd44
commit 26e04deb9f
5 changed files with 30 additions and 4 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ class UsersController < ApplicationController
def forgot_password
@user = User.find_by_email(params[:email]) unless params[:email].nil?
if @user && password_reset_mailer_setup(@user)
flash[:success] = "Password reset email sent to #{params[:email]}"
redirect_to :login
@@ -67,7 +67,7 @@ class UsersController < ApplicationController
def password_reset_mailer_setup(user)
token = generate_token(user.id, user.email)
#reset_password_mailer(user.email, token)
UserMailer.forgot_password(user.email, token).deliver
end
def generate_token(id, email)
+6 -1
View File
@@ -1,3 +1,8 @@
class UserMailer < ActionMailer::Base
default from: "from@example.com"
default from: "noreply@railsgoat.dev"
def forgot_password(email, token)
@token = token
mail(to: "#{email}", subject: "Reset your RailsGoat password")
end
end
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Need help logging in?</h1>
<p>
To reset your RailsGoat password, simply click on the
following link and follow the instructions: <%= @token %>.<br/>
</p>
<p>Thanks, and have a great day!</p>
</body>
</html>
@@ -0,0 +1,7 @@
Need help logging in?
==========================================================
To reset your RailsGoat password, simply click on the
following link and follow the instructions: <%= @token %>.
Thanks, and have a great day!
+1 -1
View File
@@ -3,7 +3,7 @@ ActionMailer::Base.smtp_settings = {
:port => 2525,
:authentication => :plain,
:user_name => ENV['MAILTRAP_USERNAME'],
:password => ENV['MAILTRAP_PASSWORD'],
:password => ENV['MAILTRAP_PASSWORD']
}
ActionMailer::Base.delivery_method = :smtp