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->phone = http::value("phone", "trim"); $user->newsletter_consent = http::value("newsletter_content", "int"); $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($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(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"); ?>