Commit 9dc17ca5 authored by Tino Goratsch's avatar Tino Goratsch

send a HTML email when an user registers a new account

parent b405fd73
......@@ -116,6 +116,38 @@ class Register extends Core\Controller\AbstractFrontendAction
$this->registrationFormValidation->validate($formData);
$mailIsSent = $this->sendRegistrationEmail($formData);
$salt = $this->secureHelper->salt(Users\Model\UserModel::SALT_LENGTH);
$insertValues = [
'id' => '',
'nickname' => $this->get('core.helpers.secure')->strEncode($formData['nickname']),
'pwd' => $this->secureHelper->generateSaltedPassword($salt, $formData['pwd'], 'sha512'),
'pwd_salt' => $salt,
'mail' => $formData['mail'],
'registration_date' => $this->date->getCurrentDateTime(),
];
$lastId = $this->userRepository->insert($insertValues);
$bool2 = $this->permissionsHelpers->updateUserRoles([2], $lastId);
$this->setTemplate($this->get('core.helpers.alerts')->confirmBox(
$this->translator->t('users',
$mailIsSent === true && $lastId !== false && $bool2 !== false ? 'register_success' : 'register_error'
),
$this->appPath->getWebRoot()
));
},
$this->request->getFullPath()
);
}
/**
* @param array $formData
* @return bool
*/
protected function sendRegistrationEmail(array $formData)
{
$systemSettings = $this->config->getSettings(Schema::MODULE_NAME);
$settings = $this->config->getSettings(Users\Installer\Schema::MODULE_NAME);
......@@ -137,28 +169,14 @@ class Register extends Core\Controller\AbstractFrontendAction
'{host}' => $this->request->getHost()
]
);
$mailIsSent = $this->sendEmail->execute('', $formData['mail'], $settings['mail'], $subject, $body);
$salt = $this->secureHelper->salt(Users\Model\UserModel::SALT_LENGTH);
$insertValues = [
'id' => '',
'nickname' => $this->get('core.helpers.secure')->strEncode($formData['nickname']),
'pwd' => $this->secureHelper->generateSaltedPassword($salt, $formData['pwd'], 'sha512'),
'pwd_salt' => $salt,
'mail' => $formData['mail'],
'registration_date' => $this->date->getCurrentDateTime(),
];
$lastId = $this->userRepository->insert($insertValues);
$bool2 = $this->permissionsHelpers->updateUserRoles([2], $lastId);
$data = (new Core\Mailer\MailerMessage())
->setRecipients($formData['mail'])
->setFrom($settings['mail'])
->setSubject($subject)
->setBody($body)
->setTemplate('Users/layout.email.register.tpl');
$this->setTemplate($this->get('core.helpers.alerts')->confirmBox(
$this->translator->t('users',
$mailIsSent === true && $lastId !== false && $bool2 !== false ? 'register_success' : 'register_error'),
$this->appPath->getWebRoot()
));
},
$this->request->getFullPath()
);
return $this->sendEmail->execute($data);
}
}
{extends file="asset:System/layout.email.tpl"}
{block EMAIL_HEAD}
<title>{$mail.title}</title>
{/block}
{block EMAIL_CONTENT}
{$mail.body}
{/block}
{extends file="asset:Users/layout.email.register.tpl"}
{extends file="asset:System/layout.email.tpl"}
{block EMAIL_HEAD}
<title>{$mail.title}</title>
{/block}
{block EMAIL_CONTENT}
{$mail.body}
{/block}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment