Exemplo n.º 1
0
 public static function autoLogin($rememberme = true)
 {
     if (isset($_SESSION["userId"])) {
         $userId = $_SESSION["userId"];
         $user = GameUsers::getGameUserById($userId);
         if (!empty($user)) {
             UtilFunctions::storeSessionUser($user, $rememberme);
             return $user;
         }
     }
     if (isset($_COOKIE["auth"]) && false) {
         $cookie = $_COOKIE["auth"];
         $arr = explode('&', $cookie);
         $userName = substr($arr[0], 4);
         $hash = substr($arr[1], 5);
         $user = GameUsers::getGameUserByUserName($userName);
         if (!empty($user)) {
             if ($hash == md5($user->getPassword())) {
                 $user->setLastLoginDate(time());
                 $user->setLoginCount($user->getLoginCount() + 1);
                 $user->updateToDatabase(DBUtils::getConnection());
                 Queue::checkUserFriends($user->userId);
                 UtilFunctions::storeSessionUser($user, $rememberme);
                 return $user;
             } else {
                 UtilFunctions::forgetMe();
             }
         }
     }
     return false;
 }
Exemplo n.º 2
0
    public function index()
    {
        if (defined("SERVER_PROD")) {
            if (!SERVER_PROD) {
                $this->user = GameUsers::getGameUserById(2);
                LanguageUtils::setLocale($this->user->language);
                if (!empty($this->user) && $this->user->active == 0) {
                    $this->redirect("banned");
                    exit(1);
                }
                return;
            }
        }
        $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true));
        $login_req = true;
        $this->user = UtilFunctions::autoLogin();
        if (!empty($this->user)) {
            $facebook->setAccessToken($this->user->getOauthToken());
            try {
                $fbUser = $facebook->api("/me");
                if (!empty($fbUser) && !empty($fbUser['id'])) {
                    $login_req = false;
                }
            } catch (Exception $exc) {
                $this->log->logError($exc->getTraceAsString());
            }
        } else {
            $login_req = true;
            if (isset($_GET['error']) || isset($_GET['error_reason']) || isset($_GET['error_description'])) {
                if ($_GET['error_description']) {
                    $this->addError($_GET['error_description']);
                }
                if (isset($_GET['error_reason'])) {
                    $this->addError(isset($_GET['error_reason']));
                }
                echo "<p> Error : " . $_GET['error_reason'] . "</p>";
                echo "<p> Please Refresh Page ! </p>";
                exit(1);
            } else {
                $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true));
                try {
                    $fbUser = $facebook->api("/me");
                } catch (Exception $exc) {
                    $this->log->logError($exc->getTraceAsString());
                }
                if (!empty($fbUser) && !empty($fbUser['id'])) {
                    $this->user = GameUsers::getGameUserByFBId($fbUser['id']);
                    if (!empty($this->user)) {
                        $this->user->setOauthToken($facebook->getAccessToken());
                        $this->user->setLastLoginDate(time());
                        $this->user->setLoginCount($this->user->getLoginCount() + 1);
                        $this->user->updateToDatabase(DBUtils::getConnection());
                        Queue::checkUserFriends($this->user->userId);
                        UtilFunctions::storeSessionUser($this->user);
                        $login_req = false;
                    } else {
                        $result = GameUsers::createGameUser($fbUser, $facebook->getAccessToken());
                        if ($result->success) {
                            $this->user = $result->result;
                            if (!empty($result)) {
                                $userId = $this->user->getUserId();
                                if (!empty($userId)) {
                                    Queue::checkUserFriends($this->user->userId);
                                    UtilFunctions::storeSessionUser($this->user);
                                    $login_req = false;
                                    $this->newUser = "******";
                                }
                            } else {
                                $this->addError(LANG_FACEBOOK_USER_CREATE_ERROR_UNKNOWN_ERROR);
                            }
                        } else {
                            if (!empty($result->result)) {
                                foreach ($result->result as $value) {
                                    $this->addError($value);
                                }
                            } else {
                                $this->addError(LANG_FACEBOOK_USER_CREATE_ERROR_UNKNOWN_ERROR);
                            }
                        }
                        unset($result);
                    }
                }
                if (!$login_req && !empty($this->user)) {
                    GameUserLoginLog::insertLog($this->user->userId);
                }
            }
        }
        if (!$login_req) {
            if (!empty($this->user) && $this->user->active == 0) {
                $this->redirect("banned");
                exit(1);
            }
        }
        if ($login_req) {
            UtilFunctions::forgetMe();
            $params = array('scope' => FB_SCOPE, 'redirect_uri' => FB_CALLBACK_URL);
            $login_url = $facebook->getLoginUrl($params);
            if (isset($_SERVER['QUERY_STRING'])) {
                if (strpos($login_url, "?")) {
                    $login_url . "&" . $_SERVER['QUERY_STRING'];
                } else {
                    $login_url . "?" . $_SERVER['QUERY_STRING'];
                }
            }
            ?>
            <!DOCTYPE html>
            <html xmlns="http://www.w3.org/1999/xhtml">
                <head></head>
                <body><script>top.location.href='<?php 
            echo $login_url;
            ?>
';</script></body>
            </html>
            <?php 
            exit(1);
        } else {
            $this->dailyBonus = BonusUtils::getDailyBonusPrice($this->user);
            if (isset($_GET['request_ids']) && !empty($_GET['request_ids'])) {
                $this->fbRequests = FacebookRequestUtils::getFacebookGiftRequest($this->user, $_GET['request_ids']);
            }
            LanguageUtils::setLocale($this->user->language);
        }
    }