sending unlock account email if account is locked #261
-
is there a way to send an unlock account email if the account is locked? I tried this locked_out? do
send_unlock_account_email
end but I get an email with an empty key (key?=id_) RodauthMailer.unlock_account(
self.class.configuration_name,
account_id,
unlock_account_key_value, # I tried to replace it with get_unlock_account_key and generate_unlock_account_key
) .deliver_later the unlock email doesn't work, and I get 403 Forbidden. I started a discussion in Rodauth and was asked to move it here as I am using Rodauth-rails. here is what I tried from there: # The email I get from this works
after_account_lockout { send_unlock_account_email }
# I get an email but the key is not valid as it doesn't unlock the account and I get a 403
locked_out? do
locked = super()
if locked
@unlock_account_key_value = get_unlock_account_key
send_unlock_account_email
end
locked
end this is my RodauthMailer class RodauthMailer < ApplicationMailer
def unlock_account(name, account_id, key)
@email_link = email_link_key(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 email_link_key(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
end |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Could you try to comment out the mailer integration in your Rodauth configuration, and see if you get the same error? I want to narrow down whether the issue is with the mailer or vanilla Rodauth. |
Beta Was this translation helpful? Give feedback.
-
when commenting out the mailer integration the generated key works fine so the issue is with the mailer. is there something I am doing wrong in my mailer? I want to note that everything else works account invite, reset password... I updated the mailer to this def email_link_key(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").split("?key=").last
end as I am using a different URL in the frontend (the backend works as an API) |
Beta Was this translation helpful? Give feedback.
I wasn't able to reproduce. Here is a self-contained example that uses Rodauth directly, but imitates the mailer configuration. The output shows that the token in the email link generated by the email is identical to the one Rodauth generates naturally.
Example