예제 #1
0
 public function createAccount($username, $password, $email, $location)
 {
     $userInfoError = $this->validateUserInfo($username, $password, $email, $location);
     if (is_null($userInfoError)) {
         $emailCode = genVerificationCode();
         // Insert row into users table
         $data = ['User_name' => $username, 'User_password' => password_hash($password, PASSWORD_DEFAULT), 'User_email' => $email, 'User_location' => $location, 'User_email_code' => $emailCode];
         // Insert and check for unique key error
         if (!$this->CI->user_access->createAccount($data)) {
             $result = ['status' => 500, 'details' => 'An unknown error occurred'];
         } else {
             //$this->CI->load->library('emailer');
             //$this->CI->emailer->sendVerificationCode($params['email'], $emailCode);
             $userId = $this->CI->user_access->insert_id();
             $sessionId = $this->CI->sessions_lib->createSession($userId);
             unset($data['User_password']);
             unset($data['User_email_code']);
             $result = ['status' => 200, 'user' => $data, 'sessionId' => $sessionId];
         }
     } else {
         $result = ['status' => 400, 'details' => $userInfoError];
     }
     return $result;
 }
예제 #2
0
function genVerificationCode()
{
    $CI =& get_instance();
    $char = "ABC8D7EF4123497GHIJKL98874KJA798HJHSAS636131MNOPQRS55ASDDFASDFASDFFFASTUVWXYZ23AK465JF4SUYRBJKCJASDYSAF";
    $code = '';
    for ($p = 0; $p < 10; $p++) {
        $code .= $char[mt_rand(0, strlen($char))];
    }
    $code .= '-' . time();
    $status = $CI->db->get_where($CI->db->USER, array('s_verification_code' => $code))->num_rows();
    if ($status > 0) {
        genVerificationCode();
    } else {
        return $code;
    }
}