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;
 }
Esempio n. 2
0
 //Construct a user auth object
 $auth = new RedcapAuth($username, NULL, $email, $fname, $lname, $zip, $city, $state, $actualage);
 //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)) {
 function updateUser($data = array(), $extra_params = array(), $flushLog = true)
 {
     // Add record ID if not already there
     $data[REDCAP_FIRST_FIELD] = $this->user_id;
     // Add event if longitudinal
     if (REDCAP_PORTAL_EVENT !== NULL) {
         $data['redcap_event_name'] = REDCAP_PORTAL_EVENT;
     }
     logIt("updateUser data1:" . print_r($data, true), "DEBUG");
     if ($flushLog && count($this->log_entry > 0)) {
         $newLog = array(getRF('log') => implode("\n", $this->log_entry));
         $data = array_merge($data, $newLog);
         //$this->log_entry = array();
     }
     //logIt("updateUser data2:".print_r($data,true), "DEBUG");
     $result = RC::writeToApi($data, $extra_params);
     if (isset($result['error'])) {
         logIt('Error updating User: '******'error'] . " with: " . print_r($data, true));
         return false;
     }
     //logIt("updateUser result:".print_r($result,true), "DEBUG");
     // Flush the log
     if ($flushLog) {
         $this->log_entry = array();
     }
     // Reload the session user from the API
     self::refreshUser();
     return true;
     //$result;
 }
Esempio n. 4
0
function getUserByEmail($email)
{
    $params = array('fields' => array(REDCAP_FIRST_FIELD, getRF('email')));
    $result = RC::callApi($params);
    $errors = array();
    $matches = array();
    foreach ($result as $idx => $record) {
        $recordEmail = sanitize($record[getRF('email')]);
        logIt("email: {$email} / recordEmail: {$recordEmail}");
        if ($email == $recordEmail) {
            $matches[$record[REDCAP_FIRST_FIELD]] = $record;
        }
    }
    if (count($matches) == 0) {
        logIt("Found no matching users with email: {$email}", "DEBUG");
        return false;
    }
    if (count($matches) > 1) {
        // Found more than one match!
        logIt("Found more than one match for email: {$email}", "ERROR");
        return false;
    }
    if (count($matches) == 1) {
        $user_id = key($matches);
        logIt("Found {$user_id} via email", "INFO");
        $user = new RedcapPortalUser($user_id);
        return $user;
    }
}