Rev 12700 | Rev 12732 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');class Fos extends MY_Controller {public $layoutName ='';function __construct() {// Call the CI_controller constructorparent::__construct();// $admin = $this->session->userdata('admin');// if(!isset($admin) || empty($admin)) {// redirect(base_url().'fosauthorize');// }$this->output->set_header("HTTP/1.0 200 OK");$this->output->set_header("HTTP/1.1 200 OK");$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()).' GMT');$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");$this->output->set_header("Cache-Control: post-check=0, pre-check=0");$this->output->set_header("Pragma: no-cache");$this->layout->setlayout('layout/layout_main');$this->load->model('fos_model');$this->layoutName= $this->layout->getLayout();$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';}public function index(){$this->__oauthorization();}function __oauthorization(){//sample session storage.. later i will imporve security for login$check =$this->session->userdata('fosauthorize');// print_r($check);die;if(isset($check) and !empty($check) and $check['authority']='success'){redirect(base_url().'fos/signupcounter');}else{$this->login();}}function dashboard() {$configdata = $this->config->item('fos_dashboard');$cachemodule = array('header','footer');$configdata = getCache($configdata,$cachemodule);//end of get cache$this->lessphp->object()->ccompile('assets/css/recharge.less','assets/css/recharge.css');$data['stylesheet'] = 'recharge.css';$data['title'] = 'Dashboard';$data['response']=$this->fos_model->getDashboard($this->input->get(),$this->input->post(),$this->config->item('fos_dashboard'));$this->layout->view(strtolower(__CLASS__).'/dashboard',$data);}function login(){//standard array$data = array();/*if (isset($_SERVER['HTTP_REFERER'])) {if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {$redirect = $_SERVER['HTTP_REFERER'];$location = $this->session->userdata('location');if(isset($location) && $location == 'shipping'){$data['location'] = 'shipping';$location = base_url().$location;$this->session->set_userdata('location',$location);}elseif(isset($location) && ($location == 'my-recharges' || $location == 'my-wallet')){$location = base_url().$location;$this->session->set_userdata('location',$location);}else{$this->session->set_userdata('location',$redirect);}}}*/$fosauthorized = $this->session->userdata('fosauthorized');if(isset($fosauthorized) && !empty($fosauthorized) && $fosauthorized['isLoggedIn'] == 1){redirect(base_url().'fos/dashboard');}//get cache$fosauthorized = $this->session->userdata('fosauthorized');if(isset($_POST) && !empty($_POST)) {if(isset($fosauthorized) && !empty($fosauthorized)){$_POST['username'] = $fosauthorized['username'];// $_POST['cartId'] = $fosauthorized['cartId'];if($fosauthorized['isActive'] == 1){$_POST['isLoggedIn'] = 'true';}elseif(isset($fosauthorized['isActive']) && empty($fosauthorized['isActive'])) {$_POST['isLoggedIn'] = 'false';}}//end of get cache$configdata =array();$configdata = $this->config->item('fos_login');unset($configdata['response'][0]);$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata);//set cache to output or renew cacheif(isset($data['response']['response']['foslogin']['fosauthorized'])){$this->session->set_userdata('fosauthorized',$data['response']['response']['foslogin']['fosauthorized']);//$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));$location = $this->session->userdata('location');if(isset($location) && !empty($location)){$this->session->unset_userdata('location');redirect($location);} else{redirect(base_url().$data['response']['response']['foslogin']['redirect']);}} else {$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');$data['title'] = 'Saholic';$data['stylesheet'] = 'auth.css';// $this->layout->view(strtolower(__CLASS__).'/fos_view',$data);redirect(base_url().'fos/login');}} else{$configdata =array();$configdata = $this->config->item('fos_login');unset($configdata['response'][1]);$cachemodule = array('header','footer','response');$configdata = getCache($configdata,$cachemodule);$data = array();$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');$data['title'] = 'Login';$data['stylesheet'] = 'auth.css';if(isset($cachemodule) and !empty($cachemodule) && !isset($api)){foreach($cachemodule as $cm){if(isset($configdata[$cm]) and !empty($configdata[$cm])){$data['response'][$cm]=$configdata[$cm];}}}setCache($configdata['module'],$cachemodule,$data['response']);$this->layout->view(strtolower(__CLASS__).'/login',$data);}}function logout() {$fosauthorized = $this->session->userdata('fosauthorized');if(isset($fosauthorized) and !empty($fosauthorized)){$this->session->unset_userdata('fosauthorized');$this->session->unset_userdata('authorized');$this->session->unset_userdata('addressId');$this->session->unset_userdata('hotspotId');$this->session->unset_userdata('cod');$this->session->unset_userdata('userId');$this->session->unset_userdata('captcha');redirect(base_url().'home');}}//social login processpublic function session($provider){// if (isset($_SERVER['HTTP_REFERER'])) {// if(strpos($_SERVER['HTTP_REFERER'],'session') == false) {// $location = $_SERVER['HTTP_REFERER'];// $this->session->set_userdata('location',$location);// }// }$type = $provider;$this->load->helper('url_helper');$social =$this->config->item('fos_social');$this->load->spark('fos2/0.4.0');$provider = $this->fos2->provider($provider, array('id' => $social[$provider]['id'],'secret' => $social[$provider]['secretkey']));if ( ! $this->input->get('code')){if($this->input->get('error')) {redirect(base_url());}else{redirect($provider->fosauthorize());}// By sending no options it'll come back here}else{try{//manage login operation here and redirect to perspective link$token = $provider->access($_GET['code']);$user = $provider->get_user_info($token);if(strcasecmp('facebook', $type) == 0){$_POST['isFacebookUser'] = 'true';$_POST['accessToken'] = $user['access_token'];$_POST['facebookId'] = $user['uid'];$_POST['email'] = $user['email'];if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST['email'])) {$fosauthorized = $this->session->userdata('fosauthorized');if(isset($_POST) && !empty($_POST)){if(isset($fosauthorized) && !empty($fosauthorized)){$_POST['userId'] = $fosauthorized['Id'];$_POST['Id'] = $fosauthorized['cartId'];if($fosauthorized['isLoggedIn'] == 1){$_POST['isLoggedIn'] = 'true';}elseif(isset($fosauthorized['isLoggedIn']) && empty($fosauthorized['isLoggedIn'])) {$_POST['isLoggedIn'] = 'false';}}}$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$this->config->item('fos_login'));if(isset($data['response']['response']['login']['fosauthorized'])){$this->session->set_userdata('fosauthorized',$data['response']['response']['login']['fosauthorized']);$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));$location = $this->session->userdata('location');if(isset($location) && !empty($location)){$this->session->unset_userdata('location');redirect($location);}else{redirect(base_url().$data['response']['response']['login']['redirect']);}}else{$inputfile = base_url().'assets/css/auth.less';$outputfile = base_url().'assets/css/auth.less';$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');$data['stylesheet'] = 'auth.css';$this->layout->view(strtolower(__CLASS__).'/fos_view',$data);}}else{$this->session->set_flashdata(array('msg'=>'Some problem occured.Please try again!'));redirect(base_url().'login');}}// Here you should use this information to A) look for a user B) help a new user sign up with existing data.// If you store it all in a cookie and redirect to a registration page this is crazy-simple.//echo "<pre>Tokens: ";//var_dump($token);//echo "\n\nUser Info: ";//var_dump($user);}catch (OAuth2_Exception $e){show_error('That didnt work: '.$e);}}}function signupcounter() {$data = array();if (isset($_SERVER['HTTP_REFERER'])) {if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {$redirect = $_SERVER['HTTP_REFERER'];$location = $this->session->userdata('location');$this->session->set_userdata('location',$redirect);}}//get cache$fosauthorized = $this->session->userdata('fosauthorized');if(isset($_POST) && !empty($_POST)) {/*if(isset($fosauthorized) && !empty($fosauthorized)) {$_POST['userId'] = $fosauthorized['Id'];if($fosauthorized['isLoggedIn'] == 1){$_POST['isLoggedIn'] = 'true';}elseif(isset($fosauthorized['isLoggedIn']) && empty($fosauthorized['isLoggedIn'])) {$_POST['isLoggedIn'] = 'false';}}*/$configdata =array();$configdata = $this->config->item('fos_signupcounter');unset($configdata['response'][0]);$data['response']=$this->fos_model->getSignup($this->input->get(),$this->input->post(),$configdata);//set cache to output or renew cacheif(isset($data['response']['response']['fossignup']['authorized']['id'])){$this->session->set_flashdata(array('msg'=>$data['response']['response']['fossignup']['msg']));$this->session->set_userdata('username',$data['response']['response']['fossignup']['authorized']['id']);$this->session->set_userdata('countercode',$data['response']['response']['fossignup']['authorized']['counterCode']);redirect(base_url().$data['response']['response']['fossignup']['redirect']);}else{$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');$data['title'] = 'Saholic';$data['stylesheet'] = 'auth.css';$this->session->set_flashdata(array('msg'=>$data['response']['response']['messsage']));redirect(base_url().$data['response']['response']['fossignup']['redirect']);}} else {$configdata =array();$configdata = $this->config->item('fossignup');unset($configdata['response'][1]);$cachemodule = array('header','footer','response');$configdata = getCache($configdata,$cachemodule);$data = array();$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');$data['stylesheet'] = 'shipping.css';$data['title'] = 'Register Counter';if(isset($cachemodule) and !empty($cachemodule) && !isset($api)){foreach($cachemodule as $cm){if(isset($configdata[$cm]) and !empty($configdata[$cm])){$data['response'][$cm]=$configdata[$cm];}}}setCache($configdata['module'],$cachemodule,$data['response']);$this->layout->view(strtolower(__CLASS__).'/signupcounter',$data);}}function thanks() {$configdata = $this->config->item('fos_dashboard');$cachemodule = array('header','footer');$configdata = getCache($configdata,$cachemodule);//end of get cache$this->lessphp->object()->ccompile('assets/css/recharge.less','assets/css/recharge.css');$data['stylesheet'] = 'recharge.css';$data['title'] = 'Dashboard';$data['username'] = $this->session->userdata('username');$data['countercode'] = $this->session->userdata('countercode');$data['response']=$this->fos_model->getDashboard($this->input->get(),$this->input->post(),$this->config->item('fos_dashboard'));$this->layout->view(strtolower(__CLASS__).'/thanks',$data);}}