function login()
 {
     $code = '';
     if (isset($_GET['code'])) {
         $code = $_GET['code'];
     }
     if (!isset($_SESSION)) {
         session_start();
     }
     $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . FB_APP . "&redirect_uri=" . urlencode(FB_URL) . "&client_secret=" . FB_SECRET . "&code=" . $code;
     $response = file_get_contents($token_url);
     $params = null;
     parse_str($response, $params);
     $_SESSION['access_token'] = $params['access_token'];
     $graph_url = "https://graph.facebook.com/me?access_token=" . $_SESSION['access_token'];
     $fb_user = json_decode(file_get_contents($graph_url));
     $user = new User();
     //adding the fb_id to the existing email and login
     if (!$user->checkLogin($fb_user->email)) {
         $user->id = $user->getIDByEmail($fb_user->email);
         $user->username = $user->getUsername();
         $user->addFBID($fb_user->id);
         $user->fb_id = $fb_user->id;
         $auth = new SlideWikiAuth($user);
         $auth->login();
         echo "<script> top.location.href='" . BASE_PATH . "'</script>";
     } else {
         $this->set('fb_user', $fb_user);
     }
 }
 function __construct($model, $controller, $action)
 {
     $this->_controller = $controller;
     $this->_action = $action;
     $this->_model = $model;
     $user_id = SlideWikiAuth::getUserId();
     if ($user_id) {
         $user = new User();
         $user->createFromID($user_id);
         $this->_user = array('is_authorized' => SlideWikiAuth::isAuthorized(), 'id' => $user_id, 'name' => $user->username);
     } else {
         $this->_user = array('is_authorized' => false, 'id' => 0, 'name' => '');
     }
     //$this->$model = new $model;
     if (!$this->_noRender) {
         $this->_template = new Template($controller, $action, $this->_noHeader, $this->_noFooter);
         $this->set('user', $this->_user);
     }
 }
Exemple #3
0
 public static function getUserId()
 {
     if (SlideWikiAuth::isAuthorized()) {
         return $_SESSION['uid'];
     } else {
         return 0;
         //return 'Login please.';
     }
 }
Exemple #4
0
 function logout()
 {
     SlideWikiAuth::logout();
 }