Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
                    $reason = lang("ACCOUNT_TOO_YOUNG");
                }
                addSessionMessage(lang("ACCOUNT_NOT_YET_ELIGIBLE", array("")), "notice");
            }
            //CLEAN UP
            unset($fname, $lname, $email, $zip, $city);
        }
    }
    // Add alerts to session for display
    foreach ($errors as $error) {
        addSessionAlert($error);
    }
} elseif (!empty($_GET['activation']) && !empty($_GET['uid'])) {
    $uid = $_GET['uid'];
    $activation = $_GET['activation'];
    $newuser = new RedcapPortalUser($uid);
    if ($newuser->isEmailTokenValid($activation)) {
        //SET EMAIL = VERIFIED
        $newuser->setEmailVerified();
        //SET USER IN SESSION
        $loggedInUser = new RedcapPortalUser($uid);
        setSessionUser($loggedInUser);
        //REDIRECT TO CONSENT
        header("Location: consent.php");
        exit;
    } else {
        // Invalid token match
        $errors[] = "The supplied email activation token is invalid or expired.  This can happen if you regenerated a new token but followed the link from an older request.";
        addSessionAlert("Invalid email activation token");
    }
}