Example #1
0
 /**
  * Sets up the session
  *
  * @param $title
  * @param $flashes
  * @param $restricted
  * @param $registered
  * @return array
  */
 static function init($title, $flashes, $restricted, $registered)
 {
     $page = [];
     $page['title'] = $title;
     $page['_SESSION'] = $_SESSION;
     $page['websiteTitle'] = $GLOBALS['websiteTitle'];
     $page['loggedin'] = User::isLoggedIn();
     if ($page['loggedin']) {
         $page['user'] = User::getUser();
     }
     // Redirect to login if the user requests a restricted page is not logged in
     if ($restricted && !User::isLoggedIn()) {
         self::setError('You must be logged in to access this page.');
         self::redirect('/login');
     }
     // Redirect to login if user's session has expired
     if ($restricted && self::hasExpired()) {
         self::destroySession();
         self::setError('Your session has expired, please log back in.');
         self::redirect('/login');
     } else {
         // extend the session
         self::setExpiry();
     }
     // If the page is a registered only page, and the person is not registered, redirect
     if ($registered && User::firstUse()) {
         self::setError('You must be Registered to view this page.');
         self::redirect('/register');
     }
     if ($flashes) {
         $page['flash'] = self::getFlashes();
     }
     $page['_SESSION']['options']['font-size'] = 'normal';
     return $page;
 }
Example #2
0
<?php

// Make sure this is the first time
// the user has used the website
if (!User::firstUse()) {
    Session::setError('Cannot register, you have already registered before.');
    Session::redirect('/');
}
// If the request is post, try and sign them up
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    foreach ($_POST['register'] as $key => $value) {
        if (is_array($value)) {
            $result = User::setEducation($value);
        } else {
            $result = User::setAttribute($key, $value);
        }
        if ($result == false) {
            Session::setError('Unable to complete your registration, please try again.');
            Session::redirect('/register');
        }
    }
    $user = User::getUser();
    $registration = UTSHelpsAPI::RegisterStudent(['StudentId' => $user['student_id'], 'DateOfBirth' => $user['dob'], 'Gender' => $user['gender'], 'Degree' => $user['degree'], 'Status' => $user['status'], 'FirstLanguage' => $user['first_language'], 'CountryOrigin' => $user['country_of_origin'], 'DegreeDetails' => $user['year'], 'AltContact' => $user['best_contact_no'], 'PreferredName' => $user['preferred_first_name'], 'HSC' => (bool) $user['hsc'], 'HSCMark' => $user['hsc_mark'], 'IELTS' => (bool) $user['ielts'], 'IELTSMark' => $user['ielts_mark'], 'TOEFL' => (bool) $user['toefl'], 'TOEFLMark' => $user['toefl_mark'], 'TAFE' => (bool) $user['tafe'], 'TAFEMark' => $user['tafe_mark'], 'CULT' => (bool) $user['cult'], 'CULTMark' => $user['cult_mark'], 'InsearchDEEP' => (bool) $user['insearch_deep'], 'InsearchDEEPMark' => $user['insearch_deep_mark'], 'InsearchDiploma' => (bool) $user['insearch_diploma'], 'InsearchDiplomaMark' => $user['insearch_diploma_mark'], 'FoundationCourse' => (bool) $user['foundation_course'], 'FoundationCourseMark' => $user['foundation_course_mark'], 'CreatorId' => 123456]);
    $message = Notification::renderEmail('emails/registration.html', ['name' => $user['name']]);
    Notification::sendEmail($user['email'], $user['name'], 'Registration Successful', $message);
    User::setFirstUse();
    User::setLastLogin();
    Session::setSuccess('You have successfully saved your registration details.');
    Session::redirect('/');
}
// Get the user
Example #3
0
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // check whether the posted fields are empty
    if (!empty($_POST['login']['studentId']) && !empty($_POST['login']['password'])) {
        // try and log the user in
        // block default accounts for demo
        if (in_array($_POST['login']['studentId'], ['11111111', '22222222'])) {
            Session::setError('Your Student ID or Password was incorrect or the account does not exist, please try again.');
            Session::redirect('/login');
        }
        if (User::attemptLogin($_POST['login']['studentId'], $_POST['login']['password'])) {
            $_SESSION['studentId'] = $_POST['login']['studentId'];
            if ($_POST['login']['rememberMe'] == 'yes') {
                $_SESSION['expiry'] = 0;
            } else {
                Session::setExpiry();
            }
            Session::setSuccess('You have successfully been logged in.');
            if (User::firstUse($_SESSION['studentId'])) {
                Session::redirect('/register');
            }
            Session::redirect('/');
        } else {
            Session::setError('Your Student ID or Password was incorrect or the account does not exist, please try again.');
            Session::redirect('/login');
        }
    } else {
        // set error message and redirect
        Session::setError('Unable to log you in, one or more fields was empty');
        Session::redirect('/login');
    }
}
Example #4
0
<?php

$page['loggedin'] = false;
if (User::isLoggedIn()) {
    // If it's the user's first use, make sure they register
    if (User::firstUse()) {
        Session::setError('You have to register first before using this service.');
        Session::redirect('/register');
    }
    $page['loggedin'] = true;
    // search for the users bookings
    $bookings = UTSHelpsAPI::SearchWorkshopBookings(['studentId' => User::getPaddedId(), 'pageSize' => 9999, 'active' => true]);
    $currentTime = strtotime(Session::getCurrentDateTime());
    $count = 0;
    // Get all the upcoming bookings
    if ($bookings != null && $bookings->IsSuccess == 1) {
        foreach ($bookings->Results as $booking) {
            // if booking archived field does not have a date, it hasn't been canceled or attended
            if ($booking->BookingArchived == null && strtotime($booking->starting) > $currentTime && $booking->canceled === null && $booking->attended === null) {
                $count++;
            }
        }
    }
    $page['bookingCount'] = $count;
    // Get all of the workshops for the workshop listings
    $workshops = UTSHelpsAPI::ListWorkshopSets(true);
    if ($workshops != null && $workshops->IsSuccess == 1) {
        $page['workshops'] = count($workshops->Results);
    } else {
        $page['workshops'] = 0;
    }