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