function user_user_add_user($args = NULL) { // username, password, email if (isset($args) && is_array($args) && count($args) > 0) { extract($args); } else { $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; } // validasi semua input... if (strlen(trim($username)) < 4) { return "ERROR - Use at least 4 character for username"; } if (strlen(trim($password)) < 6) { return "ERROR - Use at least 6 character for password"; } // TODO: email validation if (!eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$", $email)) { return "ERROR - Invalid email"; } $username_exists = user_user_redundancy_check('username', $username); if ($username_exists) { return "ERROR - Username {$username} already taken. Use another username."; } $email_exists = user_user_redundancy_check('email', $email); if ($email_exists) { return "ERROR - Email already used. Use another email."; } // masukkan ke DB $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Users'); $lilo_mongo->selectCollection('Account'); $user_data = array('email' => $email, 'password' => $password, 'username' => $username); $lilo_id = $lilo_mongo->insert($user_data); $lilo_mongo->update($user_data, array_merge($user_data, array('lilo_id' => (string) $lilo_id)), array("multiple" => false)); $lilo_mongo->close(); if (isset($_POST['automate_login']) && $_POST['automate_login'] == '1') { user_user_login($username, $password); } // semua OK? return 'OK' return "OK"; }
function friend_user_ws_friendlist($keyword = NULL) { if (!isset($keyword)) { $keyword = func_arg(0); } // dapatkan circle array // ... $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection('Circles'); $circle_data_ = $lilo_mongo->findOne(array('user_id' => $_SESSION['user_id'])); $circle_data = $circle_data_['circle_array']; // dapatkan semua data di table Friends dengan user_id = $_SESSION['user_id'] $lilo_mongo->selectDB('Social'); $lilo_mongo->selectCollection('Friends'); $friend_cursor = $lilo_mongo->find(array('user_id' => $_SESSION['user_id'])); $friend_data = array(); while ($friend = $friend_cursor->getNext()) { unset($friend['_id']); // tambahkan detail $friend dari table Users.Account dan Users.Properties // dari $friend['user_id'] $friend_account_detail = friend_user_detailbyuserid($friend['friend_id']); $friend_account_detail = json_decode($friend_account_detail); $friend = array_merge((array) $friend, (array) $friend_account_detail); $friend_data[] = $friend; } $outer_circle_friend_data = $friend_data; for ($idx = 0; $idx < count($circle_data); $idx++) { $friend_list = array(); foreach ($friend_data as $friend) { $circle_array = $friend['circle_array']; if (in_array($circle_data[$idx], $circle_array)) { // // tambahkan detail $friend dari table Users.Account dan Users.Properties // // dari $friend['user_id'] // // $friend_account_detail = friend_user_detailbyuserid($friend['friend_id']); // $friend_account_detail = json_decode($friend_account_detail); // $friend = array_merge((array)$friend, (array)$friend_account_detail); $friend_list[] = $friend; } } $circle_data[$idx] = array_merge((array) $circle_data[$idx], (array) $friend_list); } // dapatkan semua friend yg tdk masuk circle manapun... // $outer_circle_friend_data = array_diff($outer_circle_friend_data, $friend_list); for ($idx = 0; $idx < count($outer_circle_friend_data); $idx++) { if (count($outer_circle_friend_data[$idx]['circle_array'])) { unset($outer_circle_friend_data[$idx]); } } // write_log(array('filename' => NULL, 'somecontent' => print_r($outer_circle_friend_data, true) . "\n\n" . print_r($friend_list, true))); $circle_data[] = array_merge(array('Outer Circle'), (array) $outer_circle_friend_data); unset($friend_list); unset($friend_data); unset($circle_data_); $lilo_mongo->close(); // dapatkan property setiap friend ! // return print_r($circle_data, true); // return print_r($circle_data, true) . '-------------' . print_r($friend_data, true); return json_encode($circle_data); }
function user_guest_add_user($args = NULL) { // username, password, email if (isset($args) && is_array($args) && count($args) > 0) { extract($args); $birthday_expl = explode('/', $birthday); $birthday_dd = $birthday_expl[0]; $birthday_mm = $birthday_expl[1]; $birthday_yy = $birthday_expl[2]; } else { $fullname = $_POST['fullname']; $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $avatarname = $_POST['avatarname']; $handphone = $_POST['handphone']; $twitter = $_POST['twitter']; // 'sex':new_sex,'birthday':new_birthday,'location':new_location, $sex = $_POST['sex']; $birthday = $_POST['birthday']; $birthday_expl = explode('/', $birthday); $birthday_dd = $birthday_expl[0]; $birthday_mm = $birthday_expl[1]; $birthday_yy = $birthday_expl[2]; $location = $_POST['location']; } if (!isset($via_fb)) { require_once 'libraries/recaptcha/recaptchalib.php'; $privatekey = "6Lc4rc0SAAAAAPcmFERN1OCwB05q72wvPipQS5zX"; $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly return "ERROR - The reCAPTCHA wasn't entered correctly. Try it again."; // [" . $resp->error . "] // $_SESSION['pop_error_msg'][] = "The reCAPTCHA wasn't entered correctly. Try it again. [" . $resp->error . "]"; // header("Location: " . $_SESSION['basepath']); // exit; } } $config = $_SESSION['config']; // validasi semua input... // only alpha numeric allowed for username // Revisi 04072012: username sama dengan email // if(!(ctype_alnum($username) && ctype_alnum($password))){ // return "ERROR - Use only letters and digits for username and password"; // } // // if(strlen(trim($username)) < 4){ // return "ERROR - Use at least 4 character for username"; // } if (strlen(trim($password)) < 6) { return "ERROR - Use at least 6 character for password"; } // TODO: email validation if (!eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$", $email)) { return "ERROR - Invalid email"; } // Revisi 04072012: username sama dengan email // jadi yg dicek redundan: avatar name //$username_exists = user_user_redundancy_check('username', $username); //if($username_exists){ // return "ERROR - Username $username already taken. Use another username."; //} $avatarname_exists = user_guest_property_redundancy_check('avatarname', $avatarname); if ($avatarname_exists) { return "ERROR - Avatar name {$avatarname} already taken. Use another avatar name."; } $lilo_mongo = new LiloMongo(); $lilo_mongo->selectDB('Users'); $lilo_mongo->selectCollection('Account'); $email_exists = user_user_redundancy_check('email', $email); if ($email_exists) { if (isset($via_fb)) { // koneksikan kedua account // user dapat login dengan username & password PB yg sudah dia daftarkan sebelumnya // dan dia bisa juga login dengan facebook // username: sama dengan email // password: ada 2, password dan fb_password // password adalah password lama // fb_password adalah password yg di-set saat register via facebook (saat ini sama dengan fb id) // jadi, cukup melakukan update di record user dgn email tsb dengan menambahkan field fb_password // saat login, pengecekan password dilakukan pada kedua field (password & fb_password) // yg bisa di update di account setting hanya 'password' // 'fb_password' tidak dapat diupdate. $criteria = array('email' => $email); $newobj = array('fb_password' => md5($fb_id), 'fb_id' => $fb_id); $options = array("multiple" => false); $lilo_mongo->update_set($criteria, $newobj, $options); $user_data = $lilo_mongo->findOne($criteria); // perlu langsung login atau tidak? $_SESSION['user_id'] = $user_data['lilo_id']; $_SESSION['username'] = $user_data['username']; $_SESSION['fullname'] = $user_data['$fullname']; user_user_login($username, $fb_id); return 'OK'; } else { return "ERROR - Email already used. Use another email."; // STRING JANGAN DIUBAH, KARENA DIGUNAKAN DI index.php saat registrasi via Facebook } } $join_date = time(); $act_key = $username . $join_date . rand(0, 9999); $activation_key = md5($act_key); // masukkan ke DB $user_data = array('email' => htmlspecialchars($email), 'password' => md5($password), 'username' => htmlspecialchars($username), 'join_date' => $join_date, 'activation_key' => $activation_key, 'fb_id' => $fb_id); $lilo_id = $lilo_mongo->insert($user_data); $lilo_mongo->update($user_data, array_merge($user_data, array('lilo_id' => (string) $lilo_id)), array("multiple" => false)); // masukkan fullname ke table Properties // update 28 Juni 2012: tambahkan field handphone & twitter $lilo_mongo->selectCollection('Properties'); $lilo_mongo->insert(array('lilo_id' => (string) $lilo_id, 'fullname' => htmlspecialchars($fullname), 'avatarname' => htmlspecialchars($avatarname), 'handphone' => htmlspecialchars($handphone), 'twitter' => htmlspecialchars($twitter), 'sex' => htmlspecialchars($sex), 'birthday' => htmlspecialchars($birthday), 'birthday_dd' => htmlspecialchars($birthday_dd), 'birthday_mm' => htmlspecialchars($birthday_mm), 'birthday_yy' => htmlspecialchars($birthday_yy), 'location' => htmlspecialchars($location))); // daftarkan user ini ke group 'user' // sampe seneee... $lilo_mongo->selectCollection('Group'); // dapatkan lilo_id untuk name: 'user' $group_ = $lilo_mongo->findOne(array('name' => 'user')); $group_id = $group_['lilo_id']; $lilo_mongo->selectCollection('GroupMember'); $lilo_mongo->insert(array('user_id' => (string) $lilo_id, 'group_id' => $group_id)); $lilo_mongo->close(); if (isset($_POST['automate_login']) && $_POST['automate_login'] == '1' || isset($automate_login) && $automate_login == '1') { $_SESSION['user_id'] = (string) $lilo_id; $_SESSION['username'] = $username; $_SESSION['fullname'] = $fullname; user_user_login($username, $password); } // semua OK? return 'OK' return "OK"; }