Example #1
0
// 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
$page['user'] = User::getUser();
$page['educational-backgrounds'] = ['hsc' => ['label' => 'HSC', 'key' => 'hsc'], 'ielts' => ['label' => 'IELTS', 'key' => 'ielts'], 'toefl' => ['label' => 'TOEFL', 'key' => 'toefl'], 'tafe' => ['label' => 'TAFE', 'key' => 'tafe'], 'cult' => ['label' => 'CULT', 'key' => 'cult'], 'insearchDeep' => ['label' => 'Insearch DEEP', 'key' => 'insearchDeep'], 'insearchDiploma' => ['label' => 'Insearch Diploma', 'key' => 'insearchDiploma'], 'foundationCourse' => ['label' => 'Foundation Course', 'key' => 'foundationCourse']];
 /**
  * Log user in
  *
  * @access public
  * @param User $user
  * @param boolean $remember
  * @return null
  */
 function logUserIn(User $user, $remember = false)
 {
     $user->setLastLogin(DateTimeValueLib::now());
     if (is_null($user->getLastActivity())) {
         $user->setLastVisit(DateTimeValueLib::now());
     } else {
         $user->setLastVisit($user->getLastActivity());
     }
     // if
     $this->setLoggedUser($user, $remember, true);
 }
Example #3
0
 // optional fields
 if ($name != '') {
     $user->setName($name);
 }
 if ($sex != '') {
     $user->setSex($sex);
 }
 if ($location != '') {
     $user->setLocation($location);
 }
 if ($biography != '') {
     $user->setBiography($biography);
 }
 $user->save();
 // save the user
 $user->setLastLogin($user->getDateCreated());
 $user->save();
 // save last login as date created
 // log the event
 $logEvent = new Event(array('event_type_id' => 'create_user', 'user_1_id' => $user->getId()));
 $logEvent->save();
 // email confirmation
 $body = '<p>You have successfully registered for <a href="' . Url::base() . '">' . PIPELINE_NAME . '</a>.</p>';
 $body .= '<p>Your username is ' . formatUserLink($user->getID()) . '. Have fun!</p>';
 $newEmail = array('to' => $email, 'subject' => '[' . PIPELINE_NAME . '] Welcome to ' . PIPELINE_NAME . '!', 'message' => $body);
 Email::send($newEmail);
 // log us into the new account
 Session::signIn($user->getId());
 // link any email invites to this user
 Invitation::linkByEmail($email, $user->getID());
 // set confirm message and send us away
 /**
  * Log user in
  *
  * @access public
  * @param User $user
  * @param boolean $remember
  * @return null
  */
 function logUserIn(User $user, $remember = false)
 {
     trace(__FILE__, 'logUserIn():begin');
     $user->setLastLogin(DateTimeValueLib::now());
     if (is_null($user->getLastActivity())) {
         $user->setLastVisit(DateTimeValueLib::now());
     } else {
         $user->setLastVisit($user->getLastActivity());
     }
     // if
     trace(__FILE__, 'logUserIn():setLoggedUser()');
     $this->setLoggedUser($user, $remember, true);
     trace(__FILE__, 'logUserIn():end');
 }
Example #5
0
 /**
  * @covers AppBundle\Entity\User::setLastLogin
  * Implement testSetLastLogin().
  */
 public function testSetLastLogin()
 {
     $this->assertEmpty($this->user->getLastLogin());
     $this->user->setLastLogin("15-11-2015T12-30-00");
     $this->assertNotEmpty($this->user->getLastLogin());
 }