added bulk creation and e-mail sending
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
/**
|
||||
* Description of UserController
|
||||
*
|
||||
@@ -44,6 +47,7 @@ class UserController extends mfBaseController
|
||||
"ADD_URL" => self::getUrl("User", "Form"),
|
||||
"EDIT_URL" => self::getUrl("User", "Form"),
|
||||
"IMPERSONATE_URL" => self::getUrl("User", "impersonate"),
|
||||
"SEND_LOGIN_EMAIL_URL" => self::getUrl("User", "sendLoginEmail"),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -583,4 +587,159 @@ class UserController extends mfBaseController
|
||||
$_SESSION[MFAPPNAME.'_impersonate'] = $this->request->username;
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
protected function sendLoginEmailAction()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
if (!$id || !is_numeric($id)) {
|
||||
self::sendError("Benutzer-ID fehlt oder ist ungültig.");
|
||||
}
|
||||
|
||||
$user = new User($id);
|
||||
if (!$user->id || !$user->email) {
|
||||
self::sendError("Benutzer nicht gefunden oder keine E-Mail-Adresse hinterlegt.");
|
||||
}
|
||||
|
||||
$userFullName = htmlspecialchars($user->name);
|
||||
$userUsername = htmlspecialchars($user->username);
|
||||
$firstName = htmlspecialchars(explode(' ', $user->name)[0]);
|
||||
|
||||
$subject = "Ihr Zugang zu TheTOOL by XINON, {$firstName}!";
|
||||
|
||||
$logoToolPath = LIBDIR . '/../public/assets/images/the-tool-logo.png';
|
||||
$logoXinonPath = LIBDIR . '/../public/assets/images/xinon-full.png';
|
||||
|
||||
$logoToolTag = file_exists($logoToolPath) ? '<img src="cid:logo_thetool" alt="TheTOOL Logo" style="max-height: 40px; border: 0;">' : '';
|
||||
$logoXinonTag = file_exists($logoXinonPath) ? '<img src="cid:logo_xinon" alt="XINON Logo" style="max-height: 40px; border: 0;">' : '';
|
||||
|
||||
$currentYear = date("Y");
|
||||
$xinonBlue = '#005384';
|
||||
$loginLink = 'https://thetool.xinon.at';
|
||||
$passwordResetLink = 'https://thetool.xinon.at/UserPasswordReset/forgotPassword';
|
||||
|
||||
$html = <<<HTML
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{$subject}</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
|
||||
table, td { border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
|
||||
img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; }
|
||||
p { display: block; margin: 13px 0; }
|
||||
</style>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0; background-color: #f3f4f6;">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #f3f4f6;">
|
||||
<tr>
|
||||
<td style="padding: 20px 10px;">
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width: 100%; max-width: 600px;">
|
||||
<tr>
|
||||
<td>
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background-color: #ffffff; width: 100%; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); border-top: 5px solid {$xinonBlue};">
|
||||
<tr>
|
||||
<td align="center" style="padding: 25px 20px; border-bottom: 1px solid #eeeeee;">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" width="50%" style="text-align: left; padding-left: 10px;">{$logoToolTag}</td>
|
||||
<td align="right" width="50%" style="text-align: right; padding-right: 10px;">{$logoXinonTag}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 30px 40px 35px 40px;">
|
||||
<h1 style="font-family: Arial, sans-serif; font-size: 28px; font-weight: bold; color: #111827; margin: 0 0 16px 0;">Willkommen an Bord, {$firstName}!</h1>
|
||||
<p style="font-family: Arial, sans-serif; font-size: 16px; color: #4b5563; margin: 0 0 24px;">Wir freuen uns, Sie im Team zu haben. Ihr Zugang zu <strong>einer smarteren Arbeitsweise</strong> ist freigeschaltet.</p>
|
||||
|
||||
<p style="font-family: Arial, sans-serif; font-size: 16px; color: #4b5563;">Ihr persönlicher Benutzername lautet:</p>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td style="background-color: #f3f4f6; border-radius: 5px; padding: 12px 15px; font-family: monospace, sans-serif; font-size: 18px; color: #111827; text-align: center; border: 1px solid #e5e7eb;">
|
||||
{$userUsername}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p style="font-family: Arial, sans-serif; font-size: 16px; color: #4b5563; margin-top: 30px; text-align: center;">Um zu starten, legen Sie bitte Ihr <strong>persönliches Passwort</strong> fest.</p>
|
||||
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td align="center" style="padding: 15px 0 25px 0;">
|
||||
<a href="{$passwordResetLink}" target="_blank" style="font-family: Arial, sans-serif; font-size: 18px; font-weight: bold; color: #ffffff; text-decoration: none; background-color: {$xinonBlue}; padding: 15px 30px; border-radius: 8px; display: inline-block;">Passwort erstmalig setzen</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td align="center" style="border-top: 1px solid #eeeeee; padding-top: 25px;">
|
||||
<p style="font-family: Arial, sans-serif; font-size: 14px; color: #6b7280; margin: 0;">Oder besitzen Sie bereits ein Passwort?</p>
|
||||
<a href="{$loginLink}" target="_blank" style="font-family: Arial, sans-serif; font-size: 14px; color: {$xinonBlue}; text-decoration: underline;">Direkt zur Login-Seite</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 20px 40px; text-align: center; font-size: 12px; color: #6b7280; border-top: 1px solid #eeeeee; background-color: #fafafa; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px;">
|
||||
<p style="font-family: Arial, sans-serif; margin: 0;">
|
||||
© {$currentYear} XINON GmbH | <a href="https://xinon.at/impressum/" target="_blank" style="color: {$xinonBlue}; text-decoration: none;">Impressum</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
$altBody = "Willkommen an Bord, {$firstName}!\n\n" .
|
||||
"Wir freuen uns, Sie im Team zu haben. Ihr Zugang zu einer smarteren Arbeitsweise ist freigeschaltet.\n\n" .
|
||||
"Ihr persönlicher Benutzername lautet: {$userUsername}\n\n" .
|
||||
"Um zu starten, legen Sie bitte Ihr persönliches Passwort fest. Besuchen Sie dazu folgende Seite:\n" .
|
||||
"{$passwordResetLink}\n\n" .
|
||||
"Oder besitzen Sie bereits ein Passwort? Hier geht es direkt zum Login:\n" .
|
||||
"{$loginLink}\n\n" .
|
||||
"© {$currentYear} XINON GmbH | Impressum: https://xinon.at/impressum/";
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = TT_PIPEWORK_SMTP_HOST;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = TT_PIPEWORK_SMTP_USER;
|
||||
$mail->Password = TT_PIPEWORK_SMTP_PASS;
|
||||
$mail->CharSet = PHPMailer::CHARSET_UTF8;
|
||||
$mail->Encoding = 'base64';
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mail->Port = 587;
|
||||
|
||||
if (file_exists($logoToolPath)) $mail->addEmbeddedImage($logoToolPath, 'logo_thetool');
|
||||
if (file_exists($logoXinonPath)) $mail->addEmbeddedImage($logoXinonPath, 'logo_xinon');
|
||||
|
||||
$mail->setFrom('thetool@xinon.at', 'TheTOOL by XINON');
|
||||
$mail->addReplyTo('office@xinon.at', 'XINON Office');
|
||||
$mail->addAddress($user->email, $user->name);
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $html;
|
||||
$mail->AltBody = $altBody;
|
||||
|
||||
$mail->send();
|
||||
self::returnJson(['success' => true, 'message' => 'Willkommens-E-Mail wurde erfolgreich an ' . htmlspecialchars($user->email) . ' gesendet.']);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Mailer Error in sendLoginEmailAction for user ID {$id}: " . $mail->ErrorInfo);
|
||||
self::sendError("E-Mail konnte nicht gesendet werden. Bitte kontaktieren Sie den Support.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user