Esempio n. 1
0
function user_user_loginfb($fb_id)
{
    // sama dengan user_user_login, tapi utk pengguna FB: password tidak ada / sama dengan email / sama dengan id
    include_once 'libraries/fb/facebook.php';
    $config = array();
    $config['appId'] = '353789864649141';
    $config['secret'] = '9e066419bed7d9ff07f4475f26318aa8';
    $config['fileUpload'] = false;
    // optional
    $facebook = new Facebook($config);
    $me = $facebook->api('/me');
    // die("uname: $uname<br /><pre>" . print_r($me, true) . "</pre>");
    write_log(array('log_text' => time() . ": user_user_loginfb: fb_id: " . print_r($fb_id, true)));
    write_log(array('log_text' => time() . ": user_user_loginfb: " . print_r($me, true)));
    // dapatkan uname dari db
    $lilo_mongo = new LiloMongo();
    $lilo_mongo->selectDB('Users');
    $lilo_mongo->selectCollection('Account');
    $user_data = $lilo_mongo->findOne(array('fb_id' => $fb_id));
    $logged_in = user_user_login($user_data['username'], $me[id]);
    if ($logged_in != '0') {
        $_SESSION['fb_id'] = $fb_id;
    }
    return $logged_in;
}
Esempio n. 2
0
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";
}