(Re?)enable email to user after account approval

Existing function account_allow() does not seem to be used a whole
lot, and certainly not when approving a registration request.

Created new function send_reg_confirmation_email_from_register
(going for longest-function-name-in-Hubzilla) which attempts to
send such a confirmation email, and also a new email template.

Plugged this into the create_account_from_register function.

Open question: Should the sending of this email be among the success
criteria for the create_account_from_register function?
This commit is contained in:
ltning
2026-01-28 02:21:18 +00:00
parent 794b456b8a
commit bd63af69b2
2 changed files with 69 additions and 3 deletions

View File

@@ -264,9 +264,10 @@ function create_account_from_register($arr) {
$result['account']['parent'] = $result['account']['account_id'];
}
$result['success'] = true;
call_hooks('register_account',$result);
if ( send_reg_confirmation_email_from_register($arr['reg_id']) ) {
$result['success'] = true;
call_hooks('register_account',$result);
}
return $result;
}
@@ -316,6 +317,56 @@ function verify_email_address(string $email): bool {
return $res;
}
/**
* Send email to user confirming approved registration.
*
* @param int $reg_id The reg_id of the user (from register table)
*
* @return bool `true` if the email was sucessfully sent, otherwise `false`.
*/
function send_reg_confirmation_email_from_register(int $reg_id): bool {
$register = q("SELECT reg_email, reg_lang FROM register WHERE reg_id = '%s' ",
intval($reg_id)
);
if (empty($register)) {
logger('send_reg_confirmation_email_from_register: could not find email address for for reg_id ' . $reg_id);
return $result;
} else {
logger('send_reg_confirmation_email_from_register: sending confirmation email to ' . $register[0]['reg_email']);
}
if(strlen($register['reg_lang'])) {
push_lang($register['reg_lang']);
} else {
push_lang('en');
}
$email_msg = replace_macros(get_intltext_template('register_approved_eml.tpl'), array(
'$sitename' => Config::Get('system','sitename'),
'$siteurl' => z_root(),
'$email' => $register[0]['reg_email'],
));
$res = z_mail(
[
'toEmail' => $register[0]['reg_email'],
'messageSubject' => sprintf( t('Registration approved at %s'), Config::Get('system','sitename')),
'textVersion' => $email_msg,
]
);
pop_lang();
if ($res) {
return true;
} else {
logger('send_reg_confirmation_email_from_register: failed to send confirmation email to ' . $register[0]['reg_email']);
return false;
}
}
function send_reg_approval_email($arr) {