settings send test mail frontend

This commit is contained in:
2024-04-05 14:17:50 +02:00
parent 98fcd2822c
commit 964b98c22a
9 changed files with 95 additions and 10 deletions

View File

@@ -185,6 +185,7 @@ namespace Core\API\Mail {
$mail->addStringAttachment("Version: 1", null, PHPMailer::ENCODING_BASE64, "application/pgp-encrypted", "");
$mail->addStringAttachment($encryptedBody, "encrypted.asc", PHPMailer::ENCODING_7BIT, "application/octet-stream", "");
} else {
$this->logger->error("Error encrypting with gpg: " . $res["error"]);
return $this->createError($res["error"]);
}
} else {
@@ -237,6 +238,7 @@ namespace Core\API\Mail {
if ($this->success && is_array($mailQueueItems)) {
if ($debug) {
echo "Found " . count($mailQueueItems) . " mails to send" . PHP_EOL;
$this->logger->debug("Found " . count($mailQueueItems) . " mails to send");
}
$successfulMails = 0;
@@ -249,6 +251,7 @@ namespace Core\API\Mail {
if ($debug) {
echo "Sending subject=$mailQueueItem->subject to=$mailQueueItem->to" . PHP_EOL;
$this->logger->debug("Sending subject=$mailQueueItem->subject to=$mailQueueItem->to");
}
if ($mailQueueItem->send($this->context)) {
@@ -257,6 +260,9 @@ namespace Core\API\Mail {
}
$this->success = $successfulMails === count($mailQueueItems);
if ($successfulMails > 0) {
$this->logger->debug("Sent $successfulMails emails successfully");
}
}
return $this->success;

View File

@@ -117,6 +117,10 @@ namespace Core\API\Settings {
$this->success = ($query->execute() !== FALSE);
$this->lastError = $sql->getLastError();
if ($this->success) {
$this->logger->info("The site settings were changed");
}
}
return $this->success;

View File

@@ -183,6 +183,8 @@ namespace Core\API\User {
$groups = [];
$sql = $this->context->getSQL();
$currentUser = $this->context->getUser();
$currentUserId = $currentUser->getId();
$requestedGroups = array_unique($this->getParam("groups"));
if (!empty($requestedGroups)) {
@@ -190,7 +192,7 @@ namespace Core\API\User {
foreach ($requestedGroups as $groupId) {
if (!isset($availableGroups[$groupId])) {
return $this->createError("Group with id=$groupId does not exist.");
} else if ($groupId === Group::ADMIN && !$this->context->getUser()->hasGroup(Group::ADMIN)) {
} else if ($groupId === Group::ADMIN && !$currentUser->hasGroup(Group::ADMIN)) {
return $this->createError("You cannot create users with administrator groups.");
}
}
@@ -202,6 +204,7 @@ namespace Core\API\User {
if ($user !== false) {
$this->user = $user;
$this->result["userId"] = $user->getId();
$this->logger->info("A new user with username='$username' and email='$email' was created by userId='$currentUserId'");
}
return $this->success;
@@ -423,6 +426,9 @@ namespace Core\API\User {
return false;
}
$currentUserId = $this->context->getUser()->getId();
$this->logger->info("A new user with username='$username' and email='$email' was invited by userId='$currentUserId'");
// Create Token
$token = generateRandomString(36);
$validDays = 7;
@@ -724,6 +730,8 @@ namespace Core\API\User {
return false;
}
$this->logger->info("A new user with username='$username' and email='$email' was created");
$validHours = 48;
$token = generateRandomString(36);
$userToken = new UserToken($user, $token, UserToken::TYPE_EMAIL_CONFIRM, $validHours);
@@ -756,12 +764,12 @@ namespace Core\API\User {
$this->lastError = $request->getLastError();
}
} else {
$this->lastError = "Could create user token: " . $sql->getLastError();
$this->lastError = "Could not create user token: " . $sql->getLastError();
$this->success = false;
}
if (!$this->success) {
$this->logger->error("Could not deliver email to=$email type=register reason=" . $this->lastError);
$this->logger->error("Could not deliver email to='$email' type='register' reason='" . $this->lastError . "'");
$this->lastError = "Your account was registered but the confirmation email could not be sent. " .
"Please contact the server administration. This issue has been automatically logged. Reason: " . $this->lastError;
}
@@ -1007,7 +1015,7 @@ namespace Core\API\User {
"gpgFingerprint" => $gpgFingerprint
));
$this->lastError = $request->getLastError();
$this->logger->info("Requested password reset for user id=" . $user->getId() . " by ip_address=" . $_SERVER["REMOTE_ADDR"]);
$this->logger->info("Requested password reset for user id='" . $user->getId() . "' by ip_address='" . $_SERVER["REMOTE_ADDR"] . "'");
}
}
}