Add API for sending alert emails

V2_Rewrite
Skylar Ittner 7 years ago
parent 865d47121c
commit 2db9187968

@ -264,6 +264,21 @@ switch ($VARS['action']) {
}
$user_key_valid = $database->has('mobile_codes', ['[>]accounts' => ['uid' => 'uid']], ["AND" => ['mobile_codes.code' => $VARS['code'], 'accounts.username' => $VARS['username']]]);
exit(json_encode(["status" => "OK", "valid" => $user_key_valid]));
case "alertemail":
engageRateLimit();
if (is_empty($VARS['username']) || !user_exists($VARS['username'])) {
http_response_code(400);
die("\"400 Bad Request\"");
}
$appname = "???";
if (!is_empty($VARS['appname'])) {
$appname = $VARS['appname'];
}
$result = sendLoginAlertEmail($VARS['username'], $appname);
if ($result === TRUE) {
exit(json_encode(["status" => "OK"]));
}
exit(json_encode(["status" => "ERROR", "msg" => $result]));
default:
http_response_code(404);
die(json_encode("404 Not Found: the requested action is not available."));

@ -53,5 +53,5 @@ $STRINGS = [
"login failed try on web" => "There is a problem with your account. Visit Portal via a web browser for more information.",
"mobile login disabled" => "Mobile login has been disabled by your system administrator. Contact technical support for more information.",
"admin alert email subject" => "Alert: User login notification",
"admin alert email message" => "You (or another administrator) requested to be notified when user \"{username}\" logged in, an event which happened just now.\r\n\r\nUsername: {username}\r\nDate/Time: {datetime}\r\nIP address: {ipaddr}",
"admin alert email message" => "You (or another administrator) requested to be notified when user \"{username}\" logged in, an event which happened just now.\r\n\r\nUsername: \t{username}\r\nApplication: \t{appname}\r\nDate/Time: \t{datetime}\r\nIP address: \t{ipaddr}",
];

@ -282,7 +282,7 @@ function doLoginUser($username, $password) {
* @param String $username the account username
* @return Mixed TRUE if successful, error string if not
*/
function sendLoginAlertEmail($username) {
function sendLoginAlertEmail($username, $appname = "Portal") {
if (is_empty(ADMIN_EMAIL) || filter_var(ADMIN_EMAIL, FILTER_VALIDATE_EMAIL) === FALSE) {
return "false";
}
@ -319,7 +319,7 @@ function sendLoginAlertEmail($username) {
$mail->addAddress(ADMIN_EMAIL, "System Admin");
$mail->isHTML(false);
$mail->Subject = lang("admin alert email subject", false);
$mail->Body = lang2("admin alert email message", ["username" => $username, "datetime" => date("Y-m-d H:i:s"), "ipaddr" => getClientIP()], false);
$mail->Body = lang2("admin alert email message", ["username" => $username, "datetime" => date("Y-m-d H:i:s"), "ipaddr" => getClientIP(), "appname" => $appname], false);
if (!$mail->send()) {
return $mail->ErrorInfo;

Loading…
Cancel
Save