Subversion Repositories SmartDukaan

Rev

Rev 12700 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12694 anikendra 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
3
class Fos extends MY_Controller {
4
 
5
public $layoutName ='';
6
 
7
	function __construct() {
8
 
9
		// Call the CI_controller constructor
10
		parent::__construct();
11
		// $admin = $this->session->userdata('admin');
12
		// if(!isset($admin) || empty($admin)) {
13
		// 	redirect(base_url().'fosauthorize');
14
		// }
15
		$this->output->set_header("HTTP/1.0 200 OK");
16
		$this->output->set_header("HTTP/1.1 200 OK");
17
		$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()).' GMT');
18
		$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
19
		$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
20
		$this->output->set_header("Pragma: no-cache");
21
		$this->layout->setlayout('layout/layout_main');
22
		$this->load->model('fos_model');
23
		$this->layoutName= $this->layout->getLayout();
24
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
25
	}
26
 
27
	public function index()
28
	{
29
		$this->__oauthorization();	
30
	}
31
 
32
	function __oauthorization()
33
	{
34
		//sample session storage.. later i will imporve security for login 
35
		$check =$this->session->userdata('fosauthorize');
36
		// print_r($check);die;
37
		if(1 || isset($check) and !empty($check) and $check['authority']='success')
38
		{
39
			redirect(base_url().'fos/signupcounter');
40
		}
41
		else
42
		{
43
			$this->login();
44
		}	
45
	}
46
 
47
	function dashboard() {
48
		$configdata = $this->config->item('fos_dashboard');
49
		$cachemodule = array('header','footer');
50
	    $configdata = getCache($configdata,$cachemodule);
51
	    //end of get cache
52
	    $this->lessphp->object()->ccompile('assets/css/recharge.less','assets/css/recharge.css');
53
	    $data['stylesheet'] = 'recharge.css';
54
	    $data['title'] = 'Dashboard';
55
	    $data['response']=$this->fos_model->getDashboard($this->input->get(),$this->input->post(),$this->config->item('fos_dashboard'));
56
		$this->layout->view(strtolower(__CLASS__).'/dashboard',$data);
57
	}
58
 
59
	function login()
60
	{
61
		//standard array
62
		$data = array();
63
		 if (isset($_SERVER['HTTP_REFERER'])) {
64
			if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {
65
   				$redirect = $_SERVER['HTTP_REFERER'];   				
66
   				$location = $this->session->userdata('location');
67
   				if(isset($location) && $location == 'shipping'){
68
   					$data['location'] = 'shipping';
69
   					$location = base_url().$location;
70
   					$this->session->set_userdata('location',$location);
71
   				}elseif(isset($location) && ($location == 'my-recharges' || $location == 'my-wallet')){
72
   					$location = base_url().$location;
73
   					$this->session->set_userdata('location',$location);
74
   				}else{
75
   					$this->session->set_userdata('location',$redirect);	
76
   				}
77
 
78
			}
79
		}
80
		$fosauthorized = $this->session->userdata('fosauthorized');
81
		if(1 || isset($fosauthorized) && !empty($fosauthorized) && $fosauthorized['isLoggedIn'] == 1){
82
			redirect(base_url().'fos/dashboard');
83
		}
84
		//get cache 
85
		$fosauthorized = $this->session->userdata('fosauthorized');
86
		if(isset($_POST) && !empty($_POST)) {
87
			if(isset($fosauthorized) && !empty($fosauthorized)){
88
				$_POST['username'] = $fosauthorized['username'];
89
				// $_POST['cartId'] = $fosauthorized['cartId'];
90
				if($fosauthorized['isActive'] == 1){
91
					$_POST['isLoggedIn'] = 'true';
92
				}
93
				elseif(isset($fosauthorized['isActive']) && empty($fosauthorized['isActive'])) {
94
					$_POST['isLoggedIn'] = 'false';
95
				}
96
			}
97
			//end of get cache
98
			$configdata =array();
99
			$configdata = $this->config->item('fos_login');
100
			unset($configdata['response'][0]);
101
			$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata);
102
			// print_r($data['response']['response']);die;
103
			//set cache to output or renew cache
104
			if(isset($data['response']['response']['foslogin']['fosauthorized']))
105
			{
106
				$this->session->set_userdata('fosauthorized',$data['response']['response']['foslogin']['fosauthorized']);
107
				//$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));
108
				$location = $this->session->userdata('location');
109
				if(isset($location) && !empty($location)){
110
					$this->session->unset_userdata('location');
111
					redirect($location);
112
				} else{
113
					redirect(base_url().$data['response']['response']['foslogin']['redirect']);	
114
				}
115
			} else {
116
				$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
117
				$data['title'] = 'Saholic';
118
				$data['stylesheet'] = 'auth.css';
119
				$this->layout->view(strtolower(__CLASS__).'/fos_view',$data);
120
			}
121
		} else{
122
			$configdata =array();
123
			$configdata = $this->config->item('fos_login');
124
			unset($configdata['response'][1]);
125
			$cachemodule = array('header','footer','response');
126
			$configdata = getCache($configdata,$cachemodule);
127
			$data = array();
128
			$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
129
			$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
130
			$data['title'] = 'Login';
131
			$data['stylesheet'] = 'auth.css';
132
			if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
133
			{
134
				foreach($cachemodule as $cm)
135
				{
136
					if(isset($configdata[$cm]) and !empty($configdata[$cm]))
137
					{
138
						$data['response'][$cm]=$configdata[$cm];
139
					}
140
				}
141
			}
142
			setCache($configdata['module'],$cachemodule,$data['response']);
143
			$this->layout->view(strtolower(__CLASS__).'/login',$data);
144
		}
145
	}
146
 
147
	function logout() {
148
		$fosauthorized = $this->session->userdata('fosauthorized');
149
		if(isset($fosauthorized) and !empty($fosauthorized))
150
		{
151
			$this->session->unset_userdata('fosauthorized');
152
			$this->session->unset_userdata('authorized');
153
			$this->session->unset_userdata('addressId');
154
			$this->session->unset_userdata('hotspotId');
155
			$this->session->unset_userdata('cod');
156
			$this->session->unset_userdata('userId');
157
			$this->session->unset_userdata('captcha');
158
			redirect(base_url().'home');
159
		}
160
	}
161
 
162
 
163
	//social login process
164
	public function session($provider)
165
	{
166
  //   	if (isset($_SERVER['HTTP_REFERER'])) {
167
		// 	if(strpos($_SERVER['HTTP_REFERER'],'session') == false) {
168
  //  				$location = $_SERVER['HTTP_REFERER'];
169
  //  				$this->session->set_userdata('location',$location);
170
		// 	}
171
		// }
172
    	$type = $provider;
173
        $this->load->helper('url_helper');
174
        $social =$this->config->item('fos_social');
175
 
176
        $this->load->spark('fos2/0.4.0');
177
 
178
        $provider = $this->fos2->provider($provider, array(
179
            'id' => $social[$provider]['id'],
180
            'secret' => $social[$provider]['secretkey']
181
 
182
        ));
183
 
184
 
185
        if ( ! $this->input->get('code'))
186
        {
187
        	if($this->input->get('error')) {
188
        		redirect(base_url());
189
        	}else{
190
        		redirect($provider->fosauthorize());
191
        	}
192
            // By sending no options it'll come back here
193
        }
194
        else
195
        {
196
            try
197
            {
198
            	//manage login operation here and redirect to perspective link
199
                $token = $provider->access($_GET['code']);
200
 
201
                $user = $provider->get_user_info($token);
202
                if(strcasecmp('facebook', $type) == 0){
203
                	$_POST['isFacebookUser'] = 'true';
204
                	$_POST['accessToken'] = $user['access_token'];
205
                	$_POST['facebookId'] = $user['uid'];
206
                	$_POST['email'] = $user['email'];
207
                	if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST['email'])) {
208
  						$fosauthorized = $this->session->userdata('fosauthorized');
209
						if(isset($_POST) && !empty($_POST)){
210
							if(isset($fosauthorized) && !empty($fosauthorized)){
211
								$_POST['userId'] = $fosauthorized['Id'];
212
								$_POST['Id'] = $fosauthorized['cartId'];
213
								if($fosauthorized['isLoggedIn'] == 1){
214
									$_POST['isLoggedIn'] = 'true';
215
								}
216
								elseif(isset($fosauthorized['isLoggedIn']) && empty($fosauthorized['isLoggedIn'])) {
217
									$_POST['isLoggedIn'] = 'false';
218
								}
219
							}
220
						}
221
		                $data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$this->config->item('fos_login'));
222
		                if(isset($data['response']['response']['login']['fosauthorized']))
223
						{
224
							$this->session->set_userdata('fosauthorized',$data['response']['response']['login']['fosauthorized']);
225
							$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));
226
							$location = $this->session->userdata('location');
227
							if(isset($location) && !empty($location)){
228
								$this->session->unset_userdata('location');
229
								redirect($location);
230
							}
231
							else{
232
								redirect(base_url().$data['response']['response']['login']['redirect']);	
233
							}
234
						}
235
						else
236
						{
237
							$inputfile = base_url().'assets/css/auth.less';
238
							$outputfile = base_url().'assets/css/auth.less';
239
							$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
240
							$data['stylesheet'] = 'auth.css';
241
							$this->layout->view(strtolower(__CLASS__).'/fos_view',$data);
242
						}
243
					}else{
244
						$this->session->set_flashdata(array('msg'=>'Some problem occured.Please try again!'));
245
						redirect(base_url().'login');
246
					}
247
				}
248
                // Here you should use this information to A) look for a user B) help a new user sign up with existing data.
249
                // If you store it all in a cookie and redirect to a registration page this is crazy-simple.
250
                //echo "<pre>Tokens: ";
251
                //var_dump($token);
252
 
253
                //echo "\n\nUser Info: ";
254
                //var_dump($user);
255
            }
256
 
257
            catch (OAuth2_Exception $e)
258
            {
259
                show_error('That didnt work: '.$e);
260
            }
261
 
262
        }
263
    }
264
 
265
    function signupcounter() {
266
    	$data = array();    	
267
		if (isset($_SERVER['HTTP_REFERER'])) {
268
			if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {
269
   				$redirect = $_SERVER['HTTP_REFERER'];
270
   				$location = $this->session->userdata('location');
271
   				$this->session->set_userdata('location',$redirect);	
272
			}
273
		}
274
 
275
		//get cache 
276
		$fosauthorized = $this->session->userdata('fosauthorized');
277
		if(isset($_POST) && !empty($_POST)) {
278
			if(isset($fosauthorized) && !empty($fosauthorized)) {
279
				$_POST['userId'] = $fosauthorized['Id'];
280
				if($fosauthorized['isLoggedIn'] == 1){
281
					$_POST['isLoggedIn'] = 'true';
282
				}
283
				elseif(isset($fosauthorized['isLoggedIn']) && empty($fosauthorized['isLoggedIn'])) {
284
					$_POST['isLoggedIn'] = 'false';
285
				}
286
			}
287
 
288
			$configdata =array();
289
			$configdata = $this->config->item('fos_signupcounter');
290
			unset($configdata['response'][0]);
291
			$data['response']=$this->fos_model->getSignup($this->input->get(),$this->input->post(),$configdata);
292
			//set cache to output or renew cache
293
			if(1 || isset($data['response']['response']['signup']['fosauthorized']))
294
			{
295
				$this->session->set_userdata('fosauthorized',$data['response']['response']['signup']['fosauthorized']);
296
				$this->session->set_flashdata(array('msg'=>$data['response']['response']['signup']['msg']));
297
				$location = $this->session->userdata('location');
298
				$location = base_url()."fos/thanks";//delete me
299
				if(isset($location) && !empty($location)){
300
					$this->session->unset_userdata('location');
301
					redirect($location);
302
				}
303
				redirect(base_url().$data['response']['response']['signup']['redirect']);
304
			}
305
			else
306
			{
307
				$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
308
				$data['title'] = 'Saholic';
309
				$data['stylesheet'] = 'auth.css';
310
				$this->layout->view(strtolower(__CLASS__).'/fos_view',$data);
311
			}
312
		} else {
313
			$configdata =array();
314
			$configdata = $this->config->item('fossignup');
315
			unset($configdata['response'][1]);
316
			$cachemodule = array('header','footer','response');
317
			$configdata = getCache($configdata,$cachemodule);
318
			$data = array();
319
			$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
320
			$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
321
			$data['stylesheet'] = 'shipping.css';
322
			$data['title'] = 'Register Counter';
323
			if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
324
			{
325
				foreach($cachemodule as $cm)
326
				{
327
					if(isset($configdata[$cm]) and !empty($configdata[$cm]))
328
					{
329
						$data['response'][$cm]=$configdata[$cm];
330
					}
331
				}
332
			}
333
			setCache($configdata['module'],$cachemodule,$data['response']);
334
			$this->layout->view(strtolower(__CLASS__).'/signupcounter',$data);
335
		}
336
    }
337
 
338
    function thanks() {
339
    	$configdata = $this->config->item('fos_dashboard');
340
		$cachemodule = array('header','footer');
341
	    $configdata = getCache($configdata,$cachemodule);
342
	    //end of get cache
343
	    $this->lessphp->object()->ccompile('assets/css/recharge.less','assets/css/recharge.css');
344
	    $data['stylesheet'] = 'recharge.css';
345
	    $data['title'] = 'Dashboard';
346
	    $data['response']=$this->fos_model->getDashboard($this->input->get(),$this->input->post(),$this->config->item('fos_dashboard'));
347
		$this->layout->view(strtolower(__CLASS__).'/thanks',$data);
348
    }
349
}