$user = array(); $user['username'] = $db->escape($username); $user['email'] = $db->escape($email); $user['password'] = sha1($password); $user['first_name'] = $db->escape($name); $user['gender'] = $gender == 'male' ? 1 : 0; $user['institute'] = $db->escape($institute); $user['location'] = $db->escape($location); $user['registered_in'] = date("Y-m-d H:i:s", time()); $user['verified'] = 0; // Register the user $registrar = new Registrar($db); $user_id = $registrar->registerUser($user); if ($user_id) { // Registration successfull - Send the email verification link if ($registrar->sendVerificationEmail($user_id, $email)) { $result = array('success' => true); } else { $result = array('success' => false, 'error' => 'Unexpected error!'); } header('Content-Type: application/json'); echo json_encode($result); exit; } } else { $result = array('success' => false, 'error' => implode("<br/>", $error)); header('Content-Type: application/json'); echo json_encode($result); exit; } } else {
if ($user['oauth_type'] != OAUTH_TWITTER) { $user['verified'] = 1; } // Add user's record to the database $registrar = new Registrar($db); $id = $registrar->registerUser($user); if ($id) { // Delete tempUser record and unset temporary session variables $db->where('id', $_SESSION['temp_user_id']); $db->delete('users_temp'); unset($_SESSION['registration_pending']); unset($_SESSION['temp_user_id']); unset($_SESSION['spoof_proof']); /* If email has been manually provided, it needs to be verified. */ if (isset($email)) { $registrar->sendVerificationEmail($id, $user['email']); // Show verification page link $result = array('success' => true, 'verify' => true); header('Content-Type: application/json'); echo json_encode($result); exit; } // Now that the registration is complete, login the user $loginHelper = new LoginHelper(); $redirect_uri = $loginHelper->Login($id, $user['oauth_type'], $user['oauth_id']); // Return the success information $result = array('success' => true, 'redirect_uri' => $redirect_uri); header('Content-Type: application/json'); echo json_encode($result); exit; } else {