diff --git a/website/app-templates/smarty/blocks/user_finder_list.tpl b/website/app-templates/smarty/blocks/user_finder_list.tpl index 9d7bd9a40c..08a2a35038 100644 --- a/website/app-templates/smarty/blocks/user_finder_list.tpl +++ b/website/app-templates/smarty/blocks/user_finder_list.tpl @@ -13,6 +13,7 @@ Join date Last login Email valid + Status Actions @@ -25,6 +26,7 @@ {if !is_null($user->joined_on_datetime)}{$user->joined_on_datetime|print_date nofilter}{/if} {if !is_null($user->last_login_datetime)}{$user->last_login_datetime|print_date nofilter}{/if} {if $user->email_invalid}{t}false{/t}{else}{t}true{/t}{/if} + {$user->status_text()} {block user_actions}{/block} 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/GeoKrety/Model/User.php b/website/app/GeoKrety/Model/User.php index 5f8da040cb..897f33d5ab 100644 --- a/website/app/GeoKrety/Model/User.php +++ b/website/app/GeoKrety/Model/User.php @@ -48,6 +48,12 @@ class User extends Base implements \JsonSerializable { public const USER_ACCOUNT_VALID = 1; public const USER_ACCOUNT_IMPORTED = 2; + public const ACCOUNT_STATUS_TEXT = [ + self::USER_ACCOUNT_INVALID => 'Non-Activated', + self::USER_ACCOUNT_VALID => 'Fully activated', + self::USER_ACCOUNT_IMPORTED => 'Imported', + ]; + public const USER_ACCOUNT_STATUS_INVALID = [ self::USER_ACCOUNT_INVALID, self::USER_ACCOUNT_IMPORTED, @@ -303,6 +309,10 @@ public function isAccountImported(): bool { return $this->account_valid === self::USER_ACCOUNT_IMPORTED; } + public function status_text(): string { + return self::ACCOUNT_STATUS_TEXT[$this->account_valid]; + } + public function hasEmail(): bool { return !is_null($this->_email_hash); } 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);