diff --git a/website/app/GeoKrety/Controller/Pages/UserEmailRevalidateToken.php b/website/app/GeoKrety/Controller/Pages/UserEmailRevalidateToken.php index 1e076c8a5d..aadee82ff1 100644 --- a/website/app/GeoKrety/Controller/Pages/UserEmailRevalidateToken.php +++ b/website/app/GeoKrety/Controller/Pages/UserEmailRevalidateToken.php @@ -4,6 +4,7 @@ use GeoKrety\Model\EmailRevalidateToken; use GeoKrety\Service\Smarty; +use Sugar\Event; class UserEmailRevalidateToken extends Base { public function get(\Base $f3) { @@ -31,9 +32,11 @@ public function get(\Base $f3) { $token->used = EmailRevalidateToken::TOKEN_VALIDATED; $token->save(); \Flash::instance()->addMessage(_('You have successfully validated your email address.'), 'success'); + Event::instance()->emit('email-revalidation.token.used', $token); $f3->reroute(sprintf('@user_details(@userid=%d)', $token->user->id)); } \Flash::instance()->addMessage(_('Sorry this token is not valid, already used or expired.'), 'danger'); + Event::instance()->emit('email-revalidation.token.error', $token); $token->token = $_token; } diff --git a/website/app/GeoKrety/Model/EmailActivationToken.php b/website/app/GeoKrety/Model/EmailActivationToken.php index d4645c7560..761d747b47 100644 --- a/website/app/GeoKrety/Model/EmailActivationToken.php +++ b/website/app/GeoKrety/Model/EmailActivationToken.php @@ -4,6 +4,7 @@ use DateTime; use DB\SQL\Schema; +use Sugar\Event; /** * @property int|null id @@ -259,6 +260,10 @@ public function __construct() { // $this->beforeupdate(function ($self) { // }); + $this->afterinsert(function ($self) { + Event::instance()->emit('email.token.generated', $self); + }); + $this->virtual('update_expire_on_datetime', function ($self): \DateTime { $expire = $self->created_on_datetime ? clone $self->created_on_datetime : new \DateTime(); diff --git a/website/app/GeoKrety/Model/EmailRevalidateToken.php b/website/app/GeoKrety/Model/EmailRevalidateToken.php index 4c22c24e2b..7015c2472f 100644 --- a/website/app/GeoKrety/Model/EmailRevalidateToken.php +++ b/website/app/GeoKrety/Model/EmailRevalidateToken.php @@ -4,6 +4,7 @@ use DB\SQL\Schema; use GeoKrety\Model\Traits\EmailField; +use Sugar\Event; /** * @property string token @@ -113,6 +114,10 @@ public function __construct() { } }); + $this->afterinsert(function ($self) { + Event::instance()->emit('email-revalidation.token.generated', $self); + }); + $this->virtual('validate_expire_on_datetime', function ($self): \DateTime { $expire = $self->created_on_datetime ? clone $self->created_on_datetime : new \DateTime(); diff --git a/website/app/events.php b/website/app/events.php index 23e3ee72a5..ba6e17fcc4 100644 --- a/website/app/events.php +++ b/website/app/events.php @@ -224,11 +224,23 @@ function audit(string $event, $newObjectModel) { }); $events->on('email.token.generated', function (GeoKrety\Model\EmailActivationToken $token) { audit('email.token.generated', $token); - Metrics::counter('email_validation_token_created_total', 'Total number of email validation token created'); + Metrics::counter('email_validation_token_total', 'Total number of email validation token created', ['verb'], ['created']); }); $events->on('email.token.used', function (GeoKrety\Model\EmailActivationToken $token) { audit('email.token.used', $token); - Metrics::counter('email_validation_token_used_total', 'Total number of email validation token used'); + Metrics::counter('email_validation_token_total', 'Total number of email validation token used', ['verb'], ['used']); +}); +$events->on('email-revalidation.token.generated', function (GeoKrety\Model\EmailRevalidateToken $token) { + audit('email-revalidation.token.generated', $token); + Metrics::counter('email_revalidation_token_total', 'Total number of email re-validation token created', ['verb'], ['generated']); +}); +$events->on('email-revalidation.token.used', function (GeoKrety\Model\EmailRevalidateToken $token) { + audit('email-revalidation.token.used', $token); + Metrics::counter('email_revalidation_token_total', 'Total number of email re-validation token used', ['verb'], ['used']); +}); +$events->on('email-revalidation.token.error', function (GeoKrety\Model\EmailRevalidateToken $token) { + audit('email-revalidation.token.error', $token); + Metrics::counter('email_revalidation_token_total', 'Total number of email re-validation token error', ['verb'], ['error']); }); $events->on('user.secid.changed', function (GeoKrety\Model\User $user) { audit('user.secid.changed', $user);