diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aa6dde1..9bf5160 100755 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index f3d8202..1c61b83 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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 diff --git a/app/views/user_mailer/forgot_password.html.erb b/app/views/user_mailer/forgot_password.html.erb index e69de29..a9f5913 100644 --- a/app/views/user_mailer/forgot_password.html.erb +++ b/app/views/user_mailer/forgot_password.html.erb @@ -0,0 +1,14 @@ + + + + + + +

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!

+ + \ No newline at end of file diff --git a/app/views/user_mailer/forgot_password.text.erb b/app/views/user_mailer/forgot_password.text.erb index e69de29..cdc672e 100644 --- a/app/views/user_mailer/forgot_password.text.erb +++ b/app/views/user_mailer/forgot_password.text.erb @@ -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! \ No newline at end of file diff --git a/config/initializers/smtp_settings.rb b/config/initializers/smtp_settings.rb index 9fd2765..ecb0901 100644 --- a/config/initializers/smtp_settings.rb +++ b/config/initializers/smtp_settings.rb @@ -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 \ No newline at end of file