public static function isPositiveNumber($fieldValue, $fieldName)
 {
     $error = [];
     // Is a number
     if (is_numeric($fieldValue)) {
         // Is positive
         if ($fieldValue > 0) {
             return true;
         } else {
             $error[$fieldName] = $fieldName . self::PRICES[self::INVALID_SIZE];
         }
     } else {
         $error[$fieldName] = $fieldName . self::PRICES[self::WRONG_FORMAT];
     }
     // Error
     SessionOperator::setInputErrors($error);
     return false;
 }
Example #2
0
require_once "../classes/class.validation_operator.php";
require_once "../classes/class.session_operator.php";
// Reset password (if user cannot remember)
if (isset($_POST["resetPassword"])) {
    // Check if email is associated with an account
    $userInfo = QueryOperator::getAccountFromEmail($_POST["email"]);
    // Email belongs to an account - send password reset email to that user
    if ($userInfo != null) {
        $mail = new Email($_POST["email"], $userInfo["firstName"], $userInfo["lastName"]);
        $mail->prepareResetEmail();
        $mail->sentEmail();
        SessionOperator::setNotification(SessionOperator::RESET_PASSWORD);
        HelperOperator::redirectTo("../index.php");
    } else {
        // Create a session for not found email
        SessionOperator::setInputErrors(["email" => "Email could not be found in our records"]);
        // Create a session for the inputted email so that it can be recovered after the page reloads
        SessionOperator::setFormInput(["email" => $_POST["email"]]);
        HelperOperator::redirectTo("../views/forgot_password_view.php");
    }
} else {
    if (isset($_POST["changePassword"])) {
        // Retrieve Passwords
        $passwordFields = ["password1" => $_POST["password1"], "password2" => $_POST["password2"]];
        $email = SessionOperator::getEmail();
        $userDetails = QueryOperator::getAccountFromEmail($email);
        // Both passwords valid and match
        if (!ValidationOperator::hasEmtpyFields($passwordFields) && ValidationOperator::validPasswords($passwordFields["password1"], $passwordFields["password2"])) {
            QueryOperator::updatePassword($email, $passwordFields["password2"]);
            SessionOperator::deleteEmail();
            SessionOperator::setNotification(SessionOperator::CHANGED_PASSWORD);
        }
    } else {
        $error = [];
        if (($upload = ValidationOperator::checkImage()) != null) {
            // A user is logged in
            if (!is_null($user = SessionOperator::getUser())) {
                // Create random image name
                $newImageName = UPLOAD_PROFILE_IMAGE . uniqid("", true) . "." . $upload["imageExtension"];
                // Upload new profile picture to file system
                if (move_uploaded_file($upload["image"], ROOT . $newImageName)) {
                    // Delete old profile pic (if exists)
                    if (!empty($imageName = $user->getImage())) {
                        unlink(ROOT . $imageName);
                    }
                    // Store image name in database
                    QueryOperator::uploadImage($user->getUserId(), $newImageName, "users");
                    // Update user session
                    $user = QueryOperator::getAccount($user->getUserId());
                    SessionOperator::updateUser(new User($user));
                    // Set feedback session
                    SessionOperator::setNotification(SessionOperator::UPLOADED_PROFILE_PHOTO);
                } else {
                    $error["upload"] = "Image cannot be uploaded ";
                    SessionOperator::setInputErrors($error);
                }
            }
        }
    }
}
// Redirect back
HelperOperator::redirectTo("../views/profile_view.php");
Example #4
0
<?php

require_once "../classes/class.helper_operator.php";
require_once "../classes/class.session_operator.php";
require_once "../classes/class.user.php";
// Sign in button was clicked
if (isset($_POST["signIn"])) {
    require_once "../classes/class.query_operator.php";
    require_once "../classes/class.session_operator.php";
    $email = trim($_POST["loginEmail"]);
    $password = trim($_POST["loginPassword"]);
    // Login details correct
    if (!is_null($account = QueryOperator::checkAccount($email, $password))) {
        // Login user and redirect to home page
        SessionOperator::login(new User($account));
        HelperOperator::redirectTo("../views/my_live_auctions_view.php");
    } else {
        // Create a session for the login inputs so that they can be recovered after the page reloads
        SessionOperator::setFormInput(["loginEmail" => $email, "loginPassword" => $password]);
        // Create a session for incorrect email and user details
        $message = "The entered email and password did not match our records, please try again.";
        SessionOperator::setInputErrors(["login" => $message]);
    }
}
// Sign in button was not clicked or sign in failed
HelperOperator::redirectTo("../index.php");