Skip to content
Code-Schnipsel Gruppen Projekte

Revisionen vergleichen

Änderungen werden so angezeigt, als ob die Quellrevision mit der Zielrevision zusammengeführt würde. Erfahre mehr über den Vergleich von Revisionen.

Quelle

Zielprojekt auswählen
No results found

Ziel

Zielprojekt auswählen
  • quiqqer/frontend-users
1 Ergebnis
Änderungen anzeigen
Commits auf Quelle (4)
werden angezeigt mit 299 Ergänzungen und 291 Löschungen
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.11.8" installed="1.11.8" location="./tools/phpstan" copy="false"/>
<phar name="phpunit" version="^10.5.20" installed="10.5.20" location="./tools/phpunit" copy="false"/>
<phar name="phpcs" version="^3.10.1" installed="3.10.1" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.10.1" installed="3.10.1" location="./tools/phpcbf" copy="false"/>
<phar name="captainhook" version="^5.23.3" installed="5.23.3" location="./tools/captainhook" copy="false"/>
<phar name="phpstan" version="1.11.8" installed="1.11.8" location="./tools/phpstan" copy="true"/>
<phar name="phpunit" version="^10.5.20" installed="10.5.20" location="./tools/phpunit" copy="true"/>
<phar name="phpcs" version="^3.10.1" installed="3.10.1" location="./tools/phpcs" copy="true"/>
<phar name="phpcbf" version="^3.10.1" installed="3.10.1" location="./tools/phpcbf" copy="true"/>
<phar name="captainhook" version="^5.23.3" installed="5.23.3" location="./tools/captainhook" copy="true"/>
</phive>
......@@ -4,20 +4,22 @@
* @return string - User e-mail address
*/
use QUI\FrontendUsers\ActivationVerification;
use QUI\Verification\Verifier;
use QUI\Verification\VerificationRepository;
QUI::$Ajax->registerFunction(
'package_quiqqer_frontend-users_ajax_frontend_auth_existsUnverifiedActivation',
function ($userId) {
try {
$User = QUI::getUsers()->get($userId);
Verifier::getVerificationByIdentifier($User->getUUID(), ActivationVerification::getType());
$verificationRepository = new VerificationRepository();
$verification = $verificationRepository->findByIdentifier(
'activate-' . $User->getUUID()
);
} catch (Exception) {
return false;
}
return $User->getAttribute('email');
return $verification ? $User->getAttribute('email') : false;
},
['userId']
);
......@@ -4,12 +4,11 @@
* This file contains package_quiqqer_frontend-users_ajax_frontend_auth_resendActivationMail
*/
use QUI\FrontendUsers\ActivationVerification;
use QUI\FrontendUsers\Handler;
use QUI\FrontendUsers\RegistrarInterface;
use QUI\FrontendUsers\Registrars\Email\Registrar as EmailRegistrar;
use QUI\Utils\Security\Orthos;
use QUI\Verification\Verifier;
use QUI\Verification\VerificationRepository;
/**
* Resend an activation mail
......@@ -21,9 +20,16 @@
function ($email) {
try {
$User = QUI::getUsers()->getUserByMail(Orthos::clear($email));
Verifier::getVerificationByIdentifier($User->getUUID(), ActivationVerification::getType());
} catch (Exception $Exception) {
$verificationRepository = new VerificationRepository();
$verification = $verificationRepository->findByIdentifier(
'activate-' . $User->getUUID()
);
// if the verification does not exist -> do not resend mail
if (empty($verification)) {
return false;
}
} catch (Exception $Exception) {
QUI\System\Log::writeException($Exception);
return false;
}
......
......@@ -21,10 +21,10 @@ function ($category, $settings, $data) {
// Check permission
if (!Utils::hasPermissionToViewCategory($category, $settings)) {
throw new \QUI\FrontendUsers\Exception(
throw new \QUI\FrontendUsers\Exception([
'quiqqer/frontend-users',
'exception.ajax.frontend.profile.save.no_category_permission'
);
]);
}
$Control = QUI\FrontendUsers\Utils::getProfileSettingControl($category, $settings);
......
......@@ -6,14 +6,11 @@
* @return array
*/
use QUI\FrontendUsers\AbstractRegistrar;
QUI::$Ajax->registerFunction(
'package_quiqqer_frontend-users_ajax_settings_getAuthenticators',
function () {
$authenticators = [];
/** @var AbstractRegistrar $Registrar */
foreach (QUI\Users\Auth\Handler::getInstance()->getAvailableAuthenticators() as $class) {
/** @var QUI\Users\AbstractAuthenticator $Authenticator */
$Authenticator = new $class();
......
......@@ -29,7 +29,7 @@
"require": {
"quiqqer/core": "^2",
"quiqqer/countries": "^2",
"quiqqer/verification": "^2",
"quiqqer/verification": "^3",
"quiqqer/tooltips": "^2",
"quiqqer/data-layer": "^2"
},
......
......@@ -1805,36 +1805,36 @@ The deletion of your user account on [host] was requested on [date]. Please conf
<locale name="control.sign.up.terms_of_use_and_privacy_policy.label" html="true">
<de><![CDATA[
Durch das Erstellen eines Benutzerkontos versichere ich die
<a href="[termsOfUseUrl]">[termsOfUseSiteTitle]</a> und
<a href="[privacyPolicyUrl]">[privacyPolicySiteTitle]</a>
<a href="[termsOfUseUrl]" data-id="[termsOfUseSiteId]">[termsOfUseSiteTitle]</a> und
<a href="[privacyPolicyUrl]" data-id="[privacyPolicySiteId]">[privacyPolicySiteTitle]</a>
gelesen zu haben und erkläre mich mit diesen einverstanden.
]]></de>
<en><![CDATA[
By creating a user account, I confirm that I have read and agree to the
<a href="[termsOfUseUrl]">[termsOfUseSiteTitle]</a> and
<a href="[privacyPolicyUrl]">[privacyPolicySiteTitle]</a>.
<a href="[termsOfUseUrl]" data-id="[termsOfUseSiteId]">[termsOfUseSiteTitle]</a> and
<a href="[privacyPolicyUrl]" data-id="[privacyPolicySiteId]">[privacyPolicySiteTitle]</a>.
]]></en>
</locale>
<locale name="control.sign.up.terms_of_use.label" html="true">
<de><![CDATA[
Durch das Erstellen eines Benutzerkontos versichere ich die
<a href="[termsOfUseUrl]">[termsOfUseSiteTitle]</a> gelesen zu haben
<a href="[termsOfUseUrl]" data-id="[termsOfUseSiteId]">[termsOfUseSiteTitle]</a> gelesen zu haben
und erkläre mich mit diesen einverstanden.
]]></de>
<en><![CDATA[
By creating a user account, I confirm that I have read and agree to the
<a href="[termsOfUseUrl]">[termsOfUseSiteTitle]</a>.
<a href="[termsOfUseUrl]" data-id="[termsOfUseSiteId]">[termsOfUseSiteTitle]</a>.
]]></en>
</locale>
<locale name="control.sign.up.privacy_policy.label" html="true">
<de><![CDATA[
Durch das Erstellen eines Benutzerkontos versichere ich die
<a href="[privacyPolicyUrl]">[privacyPolicySiteTitle]</a>
<a href="[privacyPolicyUrl]" data-id="[privacyPolicySiteId]">[privacyPolicySiteTitle]</a>
gelesen zu haben und erkläre mich mit diesen einverstanden.
]]></de>
<en><![CDATA[
By creating a user account, I confirm that I have read and agree to the
<a href="[privacyPolicyUrl]">[privacyPolicySiteTitle]</a>.
<a href="[privacyPolicyUrl]" data-id="[privacyPolicySiteId]">[privacyPolicySiteTitle]</a>.
]]></en>
</locale>
<locale name="control.sign.up.type.login.in.button">
......
......@@ -5,59 +5,14 @@ parameters:
count: 1
path: ajax/frontend/profile/save.php
-
message: "#^Parameter \\#2 \\$code of class QUI\\\\FrontendUsers\\\\Exception constructor expects int, string given\\.$#"
count: 1
path: ajax/frontend/profile/save.php
-
message: "#^Variable \\$Registrar in PHPDoc tag @var does not match any variable in the foreach loop\\: \\$class$#"
count: 1
path: ajax/settings/getAuthenticators.php
-
message: "#^PHPDoc tag @return with type mixed is not subtype of native type string\\.$#"
count: 1
path: src/QUI/FrontendUsers/AbstractRegistrar.php
-
message: "#^Parameter \\#1 \\$User of static method QUI\\\\FrontendUsers\\\\Utils\\:\\:setUserEmailVerified\\(\\) expects QUI\\\\Users\\\\User, QUI\\\\Interfaces\\\\Users\\\\User given\\.$#"
count: 1
path: src/QUI/FrontendUsers/ActivationVerification.php
-
message: "#^Parameter \\#1 \\$code of method QUI\\\\Interfaces\\\\Users\\\\User\\:\\:activate\\(\\) expects string, false given\\.$#"
count: 1
path: src/QUI/FrontendUsers/ActivationVerification.php
-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
path: src/QUI/FrontendUsers/Console/SendUserMails.php
-
message: "#^Parameter \\#1 \\$groupId of method QUI\\\\Interfaces\\\\Users\\\\User\\:\\:addToGroup\\(\\) expects int, string given\\.$#"
count: 1
path: src/QUI/FrontendUsers/Console/SetUserGroups.php
-
message: "#^Instantiated class QUI\\\\ERP\\\\Order\\\\Exception not found\\.$#"
count: 6
path: src/QUI/FrontendUsers/Controls/Address/Address.php
-
message: "#^PHPDoc tag @throws with type QUI\\\\ERP\\\\Order\\\\Exception is not subtype of Throwable$#"
count: 1
path: src/QUI/FrontendUsers/Controls/Address/Address.php
-
message: "#^Throwing object of an unknown class QUI\\\\ERP\\\\Order\\\\Exception\\.$#"
count: 6
path: src/QUI/FrontendUsers/Controls/Address/Address.php
-
message: "#^Variable \\$Authenticator in PHPDoc tag @var does not exist\\.$#"
count: 2
count: 1
path: src/QUI/FrontendUsers/Controls/Login.php
-
......@@ -85,16 +40,6 @@ parameters:
count: 1
path: src/QUI/FrontendUsers/Controls/Profile/UserData.php
-
message: "#^Parameter \\#1 \\$code of method QUI\\\\Interfaces\\\\Users\\\\User\\:\\:activate\\(\\) expects string, false given\\.$#"
count: 1
path: src/QUI/FrontendUsers/Controls/Registration.php
-
message: "#^Parameter \\#1 \\$groupId of method QUI\\\\Interfaces\\\\Users\\\\User\\:\\:addToGroup\\(\\) expects int, string given\\.$#"
count: 1
path: src/QUI/FrontendUsers/Controls/Registration.php
-
message: "#^Parameter \\#1 \\$maxWidth of method QUI\\\\Projects\\\\Media\\\\ExternalImage\\:\\:getSizeCacheUrl\\(\\) expects bool, int given\\.$#"
count: 1
......@@ -109,18 +54,3 @@ parameters:
message: "#^Call to an undefined method QUI\\\\Interfaces\\\\Projects\\\\Site\\:\\:getLocation\\(\\)\\.$#"
count: 1
path: src/QUI/FrontendUsers/Events.php
-
message: "#^Call to method createResponse\\(\\) on an unknown class QUI\\\\REST\\\\ResponseFactory\\.$#"
count: 1
path: src/QUI/FrontendUsers/Rest/Routes/GetRegisterRequiredFields.php
-
message: "#^Instantiated class QUI\\\\REST\\\\ResponseFactory not found\\.$#"
count: 1
path: src/QUI/FrontendUsers/Rest/Routes/GetRegisterRequiredFields.php
-
message: "#^Parameter \\#1 \\$groupId of method QUI\\\\Interfaces\\\\Users\\\\User\\:\\:addToGroup\\(\\) expects int, string given\\.$#"
count: 1
path: src/QUI/FrontendUsers/Rest/Routes/PostRegister.php
<?php
namespace QUI\FrontendUsers;
use QUI;
use QUI\Projects\Project;
use QUI\Verification\AbstractLinkVerificationHandler;
use QUI\Verification\Entity\LinkVerification;
/**
* Base class for all link verification handlers of quiqqer/frontend-users.
*/
abstract class AbstractFrontendUsersLinkVerificationHandler extends AbstractLinkVerificationHandler
{
/**
* Get the Project this ActivationVerification is intended for
*
* @param LinkVerification $verification
* @return Project|null
* @throws QUI\Exception
*/
protected function getProject(LinkVerification $verification): ?Project
{
$project = $verification->getCustomDataEntry('project');
$projectLang = $verification->getCustomDataEntry('projectLang');
if (empty($project) || empty($projectLang)) {
return null;
}
return QUI::getProjectManager()->getProject($project, $projectLang);
}
}
......@@ -36,7 +36,7 @@ abstract public function validate(): array;
abstract public function getInvalidFields(): array;
/**
* @return mixed
* @return string
*/
abstract public function getUsername(): string;
......
......@@ -4,7 +4,11 @@
use QUI;
use QUI\Exception;
use QUI\Verification\AbstractVerification;
use QUI\ExceptionStack;
use QUI\Projects\Project;
use QUI\Verification\Entity\LinkVerification;
use QUI\Verification\Enum\VerificationErrorReason;
use QUI\Verification\Entity\AbstractVerification;
/**
* Class ActivationVerification
......@@ -13,16 +17,17 @@
*
* @package QUI\FrontendUsers
*/
class ActivationVerification extends AbstractVerification
class ActivationLinkVerification extends AbstractFrontendUsersLinkVerificationHandler
{
/**
* Get the duration of a Verification (minutes)
*
* @return int|false - duration in minutes;
* @param AbstractVerification $verification
* @return int|null - duration in minutes;
* if this method returns false use the module setting default value
* @throws Exception
*/
public function getValidDuration(): bool|int
public function getValidDuration(AbstractVerification $verification): ?int
{
$settings = Handler::getInstance()->getMailSettings();
return (int)$settings['verificationValidityDuration'];
......@@ -31,17 +36,18 @@ public function getValidDuration(): bool|int
/**
* Execute this method on successful verification
*
* @param LinkVerification $verification
* @return void
* @throws \Exception
*/
public function onSuccess(): void
public function onSuccess(LinkVerification $verification): void
{
$userId = $this->getIdentifier();
try {
$User = QUI::getUsers()->get($userId);
$User->activate(false, QUI::getUsers()->getSystemUser());
$userUuid = $verification->getCustomDataEntry('uuid');
$User = QUI::getUsers()->get($userUuid);
$User->activate('', QUI::getUsers()->getSystemUser());
Utils::setUserEmailVerified($User);
Utils::setDefaultUserEmailVerified($User);
QUI::getEvents()->fireEvent(
'quiqqerFrontendUsersUserActivate',
......@@ -50,21 +56,20 @@ public function onSuccess(): void
Handler::getInstance()->getRegistrar($User->getAttribute(Handler::USER_ATTR_REGISTRAR))
]
);
} catch (QUI\Users\Exception $Exception) {
QUI\System\Log::addWarning(
'quiqqer/frontend-users -> ActivationVerification :: ' . $Exception->getMessage()
);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
throw $Exception;
}
}
/**
* Execute this method on unsuccessful verification
*
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return void
*/
public function onError(): void
public function onError(LinkVerification $verification, VerificationErrorReason $reason): void
{
// nothing
}
......@@ -72,10 +77,11 @@ public function onError(): void
/**
* This message is displayed to the user on successful verification
*
* @param LinkVerification $verification
* @return string
* @throws Exception
*/
public function getSuccessMessage(): string
public function getSuccessMessage(LinkVerification $verification): string
{
$registrationSetting = Handler::getInstance()->getRegistrationSettings();
......@@ -91,10 +97,11 @@ public function getSuccessMessage(): string
/**
* This message is displayed to the user on unsuccessful verification
*
* @param string $reason - The reason for the error (see \QUI\Verification\Verifier::REASON_)
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string
*/
public function getErrorMessage(string $reason): string
public function getErrorMessage(LinkVerification $verification, VerificationErrorReason $reason): string
{
return '';
}
......@@ -102,23 +109,26 @@ public function getErrorMessage(string $reason): string
/**
* Automatically redirect the user to this URL on successful verification
*
* @return string|false - If this method returns false, no redirection takes place
* @param LinkVerification $verification
* @return string|null - If this method returns false, no redirection takes place
* @throws Exception
*/
public function getOnSuccessRedirectUrl(): bool|string
public function getOnSuccessRedirectUrl(LinkVerification $verification): ?string
{
$project = $this->getProject($verification);
if (!$project) {
return null;
}
$RegistrarHandler = Handler::getInstance();
$RegistrationSite = $RegistrarHandler->getRegistrationSignUpSite(
$this->getProject()
);
$RegistrationSite = $RegistrarHandler->getRegistrationSignUpSite($project);
if (empty($RegistrationSite)) {
$RegistrationSite = $RegistrarHandler->getRegistrationSite(
$this->getProject()
);
$RegistrationSite = $RegistrarHandler->getRegistrationSite($project);
if (empty($RegistrationSite)) {
return false;
return null;
}
}
......@@ -126,30 +136,35 @@ public function getOnSuccessRedirectUrl(): bool|string
'success'
], [
'success' => 'activation',
'registrar' => $this->getRegistrarHash()
'registrar' => $this->getRegistrarHash($verification)
]);
}
/**
* Automatically redirect the user to this URL on unsuccessful verification
*
* @return string|false - If this method returns false, no redirection takes place
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string|null - If this method returns false, no redirection takes place
* @throws Exception
* @throws ExceptionStack
*/
public function getOnErrorRedirectUrl(): bool|string
public function getOnErrorRedirectUrl(LinkVerification $verification, VerificationErrorReason $reason): ?string
{
$RegistrarHandler = Handler::getInstance();
$RegistrationSite = $RegistrarHandler->getRegistrationSignUpSite(
$this->getProject()
);
$project = $this->getProject($verification);
if (!$project) {
return null;
}
$RegistrationSite = $RegistrarHandler->getRegistrationSignUpSite($project);
if (empty($RegistrationSite)) {
$RegistrationSite = $RegistrarHandler->getRegistrationSite(
$this->getProject()
);
$RegistrationSite = $RegistrarHandler->getRegistrationSite($project);
if (empty($RegistrationSite)) {
return false;
return null;
}
}
......@@ -157,35 +172,24 @@ public function getOnErrorRedirectUrl(): bool|string
'error'
], [
'error' => 'activation',
'registrar' => $this->getRegistrarHash()
'registrar' => $this->getRegistrarHash($verification)
]);
}
/**
* Get the Project this ActivationVerification is intended for
*
* @return QUI\Projects\Project
* @throws Exception
*/
protected function getProject(): QUI\Projects\Project
{
$additionalData = $this->getAdditionalData();
return QUI::getProjectManager()->getProject($additionalData['project'], $additionalData['projectLang']);
}
/**
* Get hash of registrar used for this Verification
*
* @param LinkVerification $verification
* @return string
*/
protected function getRegistrarHash(): string
protected function getRegistrarHash(LinkVerification $verification): string
{
$data = $this->getAdditionalData();
$registrar = $verification->getCustomDataEntry('registrar');
if (empty($data['registrar'])) {
if (empty($registrar)) {
return '';
}
return $data['registrar'];
return $registrar;
}
}
......@@ -148,7 +148,7 @@ protected function getAuthenticators(): array
}
$authenticators = array_filter($authenticators, function ($authenticator) use ($allowed) {
/** @var QUI\Users\AuthenticatorInterface $Authenticator */
/** @var QUI\Users\AuthenticatorInterface $authenticator */
return in_array($authenticator, $allowed);
});
} catch (Exception $Exception) {
......
......@@ -10,7 +10,8 @@
use QUI;
use QUI\FrontendUsers\Handler;
use QUI\System\Log;
use QUI\Verification\Verifier;
use QUI\Verification\Interface\VerificationRepositoryInterface;
use QUI\Verification\VerificationRepository;
/**
* Class DeleteAccount
......@@ -23,8 +24,14 @@ class DeleteAccount extends AbstractProfileControl
* DeleteAccount constructor.
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
public function __construct(
array $attributes = [],
private ?VerificationRepositoryInterface $verificationRepository = null
) {
if (is_null($this->verificationRepository)) {
$this->verificationRepository = new VerificationRepository();
}
parent::__construct($attributes);
$this->addCSSClass('quiqqer-frontendUsers-controls-profile-deleteaccount');
......@@ -44,17 +51,17 @@ public function getBody(): string
$action = false;
try {
$DeleteVerification = Verifier::getVerificationByIdentifier(
QUI::getUserBySession()->getUUID(),
QUI\FrontendUsers\UserDeleteConfirmVerification::getType(),
true
$verification = $this->verificationRepository->findByIdentifier(
'confirmdelete-' . QUI::getUserBySession()->getUUID()
);
if (Verifier::isVerificationValid($DeleteVerification)) {
$action = 'deleteaccount_confirm_wait';
$this->setJavaScriptControlOption('deletestarted', 1);
} else {
Verifier::removeVerification($DeleteVerification);
if ($verification) {
if ($verification->isValid()) {
$action = 'deleteaccount_confirm_wait';
$this->setJavaScriptControlOption('deletestarted', 1);
} else {
$this->verificationRepository->delete($verification);
}
}
} catch (Exception) {
// nothing - no active user delete verification
......
......@@ -10,6 +10,8 @@
use QUI;
use QUI\FrontendUsers\Handler as FrontendUsersHandler;
use QUI\Utils\Security\Orthos;
use QUI\Verification\Interface\VerificationRepositoryInterface;
use QUI\Verification\VerificationRepository;
use function array_filter;
use function array_keys;
......@@ -29,8 +31,14 @@ class UserData extends AbstractProfileControl
* UserData constructor.
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
public function __construct(
array $attributes = [],
private ?VerificationRepositoryInterface $verificationRepository = null
) {
if (is_null($this->verificationRepository)) {
$this->verificationRepository = new VerificationRepository();
}
parent::__construct($attributes);
$this->addCSSClass('quiqqer-frontendUsers-controls-profile-userdata');
......@@ -60,11 +68,13 @@ public function getBody(): string
}
try {
QUI\Verification\Verifier::getVerificationByIdentifier(
$User->getUUID(),
QUI\FrontendUsers\EmailConfirmVerification::getType(),
true
$verification = $this->verificationRepository->findByIdentifier(
'confirmemail-' . $User->getUUID()
);
if (is_null($verification)) {
$emailChangeRequested = false;
}
} catch (Exception) {
$emailChangeRequested = false;
}
......
......@@ -560,7 +560,7 @@ public function register()
case $RegistrarHandler::ACTIVATION_MODE_AUTO:
case $RegistrarHandler::ACTIVATION_MODE_AUTO_WITH_EMAIL_CONFIRM:
if (!$NewUser->isActive()) {
$NewUser->activate(false, $SystemUser);
$NewUser->activate('', $SystemUser);
}
if ($registrarSettings['activationMode'] == $RegistrarHandler::ACTIVATION_MODE_AUTO_WITH_EMAIL_CONFIRM) {
......
......@@ -415,8 +415,10 @@ protected function siteTermsPrivacy(QUI\Interfaces\Template\EngineInterface $Eng
'control.sign.up.terms_of_use_and_privacy_policy.label',
[
'termsOfUseUrl' => $SiteTerms->getUrlRewritten(),
'termsOfUseSiteId' => $SiteTerms->getId(),
'termsOfUseSiteTitle' => $SiteTerms->getAttribute('title'),
'privacyPolicyUrl' => $SitePrivacy->getUrlRewritten(),
'privacyPolicySiteId' => $SitePrivacy->getId(),
'privacyPolicySiteTitle' => $SitePrivacy->getAttribute('title')
]
);
......@@ -426,6 +428,7 @@ protected function siteTermsPrivacy(QUI\Interfaces\Template\EngineInterface $Eng
'control.sign.up.terms_of_use.label',
[
'termsOfUseUrl' => $SiteTerms->getUrlRewritten(),
'termsOfUseSiteId' => $SiteTerms->getId(),
'termsOfUseSiteTitle' => $SiteTerms->getAttribute('title')
]
);
......@@ -435,6 +438,7 @@ protected function siteTermsPrivacy(QUI\Interfaces\Template\EngineInterface $Eng
'control.sign.up.privacy_policy.label',
[
'privacyPolicyUrl' => $SitePrivacy->getUrlRewritten(),
'privacyPolicySiteId' => $SitePrivacy->getId(),
'privacyPolicySiteTitle' => $SitePrivacy->getAttribute('title')
]
);
......
......@@ -4,7 +4,9 @@
use QUI;
use QUI\Exception;
use QUI\Verification\AbstractVerification;
use QUI\Verification\Entity\LinkVerification;
use QUI\Verification\Enum\VerificationErrorReason;
use QUI\Verification\Entity\AbstractVerification;
/**
* Class EmailConfirmVerification
......@@ -13,16 +15,17 @@
*
* @package QUI\FrontendUsers
*/
class EmailConfirmVerification extends AbstractVerification
class EmailConfirmLinkVerification extends AbstractFrontendUsersLinkVerificationHandler
{
/**
* Get the duration of a Verification (minutes)
*
* @param AbstractVerification $verification
* @return int - duration in minutes;
* if this method returns false use the module setting default value
* @throws Exception
*/
public function getValidDuration(): int
public function getValidDuration(AbstractVerification $verification): int
{
$settings = Handler::getInstance()->getMailSettings();
return (int)$settings['verificationValidityDuration'];
......@@ -31,16 +34,16 @@ public function getValidDuration(): int
/**
* Execute this method on successful verification
*
* @param LinkVerification $verification
* @return void
*/
public function onSuccess(): void
public function onSuccess(LinkVerification $verification): void
{
$userId = $this->getIdentifier();
try {
$RegistrarHandler = QUI\FrontendUsers\Handler::getInstance();
$User = QUI::getUsers()->get($userId);
$newEmail = $this->additionalData['newEmail'];
$userUuid = $verification->getCustomDataEntry('uuid');
$User = QUI::getUsers()->get($userUuid);
$newEmail = $verification->getCustomDataEntry('newEmail');
// if users cannot set their own username -> change username as well
// if it equals the old email-address
......@@ -57,7 +60,7 @@ public function onSuccess(): void
$User->save(QUI::getUsers()->getSystemUser());
} catch (\Exception $Exception) {
QUI\System\Log::addError(
self::class . ' :: onSuccess -> Could not find user #' . $userId
self::class . ' :: onSuccess -> Could not find user #' . $userUuid
);
QUI\System\Log::writeException($Exception);
......@@ -67,9 +70,11 @@ public function onSuccess(): void
/**
* Execute this method on unsuccessful verification
*
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return void
*/
public function onError(): void
public function onError(LinkVerification $verification, VerificationErrorReason $reason): void
{
// nothing
}
......@@ -77,9 +82,10 @@ public function onError(): void
/**
* This message is displayed to the user on successful verification
*
* @param LinkVerification $verification
* @return string
*/
public function getSuccessMessage(): string
public function getSuccessMessage(LinkVerification $verification): string
{
return '';
}
......@@ -87,10 +93,11 @@ public function getSuccessMessage(): string
/**
* This message is displayed to the user on unsuccessful verification
*
* @param string $reason - The reason for the error (see \QUI\Verification\Verifier::REASON_)
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string
*/
public function getErrorMessage(string $reason): string
public function getErrorMessage(LinkVerification $verification, VerificationErrorReason $reason): string
{
return '';
}
......@@ -98,17 +105,22 @@ public function getErrorMessage(string $reason): string
/**
* Automatically redirect the user to this URL on successful verification
*
* @return string|false - If this method returns false, no redirection takes place
* @param LinkVerification $verification
* @return string|null - If this method returns false, no redirection takes place
* @throws Exception
*/
public function getOnSuccessRedirectUrl(): bool|string
public function getOnSuccessRedirectUrl(LinkVerification $verification): ?string
{
$RegistrationSite = Handler::getInstance()->getRegistrationSignUpSite(
$this->getProject()
);
$project = $this->getProject($verification);
if (!$project) {
return null;
}
$RegistrationSite = Handler::getInstance()->getRegistrationSignUpSite($project);
if (!$RegistrationSite) {
return false;
return null;
}
return $RegistrationSite->getUrlRewritten([], [
......@@ -119,37 +131,23 @@ public function getOnSuccessRedirectUrl(): bool|string
/**
* Automatically redirect the user to this URL on unsuccessful verification
*
* @return string|false - If this method returns false, no redirection takes place
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string|null - If this method returns false, no redirection takes place
* @throws Exception
*/
public function getOnErrorRedirectUrl(): bool|string
public function getOnErrorRedirectUrl(LinkVerification $verification, VerificationErrorReason $reason): ?string
{
$RegistrationSite = Handler::getInstance()->getRegistrationSignUpSite(
$this->getProject()
);
$project = $this->getProject($verification);
$RegistrationSite = Handler::getInstance()->getRegistrationSignUpSite($project);
if (!$RegistrationSite) {
return false;
return null;
}
return $RegistrationSite->getUrlRewritten([], [
'error' => 'emailconfirm'
]);
}
/**
* Get the Project this Verification is intended for
*
* @return QUI\Projects\Project
* @throws Exception
*/
protected function getProject(): QUI\Projects\Project
{
$additionalData = $this->getAdditionalData();
return QUI::getProjectManager()->getProject(
$additionalData['project'],
$additionalData['projectLang']
);
}
}
......@@ -4,21 +4,24 @@
use QUI;
use QUI\Exception;
use QUI\Verification\AbstractVerification;
use QUI\Verification\Entity\LinkVerification;
use QUI\Verification\Enum\VerificationErrorReason;
use QUI\Verification\Entity\AbstractVerification;
/**
* User verification to confirm an e-mail-address
*/
class EmailVerification extends AbstractVerification
class EmailVerification extends AbstractFrontendUsersLinkVerificationHandler
{
/**
* Get the duration of a Verification (minutes)
*
* @param AbstractVerification $verification
* @return int - duration in minutes;
* if this method returns false use the module setting default value
* @throws Exception
*/
public function getValidDuration(): int
public function getValidDuration(AbstractVerification $verification): int
{
$settings = Handler::getInstance()->getMailSettings();
return (int)$settings['verificationValidityDuration'];
......@@ -27,16 +30,15 @@ public function getValidDuration(): int
/**
* Execute this method on successful verification
*
* @param LinkVerification $verification
* @return void
* @throws \Exception
*/
public function onSuccess(): void
public function onSuccess(LinkVerification $verification): void
{
$userId = $this->getIdentifier();
try {
$User = QUI::getUsers()->get($userId);
$email = $this->additionalData['email'];
$User = QUI::getUsers()->get($verification->getCustomDataEntry('uuid'));
$email = $verification->getCustomDataEntry('email');
Utils::setEmailAddressAsVerfifiedForUser($email, $User);
} catch (\Exception $Exception) {
......@@ -48,9 +50,11 @@ public function onSuccess(): void
/**
* Execute this method on unsuccessful verification
*
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return void
*/
public function onError(): void
public function onError(LinkVerification $verification, VerificationErrorReason $reason): void
{
// nothing
}
......@@ -58,9 +62,10 @@ public function onError(): void
/**
* This message is displayed to the user on successful verification
*
* @param LinkVerification $verification
* @return string
*/
public function getSuccessMessage(): string
public function getSuccessMessage(LinkVerification $verification): string
{
return '';
}
......@@ -68,10 +73,11 @@ public function getSuccessMessage(): string
/**
* This message is displayed to the user on unsuccessful verification
*
* @param string $reason - The reason for the error (see \QUI\Verification\Verifier::REASON_)
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string
*/
public function getErrorMessage(string $reason): string
public function getErrorMessage(LinkVerification $verification, VerificationErrorReason $reason): string
{
return '';
}
......@@ -79,17 +85,18 @@ public function getErrorMessage(string $reason): string
/**
* Automatically redirect the user to this URL on successful verification
*
* @return string|false - If this method returns false, no redirection takes place
* @param LinkVerification $verification
* @return string|null - If this method returns false, no redirection takes place
* @throws Exception
*/
public function getOnSuccessRedirectUrl(): bool|string
public function getOnSuccessRedirectUrl(LinkVerification $verification): ?string
{
$RegistrationSite = Handler::getInstance()->getRegistrationSignUpSite(
$this->getProject()
$this->getProject($verification)
);
if (!$RegistrationSite) {
return false;
return null;
}
return $RegistrationSite->getUrlRewritten([], [
......@@ -100,37 +107,23 @@ public function getOnSuccessRedirectUrl(): bool|string
/**
* Automatically redirect the user to this URL on unsuccessful verification
*
* @return string|false - If this method returns false, no redirection takes place
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string|null - If this method returns false, no redirection takes place
* @throws Exception
*/
public function getOnErrorRedirectUrl(): bool|string
public function getOnErrorRedirectUrl(LinkVerification $verification, VerificationErrorReason $reason): ?string
{
$RegistrationSite = Handler::getInstance()->getRegistrationSignUpSite(
$this->getProject()
$this->getProject($verification)
);
if (!$RegistrationSite) {
return false;
return null;
}
return $RegistrationSite->getUrlRewritten([], [
'error' => 'emailconfirm'
]);
}
/**
* Get the Project this Verification is intended for
*
* @return QUI\Projects\Project
* @throws Exception
*/
protected function getProject(): QUI\Projects\Project
{
$additionalData = $this->getAdditionalData();
return QUI::getProjectManager()->getProject(
$additionalData['project'],
$additionalData['projectLang']
);
}
}
......@@ -5,8 +5,8 @@
use QUI;
use QUI\Exception;
use QUI\Interfaces\Users\User;
use QUI\Verification\Verifier;
use QUI\Smarty\Collector;
use QUI\Verification\VerificationRepository;
use function base64_encode;
use function json_encode;
......@@ -234,13 +234,16 @@ public static function onUserDelete(User $User): void
{
// delete Verification for user (if not yet deleted by quiqqer/verification cron)
try {
$Verification = Verifier::getVerificationByIdentifier(
$User->getUUID(),
ActivationVerification::getType()
$repository = new VerificationRepository();
$verification = $repository->findByIdentifier(
'activate-' . $User->getUUID()
);
Verifier::removeVerification($Verification);
} catch (\Exception) {
// if Verification not found it does not have to be deleted
if ($verification) {
$repository->delete($verification);
}
} catch (\Throwable) {
// nothing -> if Verification not found it does not have to be deleted
}
}
......
......@@ -3,10 +3,11 @@
namespace QUI\FrontendUsers;
use QUI;
use QUI\Interfaces\Users\User as QUIUserInterface;
use QUI\Mail\Mailer;
use QUI\Utils\Singleton;
use QUI\Verification\Verifier;
use QUI\Interfaces\Users\User as QUIUserInterface;
use QUI\Verification\Interface\VerificationFactoryInterface;
use QUI\Verification\VerificationFactory;
use function array_filter;
use function time;
......@@ -97,8 +98,13 @@ class Handler extends Singleton
/**
* Handler constructor.
*/
public function __construct()
{
public function __construct(
private ?VerificationFactoryInterface $verificationFactory = null
) {
if (is_null($this->verificationFactory)) {
$this->verificationFactory = new VerificationFactory();
}
$this->Registrar = new RegistrarCollection();
}
......@@ -412,13 +418,17 @@ public function sendActivationMail(QUI\Interfaces\Users\User $User, RegistrarInt
{
$Project = $Registrar->getProject();
$ActivationVerification = new ActivationVerification($User->getUUID(), [
'project' => $Project->getName(),
'projectLang' => $Project->getLang(),
'registrar' => $Registrar->getHash()
]);
$activationLink = Verifier::startVerification($ActivationVerification, true);
$verification = $this->verificationFactory->createLinkVerification(
'activate-' . $User->getUUID(),
new ActivationLinkVerification(),
[
'uuid' => $User->getUUID(),
'project' => $Project->getName(),
'projectLang' => $Project->getLang(),
'registrar' => $Registrar->getHash()
],
true
);
$L = QUI::getLocale();
$lg = 'quiqqer/frontend-users';
......@@ -445,7 +455,7 @@ public function sendActivationMail(QUI\Interfaces\Users\User $User, RegistrarInt
'userLastName' => $User->getAttribute('lastname') ?: '',
'email' => $User->getAttribute('email'),
'date' => $L->formatDate(time()),
'activationLink' => $activationLink
'activationLink' => $verification->getVerificationUrl()
])
]
);
......@@ -603,13 +613,17 @@ public function sendChangeEmailAddressMail(
string $newEmail,
QUI\Projects\Project $Project
): void {
$EmailConfirmVerification = new EmailConfirmVerification($User->getUUID(), [
'project' => $Project->getName(),
'projectLang' => $Project->getLang(),
'newEmail' => $newEmail
]);
$confirmLink = Verifier::startVerification($EmailConfirmVerification, true);
$verification = $this->verificationFactory->createLinkVerification(
'confirmemail-' . $User->getUUID(),
new EmailConfirmLinkVerification(),
[
'uuid' => $User->getUUID(),
'project' => $Project->getName(),
'projectLang' => $Project->getLang(),
'newEmail' => $newEmail
],
true
);
$L = QUI::getLocale();
$lg = 'quiqqer/frontend-users';
......@@ -634,7 +648,7 @@ public function sendChangeEmailAddressMail(
'userLastName' => $User->getAttribute('lastname') ?: '',
'email' => $newEmail,
'date' => $L->formatDate(time()),
'confirmLink' => $confirmLink
'confirmLink' => $verification->getVerificationUrl()
])
]
);
......@@ -646,6 +660,7 @@ public function sendChangeEmailAddressMail(
QUI\System\Log::writeException($Exception);
}
}
/**
* Send email to confirm an email address.
*
......@@ -661,13 +676,16 @@ public function sendEmailConfirmationMail(
string $email,
QUI\Projects\Project $Project
): void {
$EmailConfirmVerification = new EmailVerification($User->getUUID(), [
'project' => $Project->getName(),
'projectLang' => $Project->getLang(),
'email' => $email
]);
$confirmLink = Verifier::startVerification($EmailConfirmVerification, true);
$verification = $this->verificationFactory->createLinkVerification(
'confirmemail-' . $User->getUUID(),
new EmailVerification(),
[
'uuid' => $User->getUUID(),
'project' => $Project->getName(),
'projectLang' => $Project->getLang(),
'email' => $email
]
);
$L = QUI::getLocale();
$lg = 'quiqqer/frontend-users';
......@@ -692,7 +710,7 @@ public function sendEmailConfirmationMail(
'userLastName' => $User->getAttribute('lastname') ?: '',
'email' => $email,
'date' => $L->formatDate(time()),
'confirmLink' => $confirmLink
'confirmLink' => $verification->getVerificationUrl()
])
]
);
......@@ -717,12 +735,15 @@ public function sendEmailConfirmationMail(
*/
public function sendDeleteUserConfirmationMail(QUI\Interfaces\Users\User $User, QUI\Projects\Project $Project): void
{
$DeleteUserVerification = new UserDeleteConfirmVerification($User->getUUID(), [
'project' => $Project->getName(),
'projectLang' => $Project->getLang()
]);
$confirmLink = Verifier::startVerification($DeleteUserVerification, true);
$verification = $this->verificationFactory->createLinkVerification(
'confirmdelete-' . $User->getUUID(),
new UserDeleteConfirmLinkVerification(),
[
'uuid' => $User->getUUID(),
'project' => $Project->getName(),
'projectLang' => $Project->getLang()
]
);
$L = QUI::getLocale();
$lg = 'quiqqer/frontend-users';
......@@ -746,7 +767,7 @@ public function sendDeleteUserConfirmationMail(QUI\Interfaces\Users\User $User,
'userFirstName' => $User->getAttribute('firstname') ?: '',
'userLastName' => $User->getAttribute('lastname') ?: '',
'date' => $L->formatDate(time()),
'confirmLink' => $confirmLink
'confirmLink' => $verification
])
]
);
......