From 13fd8d03e4b56f76449c3ed87bec044d79de77e5 Mon Sep 17 00:00:00 2001 From: spen Date: Fri, 2 May 2014 13:54:49 +0800 Subject: [PATCH] fix reset password --- app/mailer/user_mailer.rb | 34 ++++++++++++++++++- .../confirmation_instructions.html.erb | 5 +++ .../reset_password_instructions.html.erb | 8 +++++ .../user_mailer/unlock_instructions.html.erb | 7 ++++ config/initializers/devise.rb | 2 +- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 app/views/user_mailer/confirmation_instructions.html.erb create mode 100644 app/views/user_mailer/reset_password_instructions.html.erb create mode 100644 app/views/user_mailer/unlock_instructions.html.erb diff --git a/app/mailer/user_mailer.rb b/app/mailer/user_mailer.rb index 8a5a6e6..eca096e 100644 --- a/app/mailer/user_mailer.rb +++ b/app/mailer/user_mailer.rb @@ -1,3 +1,35 @@ class UserMailer < Devise::Mailer - default :from => "noreply@rulingcom.com" + + # default :from => "noreply@rulingcom.com" + + @site = Site.first + + @smtp_settings = { + :address => @site['site_settings']['address'], + :port => @site['site_settings']['port'], + :domain => @site['site_settings']['domain'], + :authentication => @site['site_settings']['authentication'], + :enable_starttls_auto => @site['site_settings']['enable_starttls_auto'] + } + + if !@site['site_settings']['user_name'].blank? + @smtp_settings[:user_name] = @site['site_settings']['user_name'] + end + + if !@site['site_settings']['password'].blank? + @smtp_settings[:password] = @site['site_settings']['password'] + end + + if !@site['site_settings']['service_email'].blank? + @smtp_settings[:from] = @site['site_settings']['service_email'] + Devise.mailer_sender = @site['site_settings']['service_email'] + end + + if !@site['site_settings']['reply_email'].blank? + @smtp_settings[:reply_to] = @site['site_settings']['reply_email'] + end + + + ActionMailer::Base.smtp_settings = @smtp_settings + end \ No newline at end of file diff --git a/app/views/user_mailer/confirmation_instructions.html.erb b/app/views/user_mailer/confirmation_instructions.html.erb new file mode 100644 index 0000000..a6ea8ca --- /dev/null +++ b/app/views/user_mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @resource.email %>!

+ +

You can confirm your account through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

diff --git a/app/views/user_mailer/reset_password_instructions.html.erb b/app/views/user_mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..ae9e888 --- /dev/null +++ b/app/views/user_mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password, and you can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/user_mailer/unlock_instructions.html.erb b/app/views/user_mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..2263c21 --- /dev/null +++ b/app/views/user_mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive amount of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>

diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index cfc7857..6dae797 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -6,7 +6,7 @@ Devise.setup do |config| config.mailer_sender = "noreply@rulingcom.com" # Configure the class responsible to send e-mails. - config.mailer = "Devise::Mailer" + config.mailer = "UserMailer" # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and