addError(__("Passwords do not match.")); if($password) { $user->password = password_hash($password, PASSWORD_DEFAULT, ["cost" => 14]); } $user->title = http::value("title", "trim"); $user->first_name = http::value("first_name", "trim"); $user->last_name = http::value("last_name", "trim"); $user->email = http::value("email", "email"); $user->phone = http::value("phone", "trim"); $user->has_driving_licence = (int) http::value("has_driving_licence", "int"); $user->has_car = (int) http::value("has_car", "int"); $user->locale = http::value("locale", "trim"); $user->newsletter_consent = http::value("newsletter_content", "int"); $locales = Core::locales(); if($password && !User::validatePassword($password)) $form_exception->addError(__("Password must be at least 6 characters in length and contain at least one lowercase, uppercase, number and special character.")); if(empty($user->email)) $form_exception->addError(__("Email address is invalid.")); if(empty($user->title)) $form_exception->addError(__("Title is required.")); if(empty($user->first_name)) $form_exception->addError(__("First name is required.")); if(empty($user->last_name)) $form_exception->addError(__("Last name is required.")); if(empty($user->date_of_birth)) $form_exception->addError(__("Date of birth is required.")); if(empty($user->phone)) $form_exception->addError(__("Mobile number is required.")); if(!isset($locales[$user->locale])) $form_exception->addError(__("Invalid language selected.")); if($user->isTester()) { $user->preferred_payment_method = http::value("preferred_payment_method", "int"); $user->bank_name = http::value("bank_name", "trim"); $user->bank_sort_code = http::value("bank_sort_code", "trim"); $user->bank_account_number = http::value("bank_account_number", "trim"); $user->paypal_email = http::value("paypal_email", "email"); if(!isset(User::PAYMENT_METHODS[$user->preferred_payment_method])) $form_exception->addError(__("Invalid payment method selected.")); } // Activation $deactivate = http::value("deactivate"); if($deactivate && $user->level == User::LEVEL_TESTER) { $user->level = User::LEVEL_DEACTIVATED; } $reactivate = http::value("reactivate"); if($reactivate && $user->level == User::LEVEL_DEACTIVATED) { $user->level = User::LEVEL_TESTER; } if($form_exception->hasErrors()) throw $form_exception; $success = $user->commit(); Core::addAlert("success", __("Settings saved successfully.")); HTTP::redirect("/account/settings"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } View::includeOnce("header", compact("page_title")); View::include("settings", compact("user")); View::includeOnce("footer"); ?>