Пример #1
0
 public function createNewUser($pass, $verifymail = true)
 {
     if (self::usernameExists()) {
         $this->error = "Error creating user (CODE 001)";
         // Don't create a user if they already exist!
         return false;
     }
     if (empty($pass)) {
         $this->error = "Error creating user (CODE 002)";
         // Missing password
         return false;
     }
     // Salt and Hash password
     //$salt = generateRandomString(25, true);
     $password_salt_hash = generateHash($pass);
     //logIt("Hashing $pass with $salt to yield $password_hash","DEBUG");
     $data = array(REDCAP_FIRST_FIELD => $this->next_user_id, getRF('username') => $this->username, getRF('password') => $password_salt_hash, getRF('firstname') => ucfirst($this->firstname), getRF('lastname') => $this->lastname, getRF('zip') => $this->zip, getRF('city') => $this->city, getRF('state') => $this->state, getRF('age') => $this->age, getRF('email') => $this->email, getRF('created_ts') => date('Y-m-d H:i:s'));
     // Add event if longitudinal
     if (REDCAP_PORTAL_EVENT !== NULL) {
         $data['redcap_event_name'] = REDCAP_PORTAL_EVENT;
     }
     logIt("CREATE NEW USER WITH DATA:" . print_r($data, true), "DEBUG");
     $result = RC::writeToApi($data, array('returnContent' => 'ids'));
     $new_user_id = is_array($result) ? current($result) : null;
     if (is_numeric($new_user_id)) {
         $this->new_user_id = $new_user_id;
         if ($verifymail) {
             $newuser = new RedcapPortalUser($new_user_id);
             $newuser->createEmailToken();
             $newuser->emailEmailToken();
         }
     } else {
         logIt("Error creating new user: "******"ERROR");
         $this->error = "Error creating user via API";
     }
     logIt("CREATE NEW USER RESULT:" . json_encode($result), "DEBUG");
     return $new_user_id;
 }
Пример #2
0
 //Checking this flag tells us whether there were any errors such as possible data duplication occured
 if ($auth->emailExists()) {
     $tempu = getUserByEmail($email);
     $olduser = new RedcapPortalUser($tempu->user_id);
     if ($olduser->isActive()) {
         //CURRENT ACCOUNT + ACTIVE (LINK ALREADY CLICKED)
         $errors[] = lang("ACCOUNT_EMAIL_IN_USE_ACTIVE", array($email));
     } else {
         //CURRENT ACCOUTN NOT ACTIVE
         if ($oldenough && $nextyear && $optin && $actualage >= 18) {
             //WAS FORMERLY INELIGIBLE NOW ELIGIBLE, SEND ACTIVATION LINK
             $errors[] = lang("ACCOUNT_NEW_ACTIVATION_SENT", array($email));
             //SEND NEW ACTIVATION LINK
             $olduser->updateUser(array(getRF("zip") => $zip, getRF("city") => $city, getRF("state") => $state, getRF("age") => $actualage));
             $olduser->createEmailToken();
             $olduser->emailEmailToken();
             //CLEAN UP
             unset($fname, $lname, $email, $zip, $city);
         } else {
             //WAS FORMERLY AND STILL IS INELIGIBLE
             addSessionMessage(lang("ACCOUNT_NOT_YET_ELIGIBLE", array("")), "notice");
         }
     }
 } else {
     //IF THEY DONT PASS ELIGIBILITY THEN THEY GET A THANK YOU , BUT NO ACCOUNT CREATION
     //BUT NEED TO STORE THEIR STUFF FOR CONTACT
     if ($oldenough && $nextyear && $optin && $actualage >= 18) {
         //Attempt to add the user to the database, carry out finishing  tasks like emailing the user (if required)
         if ($auth->createNewUser($password)) {
             addSessionMessage(lang("ACCOUNT_NEW_ACTIVATION_SENT"), "success");
             // THEY WILL NOW NEED TO VERIFY THEIR EMAIL LINK