/** * Check pattern is created by user * @param Number $patternId * @param Number $fbId * @return Number 0 --> no, 1 --> yes */ public function checkAccountPattern($patternId, $fbId) { $ptn = $this->patternDao->getById($patternId); $accountSrv = new AccountService($this->dp); $account = $accountSrv->getByFbId($fbId); if (is_null($ptn) || is_null($account)) { return 0; } if ($ptn->accountid == $account->id) { return 1; } return 0; }
$session = null; try { $session = $helper->getSessionFromRedirect(); } catch (Exception $ex) { // When validation fails or other local issues PLog::log($ex); } if (!is_null($session)) { // Get fb information $userProfile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className()); $fbName = $userProfile->getName(); $fbId = $userProfile->getId(); // Get account from database $db = DP::getInstant(); $accountSrv = new AccountService($db); $account = $accountSrv->getByFbId($fbId); // Insert into database If account not exist if (is_null($account)) { $account = new Account(); $account->fbId = $fbId; $account->fbName = $fbName; $accountSrv->insert($account); } $_SESSION[FB_TOKEN] = $session->getToken(); $_SESSION[FB_UID] = $fbId; } // Redirect to specified page if (isset($_SESSION['PREV_URL1'])) { $url = $_SESSION['PREV_URL1']; $_SESSION['PREV_URL1'] = null; Flight::redirect($url);