/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new FUser(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['FUser'])) { $model->attributes = $_POST['FUser']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->uid)); } } $this->render('create', array('model' => $model)); }
public function filterFacebook($filterChain) { header('P3P: CP="CAO PSA OUR"'); $facebook = Yii::app()->params['facebook']; $user = $facebook->getUser(); if (isset($_REQUEST['request_ids'])) { $_SESSION['request_ids'] = $_REQUEST['request_ids']; $rids = $_REQUEST['request_ids']; if (strpos($rids, ",") > -1) { //multi invitation $arr = explode(",", $rids); $rid = $arr[0]; $reqs = FRequest::model()->findAll('requestId=:rid', array(':rid' => $rid)); if (isset($reqs)) { if (count($reqs) > 0) { $req = $reqs[0]; $pageContent = file_get_contents('https://graph.facebook.com/' . $req->fbId); $parsedJson = json_decode($pageContent); $this->render('invitation', array('id' => $req->fbId, 'name' => $parsedJson->name)); Yii::app()->end(); } } } else { //one invitation $reqs = FRequest::model()->findAll('requestId=:rid', array(':rid' => $_REQUEST['request_ids'])); if (isset($reqs)) { if (count($reqs) > 0) { $req = $reqs[0]; $pageContent = file_get_contents('https://graph.facebook.com/' . $req->fbId); $parsedJson = json_decode($pageContent); $this->render('invitation', array('id' => $req->fbId, 'name' => $parsedJson->name)); Yii::app()->end(); } } } } $fbme = null; if ($user) { try { $uid = $user; //$facebook->getUser(); $fbme = $facebook->api('/me'); } catch (FacebookApiException $e) { print_r("<pre>" . $e . "</pre>"); } } if ($fbme) { $_SESSION["fbid"] = $uid; $fu = self::loadUserByFBID($_SESSION["fbid"]); if (!isset($fu)) { //user not exists....add new user $fu = new FUser(); $fu->name = $fbme['name']; $fu->nick = $fbme['name']; $fu->facebookID = $_SESSION["fbid"]; $fu->first_name = $fbme['first_name']; $fu->last_name = $fbme['last_name']; $fu->username = $fbme['username']; $fu->gender = $fbme['gender']; $fu->email = $fbme['email']; try { $fu->save(); } catch (FacebookApiException $e) { print_r("<pre>" . $e . "</pre>"); } } $identity = new UserIdentity($fu->name, $_SESSION["fbid"]); if ($identity->authenticate()) { Yii::app()->user->login($identity); } else { echo $identity->errorMessage; Yii::app()->end(); } // call $filterChain->run() to continue filtering and action execution $filterChain->run(); } else { $appId = $facebook->getAppId(); $canvasUrl = $facebook->getCanvasPage(); // Set the required permissions for the application $perms = Yii::app()->params['permissions']; $loginUrl = "https://www.facebook.com/dialog/oauth?scope=" . $perms . "&client_id=" . $facebook->getAppId() . "&redirect_uri=" . urlencode($canvasUrl); echo "<head><title>redirection</title><script> top.location.href='" . $loginUrl . "'; </script></head>"; Yii::app()->end(); } }