Skip to content
Code-Schnipsel Gruppen Projekte
Commit cf13daed erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

Merge branch 'feat-verification-codes' into 'next-3.x'

feat!: version 3.0 RC

See merge request !10
Übergeordnete 8251ada8 20bd489f
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
2 Merge Requests!11feat!: version 3.0,!10feat!: version 3.0 RC
Pipeline-Nr. 13738 bestanden
werden angezeigt mit 707 Ergänzungen und 232 Löschungen
# Ignore developer files when exporting
.gitattributes export-ignore
.gitignore export-ignore
.gitlab-ci.yml export-ignore
.phive export-ignore
captainhook.json export-ignore
phpcs.xml.dist export-ignore
phpstan-baseline.neon export-ignore
phpstan.dist.neon export-ignore
phpunit.dist.xml export-ignore
tests export-ignore
# Explicitly set file type and line endings for PHP files, improves git diff output
*.php text eol=lf diff=php
\ No newline at end of file
tools/ tools/
phpstan.neon phpstan.neon
.phpunit.result.cache .phpunit.result.cache
phpunit.xml phpunit.xml
\ No newline at end of file tools/
phpstan.neon
.phpunit.result.cache
phpunit.xml
include: include:
- project: 'quiqqer/stabilization/semantic-release' - component: dev.quiqqer.com/quiqqer/stabilization/ci-cd-components/quiqqer-package-bundle/quiqqer-package-bundle@main
file: '/ci-templates/.gitlab-ci.yml'
# Remove the entire phpunit-php8.1 block, to allow PHPUnit to run on PHP 8.1 in your pipeline
phpunit-php8.1:
rules:
- when: never
# Remove the entire phpunit-php8.2 block, to allow PHPUnit to run on PHP 8.2 in your pipeline
phpunit-php8.2:
rules:
- when: never
# Remove the entire phpunit-php8.3 block, to allow PHPUnit to run on PHP 8.3 in your pipeline
phpunit-php8.3:
rules:
- when: never
# Disable PHP 8.1 syntax check, as PHP 8.3 is minimum requirement
php-syntax-check-8.1:
rules:
- when: never
# Disable PHP 8.2 syntax check, as PHP 8.3 is minimum requirement
php-syntax-check-8.2:
rules:
- when: never
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive"> <phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="^1.10.67" installed="1.10.67" location="./tools/phpstan" 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> </phive>
# Contributing
This package follows the [QUIQQER contribution guidelines](https://dev.quiqqer.com/quiqqer/stabilization/documentation/-/wikis/home).
\ No newline at end of file
{
"pre-commit": {
"enabled": true,
"actions": [
{
"action": "\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting"
},
{
"action": "composer test"
}
]
}
}
\ No newline at end of file
{ {
"name": "quiqqer/verification", "name": "quiqqer/verification",
"type": "quiqqer-plugin", "type": "quiqqer-plugin",
"description": "Verify any action via a special url with a unique hash (i.e. user registration, newsletter opt-in etc.)", "description": "Verify any action via a special url with a unique hash (i.e. user registration, newsletter opt-in etc.)",
"license": [ "license": [
"PCSG QL-1.0", "PCSG QL-1.0",
"CC BY-NC-SA 4.0" "CC BY-NC-SA 4.0"
], ],
"homepage": "https://www.quiqqer.com", "homepage": "https://www.quiqqer.com",
"authors": [ "authors": [
{ {
"name": "Patrick M\u00fcller", "name": "Patrick Müller",
"email": "p.mueller@pcsg.de", "email": "p.mueller@pcsg.de",
"homepage": "https://www.pcsg.de", "homepage": "https://www.pcsg.de",
"role": "Developer" "role": "Developer"
}
],
"support": {
"email": "support@pcsg.de",
"url": "https://www.pcsg.de",
"issues": "https://dev.quiqqer.com/quiqqer/verification/issues",
"source": "https://dev.quiqqer.com/quiqqer/verification"
},
"require": {
"quiqqer/core": "^2"
},
"autoload": {
"psr-4": {
"QUI\\Verification\\": "src/QUI/Verification"
}
},
"scripts": {
"test": [
"@dev:lint",
"@dev:phpunit"
],
"dev:phpunit": "./tools/phpunit",
"dev:lint": [
"@dev:lint:phpstan",
"@dev:lint:style"
],
"dev:lint:phpstan": "./tools/phpstan",
"dev:lint:style": "./tools/phpcs",
"dev:lint:style:fix": "./tools/phpcbf",
"dev:init": [
"@dev:init:check-requirements",
"@dev:init:tools",
"@dev:init:git-hooks"
],
"dev:init:check-requirements": [
"which composer > /dev/null || (echo 'Error: composer has to be globally installed'; exit 1)",
"which phive > /dev/null || (echo 'Error: PHIVE has to be globally installed'; exit 1)"
],
"dev:init:tools": "phive install --temporary",
"dev:init:git-hooks": "./tools/captainhook install --only-enabled --force"
},
"scripts-aliases": {
"test": [
"dev:test"
]
},
"scripts-descriptions": {
"test": "Runs linting, static analysis, and unit tests.",
"dev:phpunit": "Run PHPUnit test suites",
"dev:lint": "Run PHPStan and code style check",
"dev:lint:phpstan": "Run PHPStan",
"dev:lint:style": "Run code style check (PHP_CodeSniffer)",
"dev:lint:style:fix": "Try to fix code style errors automatically",
"dev:init": "Initialize the developer tooling (tools and git hooks)",
"dev:init:check-requirements": "Check if the necessary requirements are met",
"dev:init:tools": "Install all developer tools (requires PHIVE)",
"dev:init:git-hooks": "Install all git hooks (may require tools to be installed)"
} }
],
"support": {
"email": "support@pcsg.de",
"url": "https://www.pcsg.de",
"issues": "https://dev.quiqqer.com/quiqqer/verification/issues",
"source": "https://dev.quiqqer.com/quiqqer/verification"
},
"require": {
"quiqqer/core": "^2"
},
"autoload": {
"psr-4": {
"QUI\\Verification\\": "src/QUI/Verification"
}
}
} }
\ No newline at end of file
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
<database> <database>
<global> <global>
<table name="quiqqer_verification" no-site-reference="1" no-auto-update="1"> <table name="quiqqer_verification_processes" no-site-reference="1" no-auto-update="1">
<field type="BIGINT(20) NOT NULL PRIMARY KEY AUTO_INCREMENT">id</field> <field type="BIGINT(20) NOT NULL PRIMARY KEY AUTO_INCREMENT">id</field>
<field type="VARCHAR(255) NOT NULL">uuid</field>
<field type="VARCHAR(255) NOT NULL">identifier</field> <field type="VARCHAR(255) NOT NULL">identifier</field>
<field type="MEDIUMTEXT NULL">additionalData</field> <field type="VARCHAR(255) NOT NULL">verificationClass</field>
<field type="VARCHAR(255) NOT NULL">verificationHash</field> <field type="MEDIUMTEXT NULL">customData</field>
<field type="TIMESTAMP NULL">createDate</field> <field type="VARCHAR(255) NOT NULL">verificationCode</field>
<field type="TIMESTAMP NULL">validUntilDate</field> <field type="DATETIME NOT NULL">createDate</field>
<field type="VARCHAR(255) NOT NULL">source</field> <field type="DATETIME NOT NULL">updateDate</field>
<field type="TIMESTAMP NULL">verifiedDate</field> <field type="DATETIME NULL DEFAULT NULL">validUntilDate</field>
<field type="TINYINT(1) NOT NULL DEFAULT 0">verified</field> <field type="VARCHAR(255) NOT NULL">verificationHandler</field>
<field type="MEDIUMTEXT NULL">verificationUrl</field> <field type="TINYINT(1) NOT NULL DEFAULT 0">status</field>
</table> </table>
</global> </global>
......
...@@ -130,6 +130,10 @@ ...@@ -130,6 +130,10 @@
<en><![CDATA[The verification link has already been called and is therefore no longer valid.]]></en> <en><![CDATA[The verification link has already been called and is therefore no longer valid.]]></en>
</locale> </locale>
<locale name="PhoneNumberViaSmsVerifier.sms_text">
<de><![CDATA[Der Verifizierungs-Code für deine Telefonnummer lautet: [code]]]></de>
<en><![CDATA[The verification code for your phone number is: [code]]]></en>
</locale>
</groups> </groups>
</locales> </locales>
<?xml version="1.0"?>
<ruleset>
<!-- Use PSR-12 ruleset -->
<rule ref="PSR12"/>
<!-- Only scan *.php files -->
<arg name="extensions" value="php"/>
<!-- Ignore warnings -->
<arg name="warning-severity" value="0"/>
<!-- Process 64 (or number of CPU cores) files in parallel -->
<arg name="parallel" value="64"/>
<!-- Output relative file paths, by setting the current folder as the basepath -->
<arg name="basepath" value="."/>
<!-- Show colored output -->
<arg name="colors"/>
<!-- Scan everything in the current folder -->
<file>.</file>
</ruleset>
parameters:
ignoreErrors:
-
message: "#^Method QUI\\\\Verification\\\\Entity\\\\LinkVerification\\:\\:fromArray\\(\\) should return static\\(QUI\\\\Verification\\\\Entity\\\\LinkVerification\\) but returns QUI\\\\Verification\\\\Entity\\\\LinkVerification\\.$#"
count: 1
path: src/QUI/Verification/Entity/LinkVerification.php
-
message: "#^Call to method asE164\\(\\) on an unknown class QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber\\.$#"
count: 1
path: src/QUI/Verification/Entity/PhoneNumberVerification.php
-
message: "#^Instantiated class QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber not found\\.$#"
count: 1
path: src/QUI/Verification/Entity/PhoneNumberVerification.php
-
message: "#^Method QUI\\\\Verification\\\\Entity\\\\PhoneNumberVerification\\:\\:fromArray\\(\\) should return static\\(QUI\\\\Verification\\\\Entity\\\\PhoneNumberVerification\\) but returns QUI\\\\Verification\\\\Entity\\\\PhoneNumberVerification\\.$#"
count: 1
path: src/QUI/Verification/Entity/PhoneNumberVerification.php
-
message: "#^PHPDoc tag @throws with type DateMalformedStringException\\|libphonenumber\\\\NumberParseException is not subtype of Throwable$#"
count: 1
path: src/QUI/Verification/Entity/PhoneNumberVerification.php
-
message: "#^Parameter \\$phoneNumber of method QUI\\\\Verification\\\\Entity\\\\PhoneNumberVerification\\:\\:__construct\\(\\) has invalid type QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber\\.$#"
count: 2
path: src/QUI/Verification/Entity/PhoneNumberVerification.php
-
message: "#^Property QUI\\\\Verification\\\\Entity\\\\PhoneNumberVerification\\:\\:\\$phoneNumber has unknown class QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber as its type\\.$#"
count: 2
path: src/QUI/Verification/Entity/PhoneNumberVerification.php
-
message: "#^Parameter \\$phoneNumber of method QUI\\\\Verification\\\\Interface\\\\ValidatePhoneNumberStrategyInterface\\:\\:validate\\(\\) has invalid type QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber\\.$#"
count: 1
path: src/QUI/Verification/Interface/ValidatePhoneNumberStrategyInterface.php
-
message: "#^Parameter \\$phoneNumber of method QUI\\\\Verification\\\\Interface\\\\VerificationFactoryInterface\\:\\:createPhoneNumberVerification\\(\\) has invalid type QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber\\.$#"
count: 2
path: src/QUI/Verification/Interface/VerificationFactoryInterface.php
-
message: "#^Call to an undefined method QUI\\\\Interfaces\\\\Projects\\\\Site\\:\\:getUrlRewrittenWithHost\\(\\)\\.$#"
count: 1
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Cannot call method createRandomDigitsCode\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationCodeFactoryInterface\\|null\\.$#"
count: 1
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Cannot call method createRandomHashCode\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationCodeFactoryInterface\\|null\\.$#"
count: 1
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Cannot call method delete\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationRepositoryInterface\\|null\\.$#"
count: 2
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Cannot call method findByIdentifier\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationRepositoryInterface\\|null\\.$#"
count: 2
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Cannot call method insert\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationRepositoryInterface\\|null\\.$#"
count: 2
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Parameter \\$phoneNumber of method QUI\\\\Verification\\\\VerificationFactory\\:\\:createPhoneNumberVerification\\(\\) has invalid type QUI\\\\PhoneApi\\\\Entity\\\\PhoneNumber\\.$#"
count: 2
path: src/QUI/Verification/VerificationFactory.php
-
message: "#^Cannot call method createQueryBuilder\\(\\) on Doctrine\\\\DBAL\\\\Connection\\|null\\.$#"
count: 5
path: src/QUI/Verification/VerificationRepository.php
-
message: "#^Cannot call method transactional\\(\\) on Doctrine\\\\DBAL\\\\Connection\\|null\\.$#"
count: 3
path: src/QUI/Verification/VerificationRepository.php
-
message: "#^Cannot call method getVerificationHandler\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationRepositoryInterface\\|null\\.$#"
count: 1
path: src/QUI/Verification/Verifier.php
-
message: "#^Cannot call method update\\(\\) on QUI\\\\Verification\\\\Interface\\\\VerificationRepositoryInterface\\|null\\.$#"
count: 2
path: src/QUI/Verification/Verifier.php
-
message: "#^Call to method getCurrentPhoneApiClient\\(\\) on an unknown class QUI\\\\PhoneApi\\\\ProviderManager\\.$#"
count: 1
path: src/QUI/Verification/Verifier/AbstractPhoneVerifier.php
-
message: "#^Instantiated class QUI\\\\PhoneApi\\\\ProviderManager not found\\.$#"
count: 1
path: src/QUI/Verification/Verifier/AbstractPhoneVerifier.php
-
message: "#^Parameter \\$phoneApiClient of method QUI\\\\Verification\\\\Verifier\\\\AbstractPhoneVerifier\\:\\:__construct\\(\\) has invalid type QUI\\\\PhoneApi\\\\Interface\\\\PhoneApiClientInterface\\.$#"
count: 2
path: src/QUI/Verification/Verifier/AbstractPhoneVerifier.php
-
message: "#^Property QUI\\\\Verification\\\\Verifier\\\\AbstractPhoneVerifier\\:\\:\\$phoneApiClient has unknown class QUI\\\\PhoneApi\\\\Interface\\\\PhoneApiClientInterface as its type\\.$#"
count: 2
path: src/QUI/Verification/Verifier/AbstractPhoneVerifier.php
-
message: "#^Cannot call method sendSMS\\(\\) on QUI\\\\PhoneApi\\\\Interface\\\\PhoneApiClientInterface\\|null\\.$#"
count: 1
path: src/QUI/Verification/Verifier/PhoneNumberViaSmsPhoneVerifier.php
-
message: "#^Instantiated class QUI\\\\PhoneApi\\\\Entity\\\\SMS not found\\.$#"
count: 1
path: src/QUI/Verification/Verifier/PhoneNumberViaSmsPhoneVerifier.php
-
message: "#^Cannot call method sendCall\\(\\) on QUI\\\\PhoneApi\\\\Interface\\\\PhoneApiClientInterface\\|null\\.$#"
count: 1
path: src/QUI/Verification/Verifier/PhoneNumberViaVoiceCallPhoneVerifier.php
-
message: "#^Instantiated class QUI\\\\PhoneApi\\\\Entity\\\\VoiceCall not found\\.$#"
count: 1
path: src/QUI/Verification/Verifier/PhoneNumberViaVoiceCallPhoneVerifier.php
-
message: "#^Dead catch \\- Exception is never thrown in the try block\\.$#"
count: 1
path: types/verifier.php
-
message: "#^PHPDoc tag @var above a function has no effect\\.$#"
count: 1
path: types/verifier.php
-
message: "#^Parameter \\#1 \\$verification of method QUI\\\\Verification\\\\Interface\\\\LinkVerificationHandlerInterface\\:\\:getErrorMessage\\(\\) expects QUI\\\\Verification\\\\Entity\\\\LinkVerification, QUI\\\\Verification\\\\Entity\\\\AbstractVerification given\\.$#"
count: 1
path: types/verifier.php
-
message: "#^Parameter \\#1 \\$verification of method QUI\\\\Verification\\\\Interface\\\\LinkVerificationHandlerInterface\\:\\:getOnErrorRedirectUrl\\(\\) expects QUI\\\\Verification\\\\Entity\\\\LinkVerification, QUI\\\\Verification\\\\Entity\\\\AbstractVerification given\\.$#"
count: 1
path: types/verifier.php
-
message: "#^Parameter \\#1 \\$verification of method QUI\\\\Verification\\\\Interface\\\\LinkVerificationHandlerInterface\\:\\:getOnSuccessRedirectUrl\\(\\) expects QUI\\\\Verification\\\\Entity\\\\LinkVerification, QUI\\\\Verification\\\\Entity\\\\AbstractVerification given\\.$#"
count: 1
path: types/verifier.php
-
message: "#^Parameter \\#1 \\$verification of method QUI\\\\Verification\\\\Interface\\\\LinkVerificationHandlerInterface\\:\\:getSuccessMessage\\(\\) expects QUI\\\\Verification\\\\Entity\\\\LinkVerification, QUI\\\\Verification\\\\Entity\\\\AbstractVerification given\\.$#"
count: 1
path: types/verifier.php
-
message: "#^Parameter \\#1 \\$verification of method QUI\\\\Verification\\\\Interface\\\\LinkVerificationHandlerInterface\\:\\:onError\\(\\) expects QUI\\\\Verification\\\\Entity\\\\LinkVerification, QUI\\\\Verification\\\\Entity\\\\AbstractVerification given\\.$#"
count: 1
path: types/verifier.php
-
message: "#^Parameter \\#1 \\$verification of method QUI\\\\Verification\\\\Interface\\\\LinkVerificationHandlerInterface\\:\\:onSuccess\\(\\) expects QUI\\\\Verification\\\\Entity\\\\LinkVerification, QUI\\\\Verification\\\\Entity\\\\AbstractVerification given\\.$#"
count: 1
path: types/verifier.php
...@@ -2,7 +2,7 @@ includes: ...@@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon - phpstan-baseline.neon
parameters: parameters:
level: 1 level: 8
paths: paths:
- src - src
- types - types
......
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/phpunit-bootstrap.php">
<testsuites>
<testsuite name="Tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>
<?php
namespace QUI\Verification;
use QUI\Verification\Entity\LinkVerification;
use QUI\Verification\Enum\VerificationErrorReason;
use QUI\Verification\Interface\LinkVerificationHandlerInterface;
use QUI\Verification\Entity\AbstractVerification;
abstract class AbstractLinkVerificationHandler implements LinkVerificationHandlerInterface
{
/**
* Get the duration of a Verification (minutes)
*
* @param AbstractVerification $verification
* @return int|null - duration in minutes;
* on NULL use the module setting default value
*/
public function getValidDuration(AbstractVerification $verification): ?int
{
return null;
}
/**
* Automatically redirect the user to this URL on successful verification
*
* @param LinkVerification $verification
* @return string|null - on NULL, no redirection takes place
*/
public function getOnSuccessRedirectUrl(LinkVerification $verification): ?string
{
return null;
}
/**
* Automatically redirect the user to this URL on unsuccessful verification
*
* @param LinkVerification $verification
* @param VerificationErrorReason $reason
* @return string|null - on NULL, no redirection takes place
*/
public function getOnErrorRedirectUrl(LinkVerification $verification, VerificationErrorReason $reason): ?string
{
return null;
}
}
<?php
namespace QUI\Verification;
abstract class AbstractVerification implements VerificationInterface
{
/**
* Verification identifier
*
* @var string|int
*/
protected string|int $identifier;
/**
* Additional data
*
* @var array
*/
protected array $additionalData = [];
/**
* VerificationInterface constructor.
*
* @param int|string $identifier - Unique identifier
* @param array $additionalData (optional) - Additional data
*/
public function __construct(int|string $identifier, array $additionalData = [])
{
$this->identifier = $identifier;
$this->additionalData = $additionalData;
}
/**
* Get an identifier of this Verification
*
* @return string|int
*/
public function getIdentifier(): int|string
{
return $this->identifier;
}
/**
* Get additional data
*
* @return array
*/
public function getAdditionalData(): array
{
return $this->additionalData;
}
/**
* Get the duration of a Verification (minutes)
*
* @return int|false - duration in minutes;
* if this method returns false use the module setting default value
*/
public function getValidDuration(): bool|int
{
return false;
}
/**
* Execute this method on successful verification
*
* @return void
*/
abstract public function onSuccess(): void;
/**
* Execute this method on unsuccessful verification
*
* @return void
*/
abstract public function onError(): void;
/**
* This message is displayed to the user on successful verification
*
* @return string
*/
abstract 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_)
* @return string
*/
abstract 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
*/
public function getOnSuccessRedirectUrl(): bool|string
{
return false;
}
/**
* Automatically redirect the user to this URL on unsuccessful verification
*
* @return string|false - If this method returns false, no redirection takes place
*/
public function getOnErrorRedirectUrl(): bool|string
{
return false;
}
/**
* Get type (class name)
*
* @return string
*/
public static function getType(): string
{
return get_called_class();
}
}
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
namespace QUI\Verification; namespace QUI\Verification;
use QUI; use QUI;
use QUI\Verification\Enum\VerificationStatus;
use function time;
/** /**
* Class Cron * Class Cron
...@@ -16,49 +19,56 @@ class Cron ...@@ -16,49 +19,56 @@ class Cron
* that have been verified a certain amount of days before now * that have been verified a certain amount of days before now
* *
* @return void * @return void
* @throws \QUI\Exception
*/ */
public static function deleteVerified(): void public static function deleteVerified(): void
{ {
$result = QUI::getDataBase()->fetch([ $repository = new VerificationRepository();
'select' => [
'id', try {
'verifiedDate' $deletionCandidates = $repository->findAllByStatus(VerificationStatus::VERIFIED);
], } catch (\Throwable $exception) {
'from' => Verifier::getDatabaseTable(), if ($exception instanceof \Exception) {
'where' => [ QUI\System\Log::writeException($exception);
'verified' => 1 }
] return;
]); }
$deleteIds = []; $deleteVerifications = [];
$Conf = QUI::getPackage('quiqqer/verification')->getConfig();
try {
$Conf = QUI::getPackage('quiqqer/verification')->getConfig();
} catch (\Exception $exception) {
QUI\System\Log::writeException($exception);
return;
}
if (is_null($Conf)) {
QUI\System\Log::addError("quiqqer/verification cron :: Cannot load Config for quiqqer/verification.");
return;
}
$verifiedTtl = (int)$Conf->get('settings', 'keepVerifiedDuration'); // days $verifiedTtl = (int)$Conf->get('settings', 'keepVerifiedDuration'); // days
$verifiedTtl *= 24 * 60 * 60; // seconds $verifiedTtl *= 24 * 60 * 60; // seconds
$now = time(); $now = time();
foreach ($result as $row) { foreach ($deletionCandidates as $verification) {
$verifiedTime = strtotime($row['verifiedDate']); $verifiedTime = $verification->updateDate->getTimestamp();
$aliveTime = $now - $verifiedTime; $aliveTime = $now - $verifiedTime;
if ($aliveTime > $verifiedTtl) { if ($aliveTime > $verifiedTtl) {
$deleteIds[] = $row['id']; $deleteVerifications[] = $verification;
} }
} }
if (empty($deleteIds)) { foreach ($deleteVerifications as $verification) {
return; try {
$repository->delete($verification);
} catch (\Throwable $exception) {
if ($exception instanceof \Exception) {
QUI\System\Log::writeException($exception);
}
}
} }
QUI::getDataBase()->delete(
Verifier::getDatabaseTable(),
[
'id' => [
'type' => 'IN',
'value' => $deleteIds
]
]
);
} }
/** /**
...@@ -66,50 +76,41 @@ public static function deleteVerified(): void ...@@ -66,50 +76,41 @@ public static function deleteVerified(): void
* that have exceeded their "valid until" date * that have exceeded their "valid until" date
* *
* @return void * @return void
* @throws \QUI\Exception
*/ */
public static function deleteUnverified(): void public static function deleteUnverified(): void
{ {
$result = QUI::getDataBase()->fetch([ $repository = new VerificationRepository();
'select' => [
'id',
'identifier'
],
'from' => Verifier::getDatabaseTable(),
'where' => [
'verified' => 0,
'validUntilDate' => [
'type' => '<=',
'value' => date('Y-m-d H:i:s')
]
]
]);
$deleteIds = [];
foreach ($result as $row) {
$deleteIds[] = $row['id'];
QUI::getEvents()->fireEvent(
'quiqqerVerificationDeleteUnverified',
[
Verifier::getIdentifierFromUniqueIdentifier($row['identifier'])
]
);
}
if (empty($deleteIds)) { try {
$unverified = $repository->findAllUnverifiedAndInvalid();
} catch (\Throwable $exception) {
if ($exception instanceof \Exception) {
QUI\System\Log::writeException($exception);
}
return; return;
} }
QUI::getDataBase()->delete(
Verifier::getDatabaseTable(), foreach ($unverified as $verification) {
[ try {
'id' => [ QUI::getEvents()->fireEvent(
'type' => 'IN', 'quiqqerVerificationDeleteUnverified',
'value' => $deleteIds [
] $verification
] ]
); );
} catch (\Exception $exception) {
QUI\System\Log::writeDebugException($exception);
continue;
}
try {
$repository->delete($verification);
} catch (\Throwable $exception) {
if ($exception instanceof \Exception) {
QUI\System\Log::writeException($exception);
}
}
}
} }
} }
<?php
namespace QUI\Verification\Entity;
use DateTimeImmutable;
use QUI\Verification\Enum\VerificationStatus;
abstract class AbstractVerification
{
/**
* @param string $uuid
* @param string $identifier
* @param string $verificationCode
* @param DateTimeImmutable $createDate
* @param DateTimeImmutable $updateDate
* @param VerificationStatus $status
* @param array<string|int,mixed> $customData
* @param DateTimeImmutable|null $validUntilDate
*/
public function __construct(
public readonly string $uuid,
public readonly string $identifier,
public readonly string $verificationCode,
public readonly DateTimeImmutable $createDate,
public readonly DateTimeImmutable $updateDate,
public VerificationStatus $status = VerificationStatus::PENDING,
public array $customData = [],
public ?DateTimeImmutable $validUntilDate = null
) {
}
/**
* @return array<string|int,mixed>
*/
public function getCustomData(): array
{
return $this->customData;
}
/**
* @param string $key
* @return mixed|null
*/
public function getCustomDataEntry(string $key): mixed
{
return $this->customData[$key] ?? null;
}
public function isValid(): bool
{
if (is_null($this->validUntilDate)) {
return true;
}
return $this->validUntilDate > new DateTimeImmutable();
}
/**
* @param array<string,mixed> $data
* @return static
*/
abstract public static function fromArray(array $data): static;
/**
* Get type (class name)
*
* @return string
*/
public static function getType(): string
{
return get_called_class();
}
}
<?php
namespace QUI\Verification\Entity;
use DateTimeImmutable;
use QUI\Verification\Enum\VerificationStatus;
class LinkVerification extends AbstractVerification
{
/**
* @param string $uuid
* @param string $identifier
* @param string $verificationCode
* @param DateTimeImmutable $createDate
* @param DateTimeImmutable $updateDate
* @param string $verificationUrl
* @param VerificationStatus $status
* @param array<string|int,mixed> $customData
* @param DateTimeImmutable|null $validUntilDate
*/
public function __construct(
string $uuid,
string $identifier,
string $verificationCode,
DateTimeImmutable $createDate,
DateTimeImmutable $updateDate,
string $verificationUrl,
VerificationStatus $status = VerificationStatus::PENDING,
array $customData = [],
?DateTimeImmutable $validUntilDate = null
) {
$customData['verificationUrl'] = $verificationUrl;
parent::__construct(
$uuid,
$identifier,
$verificationCode,
$createDate,
$updateDate,
$status,
$customData,
$validUntilDate
);
}
/**
* @param array<string,mixed> $data
* @return static
* @throws \DateMalformedStringException
*/
public static function fromArray(array $data): static
{
return new LinkVerification(
$data['uuid'],
$data['identifier'],
$data['verificationCode'],
new DateTimeImmutable($data['createDate']),
new DateTimeImmutable($data['updateDate']),
$data['customData']['verificationUrl'],
VerificationStatus::from($data['status']),
$data['customData'],
!empty($data['validUntilDate']) ? new DateTimeImmutable($data['validUntilDate']) : null
);
}
public function getVerificationUrl(): string
{
return $this->getCustomDataEntry('verificationUrl');
}
}
<?php
namespace QUI\Verification\Entity;
use DateTimeImmutable;
use QUI\PhoneApi\Entity\PhoneNumber;
use QUI\Verification\Enum\PhoneNumberVerificationStrategy;
use QUI\Verification\Enum\VerificationStatus;
class PhoneNumberVerification extends AbstractVerification
{
/**
* @param string $uuid
* @param string $identifier
* @param string $verificationCode
* @param DateTimeImmutable $createDate
* @param DateTimeImmutable $updateDate
* @param PhoneNumber $phoneNumber
* @param PhoneNumberVerificationStrategy $strategy
* @param VerificationStatus $status
* @param array<string|int,mixed> $customData
* @param DateTimeImmutable|null $validUntilDate
*/
public function __construct(
string $uuid,
string $identifier,
string $verificationCode,
DateTimeImmutable $createDate,
DateTimeImmutable $updateDate,
public readonly PhoneNumber $phoneNumber,
PhoneNumberVerificationStrategy $strategy,
VerificationStatus $status = VerificationStatus::PENDING,
array $customData = [],
?DateTimeImmutable $validUntilDate = null
) {
$customData['phoneNumber'] = $phoneNumber->asE164();
$customData['strategy'] = $strategy::class;
parent::__construct(
$uuid,
$identifier,
$verificationCode,
$createDate,
$updateDate,
$status,
$customData,
$validUntilDate
);
}
/**
* @param array<string,mixed> $data
* @return static
*
* @throws \DateMalformedStringException
* @throws \libphonenumber\NumberParseException
*/
public static function fromArray(array $data): static
{
return new PhoneNumberVerification(
$data['uuid'],
$data['identifier'],
$data['verificationCode'],
new DateTimeImmutable($data['createDate']),
new DateTimeImmutable($data['updateDate']),
new PhoneNumber($data['phoneNumber']),
PhoneNumberVerificationStrategy::from($data['strategy']),
VerificationStatus::from($data['status']),
$data['customData'],
!empty($data['validUntilDate']) ? new DateTimeImmutable($data['validUntilDate']) : null
);
}
}
<?php
namespace QUI\Verification\Enum;
enum PhoneNumberVerificationStrategy: string
{
case SMS = 'sms';
case CALL = 'call';
}
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren