user_pref_language users field value changed to enum. user_phone_number optional.

This commit is contained in:
2026-06-12 23:32:50 +02:00
parent aece25439b
commit d6079878c4
2 changed files with 20 additions and 18 deletions

View File

@@ -20,28 +20,28 @@ if ($API_users->request_method === 'GET') {
'user_email' => ['type' => 'email'], 'user_email' => ['type' => 'email'],
'user_first_name' => ['type' => 'string'], 'user_first_name' => ['type' => 'string'],
'user_last_name' => ['type' => 'string'], 'user_last_name' => ['type' => 'string'],
'user_full_name' => ['type' => 'string'], 'user_full_name' => ['type' => 'string'], # Does not need to be posted, set later
'user_phone_number' => ['type' => 'string'], 'user_status' => ['type' => 'enum', 'values' => ['inactive', 'banned', 'pending']],
'user_status' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned', 'pending']], 'user_password' => ['type' => 'string'], # Does not need to be posted, set later
'user_password' => ['type' => 'string'], 'user_pref_language' => ['type' => 'enum', 'values' => ['en', 'nl']],
'user_pref_language' => ['type' => 'string'], 'user_password_reset_token' => ['type' => 'string'], # Does not need to be posted, set later
'user_password_reset_token' => ['type' => 'string'], 'user_password_reset_expires' => ['type' => 'int'], # Does not need to be posted, set later
'user_password_reset_expires' => ['type' => 'int'],
]; ];
# The user will need to verify their email, the password field cannot be NULL so set an random password for now till the user resets it on when verifing there email $optionalFields = [
'user_phone_number' => ['type' => 'string']
];
# The user will need to verify their email, the password field cannot be NULL so set a random password for now till the user resets it on when verifying there email
$random_string = substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01', 64)), 0, rand(50, 64)); $random_string = substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01', 64)), 0, rand(50, 64));
$user_password = password_hash($random_string, PASSWORD_BCRYPT, ["cost" => 12]); $user_password = password_hash($random_string, PASSWORD_BCRYPT, ["cost" => 12]);
$API_users->postedData['user_password'] = $user_password; $API_users->postedData['user_password'] = $user_password;
$API_users->postedData['user_full_name'] = trim($_POST['user_first_name'] . ' ' . $_POST['user_last_name']); # Password reset token that will be sent to the newly created user
$API_users->postedData['user_pref_language'] = $_POST['user_pref_language'] ?? 'en';
# Password reset token that will be send to the newly created user
$API_users->postedData['user_password_reset_token'] = bin2hex(random_bytes(32)); $API_users->postedData['user_password_reset_token'] = bin2hex(random_bytes(32));
$API_users->postedData['user_password_reset_expires'] = time() + 86400; $API_users->postedData['user_password_reset_expires'] = time() + 86400;
$API_users->validateData($requiredFields); $API_users->validateData($requiredFields, $optionalFields);
$API_users->createUser(); $API_users->createUser();
} elseif ($API_users->request_method === 'PUT') { } elseif ($API_users->request_method === 'PUT') {
@@ -56,9 +56,12 @@ if ($API_users->request_method === 'GET') {
'user_first_name' => ['type' => 'string'], 'user_first_name' => ['type' => 'string'],
'user_last_name' => ['type' => 'string'], 'user_last_name' => ['type' => 'string'],
'user_full_name' => ['type' => 'string'], 'user_full_name' => ['type' => 'string'],
'user_phone_number' => ['type' => 'string'],
'user_status' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned', 'pending']], 'user_status' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned', 'pending']],
'user_pref_language' => ['type' => 'string'], 'user_pref_language' => ['type' => 'enum', 'values' => ['en', 'nl']],
];
$optionalFields = [
'user_phone_number' => ['type' => 'string'],
'user_stompable' => ['type' => 'boolean'] 'user_stompable' => ['type' => 'boolean']
]; ];
@@ -66,9 +69,7 @@ if ($API_users->request_method === 'GET') {
$API_users->postedData['user_pref_language'] = $_POST['user_pref_language'] ?? 'en'; $API_users->postedData['user_pref_language'] = $_POST['user_pref_language'] ?? 'en';
$API_users->postedData['user_stompable'] = (bool)$_POST['user_stompable']; $API_users->postedData['user_stompable'] = (bool)$_POST['user_stompable'];
$API_users->validateData($requiredFields, $optionalFields);
$API_users->validateData($requiredFields);
$API_users->updateUser(); $API_users->updateUser();

1
sql-update-1.2.3.sql Normal file
View File

@@ -0,0 +1 @@
ALTER TABLE `system_users` CHANGE COLUMN `user_pref_language` `user_pref_language` ENUM("en","nl") NOT NULL DEFAULT 'en' COLLATE 'utf8mb4_general_ci' AFTER `user_login_attempts`;