| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- $page_title = "Settings";
- Core::addBreadcrumb("/account", "Account");
- Core::addBreadcrumb("/account/settings", $page_title);
- $user = Core::$user;
- $submit = http::value("submit");
- if($submit) {
- try {
- Core::validateCSRFToken($submit);
- $form_exception = new FormException;
- // Password
- $password = http::value("password");
- $password_confirm = http::value("password_confirm");
- if($password != $password_confirm) $form_exception->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->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(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");
- ?>
|