From 79770a899467464c114b2a49fcc15d0ebc98f5be Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Wed, 1 Feb 2023 16:33:02 +0100 Subject: [PATCH 1/3] Add otp_email_override support UI is still to be implemented --- interface/web/login/otp.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/interface/web/login/otp.php b/interface/web/login/otp.php index 8b80691da6..c8630b0817 100644 --- a/interface/web/login/otp.php +++ b/interface/web/login/otp.php @@ -157,13 +157,21 @@ if($_SESSION['otp']['type'] == 'email') { $app->ispcmail->setOptions($mail_config); } - $clientuser = $app->db->queryOneRecord('SELECT email FROM sys_user u LEFT JOIN client c ON (u.client_id=c.client_id) WHERE u.userid = ?', $_SESSION['s_pending']['user']['userid']); - if (!empty($clientuser['email'])) { - $email_to = $clientuser['email']; + $sys_user = $app->db->queryOneRecord('SELECT otp_data FROM sys_user WHERE userid = ?', $_SESSION['s_pending']['user']['userid']); + $data = json_decode($sys_user['otp_data'], TRUE); + + if (!empty($data['otp_email_override'] )) { + $email_to = $data['otp_email_override']; } else { - // Admin users are not related to a client, thus use the globally configured email address. - $email_to = $mail_config['admin_mail']; + $clientuser = $app->db->queryOneRecord('SELECT email FROM sys_user u LEFT JOIN client c ON (u.client_id=c.client_id) WHERE u.userid = ?', $_SESSION['s_pending']['user']['userid']); + if (!empty($clientuser['email'])) { + $email_to = $clientuser['email']; + } + else { + // Admin users are not related to a client, thus use the globally configured email address. + $email_to = $mail_config['admin_mail']; + } } $app->ispcmail->setSender($mail_config['admin_mail'], $mail_config['admin_name']); -- GitLab From 7cb697a8f8bf59542ee40f96e3a50730a9ae2735 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Thu, 19 May 2022 13:36:11 +0200 Subject: [PATCH 2/3] Fix indend and add comment --- interface/web/login/otp.php | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/web/login/otp.php b/interface/web/login/otp.php index c8630b0817..86a941add9 100644 --- a/interface/web/login/otp.php +++ b/interface/web/login/otp.php @@ -161,6 +161,7 @@ if($_SESSION['otp']['type'] == 'email') { $data = json_decode($sys_user['otp_data'], TRUE); if (!empty($data['otp_email_override'] )) { + // Handle otp_email_override. $email_to = $data['otp_email_override']; } else { -- GitLab From 3ddebfe99470c34bab240aeb42fe9dc42772c7ad Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Wed, 1 Feb 2023 16:56:05 +0100 Subject: [PATCH 3/3] Extra error when No mail address available to sent an OTP code to --- interface/web/login/otp.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/web/login/otp.php b/interface/web/login/otp.php index 86a941add9..a0a4c0c6eb 100644 --- a/interface/web/login/otp.php +++ b/interface/web/login/otp.php @@ -169,10 +169,13 @@ if($_SESSION['otp']['type'] == 'email') { if (!empty($clientuser['email'])) { $email_to = $clientuser['email']; } - else { + elseif(!empty($mail_config['admin_mail'])) { // Admin users are not related to a client, thus use the globally configured email address. $email_to = $mail_config['admin_mail']; } + else { + $app->error('No mail address available to sent an OTP code to.', 'index.php'); + } } $app->ispcmail->setSender($mail_config['admin_mail'], $mail_config['admin_name']); -- GitLab