Implement basic password reset mailer
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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!
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user