Class: UserMailer
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- UserMailer
- Defined in:
- backend/app/lib/user_mailer.rb
Defined Under Namespace
Classes: MailError
Instance Method Summary collapse
-
#headers ⇒ Object
-
#initialize ⇒ UserMailer
constructor
A new instance of UserMailer.
-
#send_reset_token(username, token) ⇒ Object
-
#update_view_path ⇒ Object
It’s unfortunate that this is necessary, but being that the backend is not a Rails app, ActionMailer will need help finding view templates.
Constructor Details
#initialize ⇒ UserMailer
Returns a new instance of UserMailer.
6 7 8 9 |
# File 'backend/app/lib/user_mailer.rb', line 6 def initialize super update_view_path end |
Instance Method Details
#headers ⇒ Object
14 15 16 17 |
# File 'backend/app/lib/user_mailer.rb', line 14 def headers delivery_method = ActionMailer::Base.delivery_method { delivery_method: delivery_method, to: @user.email, from: AppConfig[:global_email_from_address], subject: I18n.t('user.reset_password') } end |
#send_reset_token(username, token) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'backend/app/lib/user_mailer.rb', line 32 def send_reset_token(username, token) @user = User.first(username: username) @magic_link = AppConfig[:frontend_proxy_url] + "/users/#{username}/#{token}" begin msg = mail headers do |format| format.html { render 'send_reset_token' } end msg.deliver rescue Exception => e Log.error("Mailing password reset link failed: #{e.inspect}") raise MailError.new end end |
#update_view_path ⇒ Object
It’s unfortunate that this is necessary, but being that the backend is not a Rails app, ActionMailer will need help finding view templates.
21 22 23 24 25 26 27 28 29 30 |
# File 'backend/app/lib/user_mailer.rb', line 21 def update_view_path view_path = File.join(ASUtils.find_base_directory, 'backend', 'app', 'views') # above method does not work when running in Jetty unless File.exist?(view_path) view_path = File.join('app', 'views') end self.append_view_path(view_path) end |