v1.0.0.8
Publisium
- <?php
-
- declare(strict_types=1);
-
- $action = $_POST['action'] ?? '';
- $reader = UserAuth::user();
-
- if ($action === 'update_profile') {
- $displayName = trim((string) ($_POST['display_name'] ?? ''));
- $newPassword = (string) ($_POST['new_password'] ?? '');
-
- $params = ['display_name' => $displayName !== '' ? $displayName : $reader['display_name'], 'id' => $reader['id']];
-
- if ($newPassword !== '') {
- if (strlen($newPassword) < 8) {
- return Language::get('account_password_too_short', 'Your new password needs at least 8 characters.');
- }
- $newHash = password_hash($newPassword, PASSWORD_DEFAULT);
- $statement = Database::users()->prepare(
- 'UPDATE user_accounts SET display_name = :display_name, password_hash = :hash WHERE id = :id'
- );
- $statement->execute($params + ['hash' => $newHash]);
- UserAuth::passwordChanged((int) $reader['id'], $newHash);
- } else {
- $statement = Database::users()->prepare(
- 'UPDATE user_accounts SET display_name = :display_name WHERE id = :id'
- );
- $statement->execute($params);
- }
-
- return Language::get('account_profile_saved', 'Your profile is saved.');
- }
-
- if ($action === 'update_consents' && SiteFront::settings()['account_consents_enabled'] === '1') {
- $consentTypes = ['analytics', 'ads_personalization'];
- $db = Database::users();
-
- foreach ($consentTypes as $type) {
- $granted = isset($_POST['consent_' . $type]) ? 1 : 0;
-
- $existingStatement = $db->prepare(
- 'SELECT id FROM user_consents WHERE user_account_id = :user_id AND consent_type = :type ORDER BY id DESC LIMIT 1'
- );
- $existingStatement->execute(['user_id' => $reader['id'], 'type' => $type]);
- $existing = $existingStatement->fetch();
-
- if ($existing) {
- $statement = $db->prepare(
- 'UPDATE user_consents SET is_granted = :granted, granted_at = IF(:granted_check = 1, NOW(), granted_at), revoked_at = IF(:granted_check2 = 0, NOW(), NULL) WHERE id = :id'
- );
- $statement->execute(['granted' => $granted, 'granted_check' => $granted, 'granted_check2' => $granted, 'id' => $existing['id']]);
- } else {
- $statement = $db->prepare(
- 'INSERT INTO user_consents (user_account_id, consent_type, is_granted, granted_at) VALUES (:user_id, :type, :granted, IF(:granted_check = 1, NOW(), NULL))'
- );
- $statement->execute(['user_id' => $reader['id'], 'type' => $type, 'granted' => $granted, 'granted_check' => $granted]);
- }
- }
-
- return Language::get('account_preferences_saved', 'Your choices are saved.');
- }
-
- return null;
-