Subversion Repositories SmartDukaan

Rev

Rev 12694 | Rev 12704 | Go to most recent revision | Details | Compare with Previous | 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;
12700 anikendra 37
		if(isset($check) and !empty($check) and $check['authority']='success')
12694 anikendra 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');
12700 anikendra 81
		if(isset($fosauthorized) && !empty($fosauthorized) && $fosauthorized['isLoggedIn'] == 1){
12694 anikendra 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';
12700 anikendra 119
				// $this->layout->view(strtolower(__CLASS__).'/fos_view',$data);
120
				redirect(base_url().'fos/login');	
12694 anikendra 121
			}
122
		} else{
123
			$configdata =array();
124
			$configdata = $this->config->item('fos_login');
125
			unset($configdata['response'][1]);
126
			$cachemodule = array('header','footer','response');
127
			$configdata = getCache($configdata,$cachemodule);
128
			$data = array();
129
			$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
130
			$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
131
			$data['title'] = 'Login';
132
			$data['stylesheet'] = 'auth.css';
133
			if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
134
			{
135
				foreach($cachemodule as $cm)
136
				{
137
					if(isset($configdata[$cm]) and !empty($configdata[$cm]))
138
					{
139
						$data['response'][$cm]=$configdata[$cm];
140
					}
141
				}
142
			}
143
			setCache($configdata['module'],$cachemodule,$data['response']);
144
			$this->layout->view(strtolower(__CLASS__).'/login',$data);
145
		}
146
	}
147
 
148
	function logout() {
149
		$fosauthorized = $this->session->userdata('fosauthorized');
150
		if(isset($fosauthorized) and !empty($fosauthorized))
151
		{
152
			$this->session->unset_userdata('fosauthorized');
153
			$this->session->unset_userdata('authorized');
154
			$this->session->unset_userdata('addressId');
155
			$this->session->unset_userdata('hotspotId');
156
			$this->session->unset_userdata('cod');
157
			$this->session->unset_userdata('userId');
158
			$this->session->unset_userdata('captcha');
159
			redirect(base_url().'home');
160
		}
161
	}
162
 
163
 
164
	//social login process
165
	public function session($provider)
166
	{
167
  //   	if (isset($_SERVER['HTTP_REFERER'])) {
168
		// 	if(strpos($_SERVER['HTTP_REFERER'],'session') == false) {
169
  //  				$location = $_SERVER['HTTP_REFERER'];
170
  //  				$this->session->set_userdata('location',$location);
171
		// 	}
172
		// }
173
    	$type = $provider;
174
        $this->load->helper('url_helper');
175
        $social =$this->config->item('fos_social');
176
 
177
        $this->load->spark('fos2/0.4.0');
178
 
179
        $provider = $this->fos2->provider($provider, array(
180
            'id' => $social[$provider]['id'],
181
            'secret' => $social[$provider]['secretkey']
182
 
183
        ));
184
 
185
 
186
        if ( ! $this->input->get('code'))
187
        {
188
        	if($this->input->get('error')) {
189
        		redirect(base_url());
190
        	}else{
191
        		redirect($provider->fosauthorize());
192
        	}
193
            // By sending no options it'll come back here
194
        }
195
        else
196
        {
197
            try
198
            {
199
            	//manage login operation here and redirect to perspective link
200
                $token = $provider->access($_GET['code']);
201
 
202
                $user = $provider->get_user_info($token);
203
                if(strcasecmp('facebook', $type) == 0){
204
                	$_POST['isFacebookUser'] = 'true';
205
                	$_POST['accessToken'] = $user['access_token'];
206
                	$_POST['facebookId'] = $user['uid'];
207
                	$_POST['email'] = $user['email'];
208
                	if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST['email'])) {
209
  						$fosauthorized = $this->session->userdata('fosauthorized');
210
						if(isset($_POST) && !empty($_POST)){
211
							if(isset($fosauthorized) && !empty($fosauthorized)){
212
								$_POST['userId'] = $fosauthorized['Id'];
213
								$_POST['Id'] = $fosauthorized['cartId'];
214
								if($fosauthorized['isLoggedIn'] == 1){
215
									$_POST['isLoggedIn'] = 'true';
216
								}
217
								elseif(isset($fosauthorized['isLoggedIn']) && empty($fosauthorized['isLoggedIn'])) {
218
									$_POST['isLoggedIn'] = 'false';
219
								}
220
							}
221
						}
222
		                $data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$this->config->item('fos_login'));
223
		                if(isset($data['response']['response']['login']['fosauthorized']))
224
						{
225
							$this->session->set_userdata('fosauthorized',$data['response']['response']['login']['fosauthorized']);
226
							$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));
227
							$location = $this->session->userdata('location');
228
							if(isset($location) && !empty($location)){
229
								$this->session->unset_userdata('location');
230
								redirect($location);
231
							}
232
							else{
233
								redirect(base_url().$data['response']['response']['login']['redirect']);	
234
							}
235
						}
236
						else
237
						{
238
							$inputfile = base_url().'assets/css/auth.less';
239
							$outputfile = base_url().'assets/css/auth.less';
240
							$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
241
							$data['stylesheet'] = 'auth.css';
242
							$this->layout->view(strtolower(__CLASS__).'/fos_view',$data);
243
						}
244
					}else{
245
						$this->session->set_flashdata(array('msg'=>'Some problem occured.Please try again!'));
246
						redirect(base_url().'login');
247
					}
248
				}
249
                // Here you should use this information to A) look for a user B) help a new user sign up with existing data.
250
                // If you store it all in a cookie and redirect to a registration page this is crazy-simple.
251
                //echo "<pre>Tokens: ";
252
                //var_dump($token);
253
 
254
                //echo "\n\nUser Info: ";
255
                //var_dump($user);
256
            }
257
 
258
            catch (OAuth2_Exception $e)
259
            {
260
                show_error('That didnt work: '.$e);
261
            }
262
 
263
        }
264
    }
265
 
266
    function signupcounter() {
267
    	$data = array();    	
268
		if (isset($_SERVER['HTTP_REFERER'])) {
269
			if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {
270
   				$redirect = $_SERVER['HTTP_REFERER'];
271
   				$location = $this->session->userdata('location');
272
   				$this->session->set_userdata('location',$redirect);	
273
			}
274
		}
275
 
276
		//get cache 
277
		$fosauthorized = $this->session->userdata('fosauthorized');
278
		if(isset($_POST) && !empty($_POST)) {
12700 anikendra 279
			/*if(isset($fosauthorized) && !empty($fosauthorized)) {
12694 anikendra 280
				$_POST['userId'] = $fosauthorized['Id'];
281
				if($fosauthorized['isLoggedIn'] == 1){
282
					$_POST['isLoggedIn'] = 'true';
283
				}
284
				elseif(isset($fosauthorized['isLoggedIn']) && empty($fosauthorized['isLoggedIn'])) {
285
					$_POST['isLoggedIn'] = 'false';
286
				}
12700 anikendra 287
			}*/	
12694 anikendra 288
 
289
			$configdata =array();
290
			$configdata = $this->config->item('fos_signupcounter');
291
			unset($configdata['response'][0]);
292
			$data['response']=$this->fos_model->getSignup($this->input->get(),$this->input->post(),$configdata);
293
			//set cache to output or renew cache
12700 anikendra 294
			if(isset($data['response']['response']['fossignup']['authorized']['id']))
12694 anikendra 295
			{
12700 anikendra 296
				$this->session->set_flashdata(array('msg'=>$data['response']['response']['fossignup']['msg']));
297
				$this->session->set_userdata('username',$data['response']['response']['fossignup']['authorized']['id']);
298
				$this->session->set_userdata('countercode',$data['response']['response']['fossignup']['authorized']['counterCode']);
299
				redirect(base_url().$data['response']['response']['fossignup']['redirect']);
12694 anikendra 300
			}
301
			else
302
			{
303
				$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
304
				$data['title'] = 'Saholic';
305
				$data['stylesheet'] = 'auth.css';
12700 anikendra 306
				$this->session->set_flashdata(array('msg'=>$data['response']['response']['messsage']));
307
				redirect(base_url().$data['response']['response']['fossignup']['redirect']);	
12694 anikendra 308
			}
309
		} else {
310
			$configdata =array();
311
			$configdata = $this->config->item('fossignup');
312
			unset($configdata['response'][1]);
313
			$cachemodule = array('header','footer','response');
314
			$configdata = getCache($configdata,$cachemodule);
315
			$data = array();
316
			$data['response']=$this->fos_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
317
			$this->lessphp->object()->ccompile('assets/css/shipping.less','assets/css/shipping.css');
318
			$data['stylesheet'] = 'shipping.css';
319
			$data['title'] = 'Register Counter';
320
			if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
321
			{
322
				foreach($cachemodule as $cm)
323
				{
324
					if(isset($configdata[$cm]) and !empty($configdata[$cm]))
325
					{
326
						$data['response'][$cm]=$configdata[$cm];
327
					}
328
				}
329
			}
330
			setCache($configdata['module'],$cachemodule,$data['response']);
331
			$this->layout->view(strtolower(__CLASS__).'/signupcounter',$data);
332
		}
333
    }
334
 
335
    function thanks() {
336
    	$configdata = $this->config->item('fos_dashboard');
337
		$cachemodule = array('header','footer');
338
	    $configdata = getCache($configdata,$cachemodule);
339
	    //end of get cache
340
	    $this->lessphp->object()->ccompile('assets/css/recharge.less','assets/css/recharge.css');
341
	    $data['stylesheet'] = 'recharge.css';
342
	    $data['title'] = 'Dashboard';
12700 anikendra 343
	    $data['username'] = $this->session->userdata('username');
344
	    $data['countercode'] = $this->session->userdata('countercode');	    
12694 anikendra 345
	    $data['response']=$this->fos_model->getDashboard($this->input->get(),$this->input->post(),$this->config->item('fos_dashboard'));
346
		$this->layout->view(strtolower(__CLASS__).'/thanks',$data);
347
    }
348
}