From 5360715e7cfbd73b7d985f2729839cec743bddb4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 13:04:57 +0000 Subject: [PATCH 1/6] Initial plan From 6c5619cddbbf171d574daf2a44c017c51671e688 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 13:13:40 +0000 Subject: [PATCH 2/6] Initial exploration complete Co-authored-by: alxndr-w <3855487+alxndr-w@users.noreply.github.com> --- vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ | 1 + 1 file changed, 1 insertion(+) create mode 100644 vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ diff --git a/vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ b/vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ new file mode 100644 index 00000000..fc202978 --- /dev/null +++ b/vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ @@ -0,0 +1 @@ +Blocked by DNS monitoring proxy \ No newline at end of file From 879851943a28af1464ba36e060ca88b22c540510 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 13:16:22 +0000 Subject: [PATCH 3/6] Add status constants, getStatusOptions method, and update JSON to use callable Co-authored-by: alxndr-w <3855487+alxndr-w@users.noreply.github.com> --- .gitignore | 1 + install/tablesets/yform_user.json | 2 +- lib/ycom_user.php | 35 ++++++++++++++++++- .../tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ | 1 - 4 files changed, 36 insertions(+), 3 deletions(-) delete mode 100644 vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ diff --git a/.gitignore b/.gitignore index 8cacf425..7626638e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .phpunit.result.cache .php-cs-fixer.cache +vendor/composer/*.zip~ diff --git a/install/tablesets/yform_user.json b/install/tablesets/yform_user.json index f9efdc66..8eeb015e 100644 --- a/install/tablesets/yform_user.json +++ b/install/tablesets/yform_user.json @@ -177,7 +177,7 @@ "attributes": "", "choice_attributes": "", "choice_label": "", - "choices": "translate:ycom_account_inactive_termination=-3,translate:ycom_account_inactive_logins=-2,translate:ycom_account_inactive=-1,translate:ycom_account_requested=0,translate:ycom_account_confirm=1,translate:ycom_account_active=2", + "choices": "callable::rex_ycom_user::getStatusOptions", "db_type": "text", "default": "-1", "expanded": "", diff --git a/lib/ycom_user.php b/lib/ycom_user.php index ae2100c9..0c60290f 100644 --- a/lib/ycom_user.php +++ b/lib/ycom_user.php @@ -5,6 +5,24 @@ class rex_ycom_user extends rex_yform_manager_dataset public string $password = ''; public int $login_tries = 0; + // Status constants + public const STATUS_INACTIVE_TERMINATION = -3; + public const STATUS_INACTIVE_LOGINS = -2; + public const STATUS_INACTIVE = -1; + public const STATUS_REQUESTED = 0; + public const STATUS_CONFIRMED = 1; + public const STATUS_ACTIVE = 2; + + // Default status options + public const DEFAULT_STATUS_OPTIONS = [ + self::STATUS_INACTIVE_TERMINATION => 'translate:ycom_account_inactive_termination', + self::STATUS_INACTIVE_LOGINS => 'translate:ycom_account_inactive_logins', + self::STATUS_INACTIVE => 'translate:ycom_account_inactive', + self::STATUS_REQUESTED => 'translate:ycom_account_requested', + self::STATUS_CONFIRMED => 'translate:ycom_account_confirm', + self::STATUS_ACTIVE => 'translate:ycom_account_active', + ]; + /** * @return rex_ycom_user|null */ @@ -53,7 +71,7 @@ public function getGroups(): array */ public static function createUserByEmail(array $data) { - $data['status'] = 1; + $data['status'] = self::STATUS_CONFIRMED; $data['password'] = str_shuffle('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'); $data['login'] = $data['email']; $data['login_tries'] = 0; @@ -111,4 +129,19 @@ public function resetOTPTries(): self $this->setValue('otp_last_try_time', time()); return $this; } + + /** + * Get status options with extension point for customization. + * + * @return array + */ + public static function getStatusOptions(): array + { + // Allow additional status options via extension point + $statusOptions = rex_extension::registerPoint(new rex_extension_point('YCOM_USER_STATUS_OPTIONS', self::DEFAULT_STATUS_OPTIONS)); + if (!is_array($statusOptions)) { + $statusOptions = self::DEFAULT_STATUS_OPTIONS; + } + return $statusOptions; + } } diff --git a/vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ b/vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ deleted file mode 100644 index fc202978..00000000 --- a/vendor/composer/tmp-3a02bfb0cbd4ab100b8d2cc816fb42bc.zip~ +++ /dev/null @@ -1 +0,0 @@ -Blocked by DNS monitoring proxy \ No newline at end of file From d653dc454d4d4fd9a25070e80b610bfad690fd56 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 13:19:31 +0000 Subject: [PATCH 4/6] Add documentation for status constants and extension point, add unit tests Co-authored-by: alxndr-w <3855487+alxndr-w@users.noreply.github.com> --- docs/03_login_logout_profile_register.md | 10 ++++ docs/05_passwords.md | 47 ++++++++++++++--- tests/unit/user_status_test.php | 65 ++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 tests/unit/user_status_test.php diff --git a/docs/03_login_logout_profile_register.md b/docs/03_login_logout_profile_register.md index 8ed6eabb..16bace05 100644 --- a/docs/03_login_logout_profile_register.md +++ b/docs/03_login_logout_profile_register.md @@ -120,6 +120,16 @@ action|ycom_auth_db ## Registrierung +> **Hinweis zu Status-Werten:** Die Status-Werte sind als Konstanten in der Klasse `rex_ycom_user` definiert. Während in YForm-Formularen die numerischen Werte verwendet werden (z.B. `hidden|status|0`), kann im PHP-Code auf die entsprechenden Konstanten zurückgegriffen werden: +> - `STATUS_INACTIVE_TERMINATION = -3` +> - `STATUS_INACTIVE_LOGINS = -2` +> - `STATUS_INACTIVE = -1` +> - `STATUS_REQUESTED = 0` +> - `STATUS_CONFIRMED = 1` +> - `STATUS_ACTIVE = 2` +> +> Siehe auch die [Status-Liste](05_passwords.md#status-liste-eines-ycom-accounts) für weitere Details. + ### Registrierungs-Formular ```php diff --git a/docs/05_passwords.md b/docs/05_passwords.md index 780b7243..d2602b4d 100644 --- a/docs/05_passwords.md +++ b/docs/05_passwords.md @@ -120,14 +120,45 @@ Der Status kann hier auch 2 sein (`status=2`), wenn man mit selbst angelegten Ac #### Status Liste eines YCom-Accounts -Interner Name | Übersetzung | Wert ------- | ------ | ------ -ycom_account_inactive_termination | Zugang wurde gekündigt | -3 -ycom_account_inactive_logins | Zugang wurde deaktiviert [Loginfehlversuche] | -2 -ycom_account_inactive | Zugang ist inaktiv | -1 -ycom_account_requested | Zugang wurde angefragt | 0 -ycom_account_confirm | Zugang wurde bestätigt und ist aktiv | 1 -ycom_account_active | Zugang ist aktiv | 2 +Interner Name | Übersetzung | Wert | Konstante +------ | ------ | ------ | ------ +ycom_account_inactive_termination | Zugang wurde gekündigt | -3 | `rex_ycom_user::STATUS_INACTIVE_TERMINATION` +ycom_account_inactive_logins | Zugang wurde deaktiviert [Loginfehlversuche] | -2 | `rex_ycom_user::STATUS_INACTIVE_LOGINS` +ycom_account_inactive | Zugang ist inaktiv | -1 | `rex_ycom_user::STATUS_INACTIVE` +ycom_account_requested | Zugang wurde angefragt | 0 | `rex_ycom_user::STATUS_REQUESTED` +ycom_account_confirm | Zugang wurde bestätigt und ist aktiv | 1 | `rex_ycom_user::STATUS_CONFIRMED` +ycom_account_active | Zugang ist aktiv | 2 | `rex_ycom_user::STATUS_ACTIVE` + +##### Status-Konstanten + +Seit Version X.X werden die Status-Werte als Konstanten in der Klasse `rex_ycom_user` definiert. Diese können im Code verwendet werden, um die Lesbarkeit zu erhöhen: + +```php +// Statt: +$data['status'] = 1; + +// Verwende: +$data['status'] = rex_ycom_user::STATUS_CONFIRMED; +``` + +##### Status-Optionen erweitern + +Die Status-Optionen können über den Extension Point `YCOM_USER_STATUS_OPTIONS` erweitert oder angepasst werden: + +```php +rex_extension::register('YCOM_USER_STATUS_OPTIONS', function (rex_extension_point $ep) { + /** @var array $statusOptions */ + $statusOptions = $ep->getSubject(); + + // Eigenen Status hinzufügen + $statusOptions[3] = 'translate:ycom_account_premium'; + + // Optional: Sortierung anpassen + ksort($statusOptions); + + return $statusOptions; +}); +``` #### Weitere Hinweise diff --git a/tests/unit/user_status_test.php b/tests/unit/user_status_test.php new file mode 100644 index 00000000..55757d45 --- /dev/null +++ b/tests/unit/user_status_test.php @@ -0,0 +1,65 @@ + Date: Tue, 14 Oct 2025 13:22:15 +0000 Subject: [PATCH 5/6] Add comprehensive examples documentation for status constants and extension point Co-authored-by: alxndr-w <3855487+alxndr-w@users.noreply.github.com> --- docs/12_status_examples.md | 104 +++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 docs/12_status_examples.md diff --git a/docs/12_status_examples.md b/docs/12_status_examples.md new file mode 100644 index 00000000..0f5d4381 --- /dev/null +++ b/docs/12_status_examples.md @@ -0,0 +1,104 @@ +# YCom User Status - Beispiele + +## Status-Konstanten verwenden + +### Im PHP-Code + +```php +setValue('email', 'test@example.com'); +$user->setValue('login', 'test@example.com'); +$user->setValue('status', rex_ycom_user::STATUS_CONFIRMED); +$user->save(); + +// Status prüfen +$currentUser = rex_ycom_user::getMe(); +if ($currentUser && $currentUser->getValue('status') >= rex_ycom_user::STATUS_CONFIRMED) { + // User ist eingeloggt und bestätigt +} + +// Status auf inaktiv setzen +$user->setValue('status', rex_ycom_user::STATUS_INACTIVE); +$user->save(); +``` + +## Status-Optionen erweitern via Extension Point + +### Beispiel 1: Eigenen Status hinzufügen + +```php + $statusOptions */ + $statusOptions = $ep->getSubject(); + + // Premium-Status hinzufügen (Wert 3) + $statusOptions[3] = 'translate:ycom_account_premium'; + + // VIP-Status hinzufügen (Wert 4) + $statusOptions[4] = 'translate:ycom_account_vip'; + + return $statusOptions; +}); +``` + +### Beispiel 2: Status-Optionen anpassen und sortieren + +```php + $statusOptions */ + $statusOptions = $ep->getSubject(); + + // Bestimmte Stati entfernen (optional) + unset($statusOptions[rex_ycom_user::STATUS_INACTIVE_TERMINATION]); + + // Eigene Stati hinzufügen + $statusOptions[10] = 'translate:ycom_account_special'; + + // Nach Schlüssel sortieren + ksort($statusOptions); + + return $statusOptions; +}); +``` + +### Beispiel 3: Status-Labels projektspezifisch anpassen + +```php + $statusOptions */ + $statusOptions = $ep->getSubject(); + + // Standard-Labels durch eigene ersetzen + $statusOptions[rex_ycom_user::STATUS_ACTIVE] = 'Aktives Mitglied'; + $statusOptions[rex_ycom_user::STATUS_CONFIRMED] = 'Bestätigtes Mitglied'; + $statusOptions[rex_ycom_user::STATUS_REQUESTED] = 'Registrierung ausstehend'; + + return $statusOptions; +}); +``` + +## Verfügbare Status-Konstanten + +| Konstante | Wert | Standard-Label | +|-----------|------|----------------| +| `rex_ycom_user::STATUS_INACTIVE_TERMINATION` | -3 | Zugang wurde gekündigt | +| `rex_ycom_user::STATUS_INACTIVE_LOGINS` | -2 | Zugang wurde deaktiviert [Loginfehlversuche] | +| `rex_ycom_user::STATUS_INACTIVE` | -1 | Zugang ist inaktiv | +| `rex_ycom_user::STATUS_REQUESTED` | 0 | Zugang wurde angefragt | +| `rex_ycom_user::STATUS_CONFIRMED` | 1 | Zugang wurde bestätigt und ist aktiv | +| `rex_ycom_user::STATUS_ACTIVE` | 2 | Zugang ist aktiv | + +## Status-Logik + +- **Login erlaubt**: Status >= 1 (STATUS_CONFIRMED oder höher) +- **Login nicht erlaubt**: Status <= -1 (STATUS_INACTIVE oder niedriger) +- **Registriert, aber Nutzungsbedingungen fehlen**: Status = 0 (STATUS_REQUESTED) From da55cdf332a2856a40920dff9daa01db3c02e69a Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Tue, 14 Oct 2025 16:24:40 +0200 Subject: [PATCH 6/6] Update lib/ycom_user.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- lib/ycom_user.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ycom_user.php b/lib/ycom_user.php index 0c60290f..15c194dc 100644 --- a/lib/ycom_user.php +++ b/lib/ycom_user.php @@ -132,7 +132,6 @@ public function resetOTPTries(): self /** * Get status options with extension point for customization. - * * @return array */ public static function getStatusOptions(): array