v1.4.2
-
The generated Action Mailer configuration has received several improvements:
- configuration name is now passed into the mailer, making it work for secondary configurations
- finding the account was extracted into a method, to make it easier to change if needed for different Rodauth configurations
- the old/new email address are not passed into mailer arguments anymore for verifying login change, making it more GDPR-friendly
# app/misc/rodauth_main.rb class RodautMain < Rodauth::Rails::Auth configure do # ... create_reset_password_email do RodauthMailer.reset_password(*self.class.configuration_name, account_id, reset_password_key_value) end create_verify_account_email do RodauthMailer.verify_account(*self.class.configuration_name, account_id, verify_account_key_value) end create_verify_login_change_email do |_login| RodauthMailer.verify_login_change(*self.class.configuration_name, account_id, verify_login_change_key_value) end create_password_changed_email do RodauthMailer.password_changed(*self.class.configuration_name, account_id) end # create_email_auth_email do # RodauthMailer.email_auth(*self.class.configuration_name, account_id, email_auth_key_value) # end # create_unlock_account_email do # RodauthMailer.unlock_account(*self.class.configuration_name, account_id, unlock_account_key_value) # end # ... end end
# app/mailers/rodauth_mailer.rb class RodauthMailer < ApplicationMailer def verify_account(name = nil, account_id, key) @email_link = email_link(name, :verify_account, account_id, key) @account = find_account(name, account_id) mail to: @account.email, subject: rodauth(name).verify_account_email_subject end def reset_password(name = nil, account_id, key) @email_link = email_link(name, :reset_password, account_id, key) @account = find_account(name, account_id) mail to: @account.email, subject: rodauth(name).reset_password_email_subject end def verify_login_change(name = nil, account_id, key) @email_link = email_link(name, :verify_login_change, account_id, key) @account = find_account(name, account_id) @new_email = @account.login_change_key.login mail to: @new_email, subject: rodauth(name).verify_login_change_email_subject end def password_changed(name = nil, account_id) @account = find_account(name, account_id) mail to: @account.email, subject: rodauth(name).password_changed_email_subject end # def email_auth(name = nil, account_id, key) # @email_link = email_link(name, :email_auth, account_id, key) # @account = find_account(name, account_id) # mail to: @account.email, subject: rodauth(name).email_auth_email_subject # end # def unlock_account(name = nil, account_id, key) # @email_link = email_link(name, :unlock_account, account_id, key) # @account = find_account(name, account_id) # mail to: @account.email, subject: rodauth(name).unlock_account_email_subject # end private def find_account(_name, account_id) Account.find(account_id) end def email_link(name, action, account_id, key) instance = rodauth(name) instance.instance_variable_set(:@account, { id: account_id }) instance.instance_variable_set(:"@#{action}_key_value", key) instance.public_send(:"#{action}_email_link") end def rodauth(name) RodauthApp.rodauth(name).allocate end end
<%# app/views/rodauth_mailer/verify_login_change.text.erb %> Someone with an account has requested their login be changed to this email address: Old email: <%= @account.email %> New email: <%= @new_email %> If you did not request this login change, please ignore this message. If you requested this login change, please go to <%= @email_link %> to verify the login change.
-
Now that rodauth-model added support for Sequel models, the generated Sequel account model includes the model mixin automatically (just like the Active Record account model).
class Account < Sequel::Model include Rodauth::Rails.model # <== now supported plugin :enum enum :status, unverified: 1, verified: 2, closed: 3 end