diff --git a/pub/api/v1/portal-management/users/index.php b/pub/api/v1/portal-management/users/index.php index ab35ed2..0052804 100644 --- a/pub/api/v1/portal-management/users/index.php +++ b/pub/api/v1/portal-management/users/index.php @@ -20,28 +20,28 @@ if ($API_users->request_method === 'GET') { 'user_email' => ['type' => 'email'], 'user_first_name' => ['type' => 'string'], 'user_last_name' => ['type' => 'string'], - 'user_full_name' => ['type' => 'string'], - 'user_phone_number' => ['type' => 'string'], - 'user_status' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned', 'pending']], - 'user_password' => ['type' => 'string'], - 'user_pref_language' => ['type' => 'string'], - 'user_password_reset_token' => ['type' => 'string'], - 'user_password_reset_expires' => ['type' => 'int'], + 'user_full_name' => ['type' => 'string'], # Does not need to be posted, set later + 'user_status' => ['type' => 'enum', 'values' => ['inactive', 'banned', 'pending']], + 'user_password' => ['type' => 'string'], # Does not need to be posted, set later + 'user_pref_language' => ['type' => 'enum', 'values' => ['en', 'nl']], + 'user_password_reset_token' => ['type' => 'string'], # Does not need to be posted, set later + 'user_password_reset_expires' => ['type' => 'int'], # Does not need to be posted, set later ]; - # 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)); $user_password = password_hash($random_string, PASSWORD_BCRYPT, ["cost" => 12]); $API_users->postedData['user_password'] = $user_password; - $API_users->postedData['user_full_name'] = trim($_POST['user_first_name'] . ' ' . $_POST['user_last_name']); - $API_users->postedData['user_pref_language'] = $_POST['user_pref_language'] ?? 'en'; - - # Password reset token that will be send to the newly created user + # Password reset token that will be sent to the newly created user $API_users->postedData['user_password_reset_token'] = bin2hex(random_bytes(32)); $API_users->postedData['user_password_reset_expires'] = time() + 86400; - $API_users->validateData($requiredFields); + $API_users->validateData($requiredFields, $optionalFields); $API_users->createUser(); } elseif ($API_users->request_method === 'PUT') { @@ -56,9 +56,12 @@ if ($API_users->request_method === 'GET') { 'user_first_name' => ['type' => 'string'], 'user_last_name' => ['type' => 'string'], 'user_full_name' => ['type' => 'string'], - 'user_phone_number' => ['type' => 'string'], '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'] ]; @@ -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_stompable'] = (bool)$_POST['user_stompable']; - - $API_users->validateData($requiredFields); - + $API_users->validateData($requiredFields, $optionalFields); $API_users->updateUser(); diff --git a/sql-update-1.2.3.sql b/sql-update-1.2.3.sql new file mode 100644 index 0000000..1f44de8 --- /dev/null +++ b/sql-update-1.2.3.sql @@ -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`;