| 10582 |
lgm |
1 |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
2 |
class Auth extends MY_Controller {
|
|
|
3 |
public $layoutName ='';
|
|
|
4 |
function __construct() {
|
|
|
5 |
|
|
|
6 |
// Call the CI_controller constructor
|
|
|
7 |
parent::__construct();
|
| 11108 |
lgm |
8 |
// $admin = $this->session->userdata('admin');
|
|
|
9 |
// if(!isset($admin) || empty($admin)) {
|
|
|
10 |
// redirect(base_url().'authorize');
|
|
|
11 |
// }
|
| 10582 |
lgm |
12 |
$this->output->set_header("HTTP/1.0 200 OK");
|
|
|
13 |
$this->output->set_header("HTTP/1.1 200 OK");
|
|
|
14 |
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()).' GMT');
|
|
|
15 |
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
|
|
|
16 |
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
|
|
|
17 |
$this->output->set_header("Pragma: no-cache");
|
|
|
18 |
$this->layout->setlayout('layout/layout_main');
|
|
|
19 |
$this->load->model('oauth_model');
|
|
|
20 |
$this->layoutName= $this->layout->getLayout();
|
|
|
21 |
$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
}
|
|
|
26 |
public function index()
|
|
|
27 |
{
|
|
|
28 |
$this->__oauthorization();
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
}
|
|
|
32 |
function __oauthorization()
|
|
|
33 |
{
|
|
|
34 |
//sample session storage.. later i will imporve security for login
|
|
|
35 |
$check =$this->session->userdata('authorize');
|
|
|
36 |
if(isset($check) and !empty($check) and $check['authority']='success')
|
|
|
37 |
{
|
|
|
38 |
redirect(base_url().'home');
|
|
|
39 |
}
|
|
|
40 |
else
|
|
|
41 |
{
|
|
|
42 |
$this->login();
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
}
|
|
|
47 |
function login()
|
|
|
48 |
{
|
|
|
49 |
//standard array
|
|
|
50 |
$data = array();
|
|
|
51 |
if (isset($_SERVER['HTTP_REFERER'])) {
|
|
|
52 |
if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {
|
|
|
53 |
$redirect = $_SERVER['HTTP_REFERER'];
|
|
|
54 |
$location = $this->session->userdata('location');
|
|
|
55 |
if(isset($location) && $location == 'shipping'){
|
|
|
56 |
$data['location'] = 'shipping';
|
|
|
57 |
$location = base_url().$location;
|
|
|
58 |
$this->session->set_userdata('location',$location);
|
| 11520 |
lgm |
59 |
}elseif(isset($location) && ($location == 'my-recharges' || $location == 'my-wallet')){
|
|
|
60 |
$location = base_url().$location;
|
|
|
61 |
$this->session->set_userdata('location',$location);
|
| 10582 |
lgm |
62 |
}else{
|
|
|
63 |
$this->session->set_userdata('location',$redirect);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
$authorized = $this->session->userdata('authorized');
|
|
|
69 |
if(isset($authorized) && !empty($authorized) && $authorized['isLoggedIn'] == 1){
|
|
|
70 |
redirect(base_url().'home');
|
|
|
71 |
}
|
|
|
72 |
//get cache
|
|
|
73 |
$authorized = $this->session->userdata('authorized');
|
|
|
74 |
if(isset($_POST) && !empty($_POST)){
|
|
|
75 |
if(isset($authorized) && !empty($authorized)){
|
|
|
76 |
$_POST['userId'] = $authorized['Id'];
|
|
|
77 |
$_POST['cartId'] = $authorized['cartId'];
|
|
|
78 |
if($authorized['isLoggedIn'] == 1){
|
|
|
79 |
$_POST['isLoggedIn'] = 'true';
|
|
|
80 |
}
|
|
|
81 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
82 |
$_POST['isLoggedIn'] = 'false';
|
|
|
83 |
}
|
|
|
84 |
}
|
| 11049 |
lgm |
85 |
//end of get cache
|
| 11171 |
lgm |
86 |
$configdata =array();
|
|
|
87 |
$configdata = $this->config->item('oauth_login');
|
|
|
88 |
unset($configdata['response'][0]);
|
|
|
89 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$configdata);
|
| 15750 |
anikendra |
90 |
//error_log(print_r($data['response']['response'],1));
|
| 11049 |
lgm |
91 |
//set cache to output or renew cache
|
|
|
92 |
if(isset($data['response']['response']['login']['authorized']))
|
| 10582 |
lgm |
93 |
{
|
| 11049 |
lgm |
94 |
$this->session->set_userdata('authorized',$data['response']['response']['login']['authorized']);
|
|
|
95 |
//$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));
|
|
|
96 |
$location = $this->session->userdata('location');
|
|
|
97 |
if(isset($location) && !empty($location)){
|
|
|
98 |
$this->session->unset_userdata('location');
|
|
|
99 |
redirect($location);
|
| 10582 |
lgm |
100 |
}
|
| 11049 |
lgm |
101 |
else{
|
|
|
102 |
redirect(base_url().$data['response']['response']['login']['redirect']);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
|
| 10582 |
lgm |
106 |
}
|
| 11049 |
lgm |
107 |
else
|
|
|
108 |
{
|
|
|
109 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
|
|
110 |
$data['title'] = 'Saholic';
|
|
|
111 |
$data['stylesheet'] = 'auth.css';
|
|
|
112 |
$this->layout->view(strtolower(__CLASS__).'/oauth_view',$data);
|
| 10582 |
lgm |
113 |
}
|
|
|
114 |
}
|
| 11049 |
lgm |
115 |
else{
|
| 11171 |
lgm |
116 |
$configdata =array();
|
|
|
117 |
$configdata = $this->config->item('oauth_login');
|
|
|
118 |
unset($configdata['response'][1]);
|
|
|
119 |
$cachemodule = array('header','footer','response');
|
|
|
120 |
$configdata = getCache($configdata,$cachemodule);
|
| 11049 |
lgm |
121 |
$data = array();
|
| 11171 |
lgm |
122 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
|
| 10582 |
lgm |
123 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
| 11012 |
lgm |
124 |
$data['title'] = 'Saholic';
|
| 10582 |
lgm |
125 |
$data['stylesheet'] = 'auth.css';
|
| 11171 |
lgm |
126 |
if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
|
|
|
127 |
{
|
|
|
128 |
foreach($cachemodule as $cm)
|
|
|
129 |
{
|
|
|
130 |
if(isset($configdata[$cm]) and !empty($configdata[$cm]))
|
|
|
131 |
{
|
|
|
132 |
$data['response'][$cm]=$configdata[$cm];
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
setCache($configdata['module'],$cachemodule,$data['response']);
|
| 11049 |
lgm |
137 |
$this->layout->view(strtolower(__CLASS__).'/login',$data);
|
| 10582 |
lgm |
138 |
}
|
|
|
139 |
}
|
|
|
140 |
function signup()
|
|
|
141 |
{
|
|
|
142 |
//standard array
|
|
|
143 |
$authorized = $this->session->userdata('authorized');
|
|
|
144 |
if(isset($authorized) && !empty($authorized) && $authorized['isLoggedIn'] == 1){
|
|
|
145 |
redirect(base_url().'home');
|
|
|
146 |
}
|
|
|
147 |
$data = array();
|
|
|
148 |
if (isset($_SERVER['HTTP_REFERER'])) {
|
|
|
149 |
if ((strpos($_SERVER['HTTP_REFERER'],'login') == false) && (strpos($_SERVER['HTTP_REFERER'],'register') == false)) {
|
|
|
150 |
$redirect = $_SERVER['HTTP_REFERER'];
|
|
|
151 |
$location = $this->session->userdata('location');
|
|
|
152 |
if(isset($location) && $location == 'shipping'){
|
|
|
153 |
$data['location'] = 'shipping';
|
|
|
154 |
$this->session->set_userdata('location',$location);
|
| 11520 |
lgm |
155 |
}elseif(isset($location) && ($location == 'my-recharges' || $location == 'my-wallet')){
|
|
|
156 |
$location = base_url().$location;
|
|
|
157 |
$this->session->set_userdata('location',$location);
|
| 10582 |
lgm |
158 |
}else{
|
|
|
159 |
$this->session->set_userdata('location',$redirect);
|
|
|
160 |
}
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
//get cache
|
|
|
164 |
$authorized = $this->session->userdata('authorized');
|
|
|
165 |
if(isset($_POST) && !empty($_POST)){
|
|
|
166 |
if(isset($authorized) && !empty($authorized)){
|
|
|
167 |
$_POST['userId'] = $authorized['Id'];
|
|
|
168 |
$_POST['Id'] = $authorized['cartId'];
|
|
|
169 |
if($authorized['isLoggedIn'] == 1){
|
|
|
170 |
$_POST['isLoggedIn'] = 'true';
|
|
|
171 |
}
|
|
|
172 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
173 |
$_POST['isLoggedIn'] = 'false';
|
|
|
174 |
}
|
|
|
175 |
}
|
| 11049 |
lgm |
176 |
|
| 11171 |
lgm |
177 |
$configdata =array();
|
|
|
178 |
$configdata = $this->config->item('oauth_signup');
|
|
|
179 |
unset($configdata['response'][0]);
|
|
|
180 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$configdata);
|
| 15750 |
anikendra |
181 |
//error_log(print_r($data['response']['response'],1));
|
| 11049 |
lgm |
182 |
//set cache to output or renew cache
|
|
|
183 |
if(isset($data['response']['response']['signup']['authorized']))
|
| 10582 |
lgm |
184 |
{
|
| 11049 |
lgm |
185 |
$this->session->set_userdata('authorized',$data['response']['response']['signup']['authorized']);
|
|
|
186 |
$this->session->set_flashdata(array('msg'=>$data['response']['response']['signup']['msg']));
|
|
|
187 |
$location = $this->session->userdata('location');
|
|
|
188 |
if(isset($location) && !empty($location)){
|
|
|
189 |
$this->session->unset_userdata('location');
|
|
|
190 |
redirect($location);
|
| 10582 |
lgm |
191 |
}
|
| 11049 |
lgm |
192 |
redirect(base_url().$data['response']['response']['signup']['redirect']);
|
| 10582 |
lgm |
193 |
}
|
| 11049 |
lgm |
194 |
else
|
|
|
195 |
{
|
|
|
196 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
|
|
197 |
$data['title'] = 'Saholic';
|
|
|
198 |
$data['stylesheet'] = 'auth.css';
|
|
|
199 |
$this->layout->view(strtolower(__CLASS__).'/oauth_view',$data);
|
| 10582 |
lgm |
200 |
}
|
| 11049 |
lgm |
201 |
}else{
|
| 11171 |
lgm |
202 |
$configdata =array();
|
|
|
203 |
$configdata = $this->config->item('oauth_signup');
|
|
|
204 |
unset($configdata['response'][1]);
|
|
|
205 |
$cachemodule = array('header','footer','response');
|
|
|
206 |
$configdata = getCache($configdata,$cachemodule);
|
| 11049 |
lgm |
207 |
$data = array();
|
| 11171 |
lgm |
208 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
|
| 10582 |
lgm |
209 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
| 11012 |
lgm |
210 |
$data['title'] = 'Saholic';
|
| 10582 |
lgm |
211 |
$data['stylesheet'] = 'auth.css';
|
| 11171 |
lgm |
212 |
if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
|
|
|
213 |
{
|
|
|
214 |
foreach($cachemodule as $cm)
|
|
|
215 |
{
|
|
|
216 |
if(isset($configdata[$cm]) and !empty($configdata[$cm]))
|
|
|
217 |
{
|
|
|
218 |
$data['response'][$cm]=$configdata[$cm];
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
setCache($configdata['module'],$cachemodule,$data['response']);
|
| 11049 |
lgm |
223 |
$this->layout->view(strtolower(__CLASS__).'/signup',$data);
|
| 10582 |
lgm |
224 |
}
|
|
|
225 |
}
|
|
|
226 |
function logout()
|
|
|
227 |
{
|
|
|
228 |
|
|
|
229 |
$authorized = $this->session->userdata('authorized');
|
|
|
230 |
if(isset($authorized) and !empty($authorized))
|
|
|
231 |
{
|
| 16276 |
amit.gupta |
232 |
$this->session->sess_destroy();
|
| 10582 |
lgm |
233 |
redirect(base_url().'home');
|
|
|
234 |
|
|
|
235 |
}
|
|
|
236 |
}
|
| 11677 |
lgm |
237 |
|
|
|
238 |
function changePassword()
|
|
|
239 |
{
|
|
|
240 |
//standard array
|
|
|
241 |
$data = array();
|
|
|
242 |
$authorized = $this->session->userdata('authorized');
|
|
|
243 |
// if(isset($authorized) && !empty($authorized) && $authorized['isLoggedIn'] == 1){
|
|
|
244 |
// redirect(base_url().'home');
|
|
|
245 |
// }
|
|
|
246 |
//get cache
|
|
|
247 |
$authorized = $this->session->userdata('authorized');
|
|
|
248 |
if(isset($_POST) && !empty($_POST)){
|
|
|
249 |
// print_r($_POST);
|
|
|
250 |
// die();
|
|
|
251 |
if(isset($authorized) && !empty($authorized)){
|
|
|
252 |
$_POST['userId'] = $authorized['Id'];
|
|
|
253 |
$_POST['cartId'] = $authorized['cartId'];
|
|
|
254 |
if($authorized['isLoggedIn'] == 1){
|
|
|
255 |
$_POST['isLoggedIn'] = 'true';
|
|
|
256 |
}
|
|
|
257 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
258 |
$_POST['isLoggedIn'] = 'false';
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
//end of get cache
|
|
|
262 |
$configdata =array();
|
|
|
263 |
$configdata = $this->config->item('change_password');
|
|
|
264 |
unset($configdata['response'][0]);
|
|
|
265 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$configdata);
|
|
|
266 |
//set cache to output or renew cache
|
|
|
267 |
if(isset($data['response']['response']['changePassword']))
|
|
|
268 |
{
|
|
|
269 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
|
|
270 |
$data['title'] = 'Saholic';
|
|
|
271 |
$data['stylesheet'] = 'auth.css';
|
|
|
272 |
$this->layout->view(strtolower(__CLASS__).'/oauth_view',$data);
|
|
|
273 |
|
|
|
274 |
}
|
|
|
275 |
else
|
|
|
276 |
{
|
|
|
277 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
|
|
278 |
$data['title'] = 'Saholic';
|
|
|
279 |
$data['stylesheet'] = 'auth.css';
|
|
|
280 |
$this->layout->view(strtolower(__CLASS__).'/oauth_view',$data);
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
else{
|
|
|
284 |
// echo 'inside else';
|
|
|
285 |
// die();
|
|
|
286 |
$configdata =array();
|
|
|
287 |
$configdata = $this->config->item('change_password');
|
|
|
288 |
unset($configdata['response'][1]);
|
|
|
289 |
$cachemodule = array('header','footer','response');
|
|
|
290 |
$configdata = getCache($configdata,$cachemodule);
|
|
|
291 |
$data = array();
|
|
|
292 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$configdata['module']);
|
|
|
293 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
|
|
294 |
$data['title'] = 'Saholic';
|
|
|
295 |
$data['stylesheet'] = 'auth.css';
|
|
|
296 |
if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
|
|
|
297 |
{
|
|
|
298 |
foreach($cachemodule as $cm)
|
|
|
299 |
{
|
|
|
300 |
if(isset($configdata[$cm]) and !empty($configdata[$cm]))
|
|
|
301 |
{
|
|
|
302 |
$data['response'][$cm]=$configdata[$cm];
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
}
|
|
|
306 |
setCache($configdata['module'],$cachemodule,$data['response']);
|
|
|
307 |
$this->layout->view(strtolower(__CLASS__).'/changePassword',$data);
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
|
| 10582 |
lgm |
311 |
function forgotPassword($email)
|
|
|
312 |
{
|
|
|
313 |
|
|
|
314 |
$authorized = $this->session->userdata('authorized');
|
|
|
315 |
if(!isset($authorized['isLoggedIn']) || ($authorized['isLoggedIn'] != 1))
|
|
|
316 |
{
|
|
|
317 |
if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){
|
|
|
318 |
$configUrl = $this->config->item('forgotpassword');
|
|
|
319 |
$configUrl = $configUrl['url'];
|
|
|
320 |
$url = $this->config->item('curl_base_url').$configUrl;
|
|
|
321 |
$params['emailId'] = $email;
|
|
|
322 |
$this->mcurl->add_call('forgotPassword','post',$url,$params);
|
|
|
323 |
$response = $this->mcurl->execute($url);
|
|
|
324 |
$data['response'] = $response['forgotPassword']['response'];
|
|
|
325 |
print_r($data['response']);
|
|
|
326 |
}
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
//social login process
|
|
|
331 |
public function session($provider)
|
| 11631 |
lgm |
332 |
{
|
| 10582 |
lgm |
333 |
// if (isset($_SERVER['HTTP_REFERER'])) {
|
|
|
334 |
// if(strpos($_SERVER['HTTP_REFERER'],'session') == false) {
|
|
|
335 |
// $location = $_SERVER['HTTP_REFERER'];
|
|
|
336 |
// $this->session->set_userdata('location',$location);
|
|
|
337 |
// }
|
|
|
338 |
// }
|
|
|
339 |
$type = $provider;
|
|
|
340 |
$this->load->helper('url_helper');
|
|
|
341 |
$social =$this->config->item('oauth_social');
|
|
|
342 |
|
|
|
343 |
$this->load->spark('oauth2/0.4.0');
|
|
|
344 |
|
|
|
345 |
$provider = $this->oauth2->provider($provider, array(
|
|
|
346 |
'id' => $social[$provider]['id'],
|
|
|
347 |
'secret' => $social[$provider]['secretkey']
|
|
|
348 |
|
|
|
349 |
));
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
if ( ! $this->input->get('code'))
|
|
|
353 |
{
|
|
|
354 |
if($this->input->get('error')) {
|
|
|
355 |
redirect(base_url());
|
|
|
356 |
}else{
|
|
|
357 |
redirect($provider->authorize());
|
|
|
358 |
}
|
|
|
359 |
// By sending no options it'll come back here
|
|
|
360 |
}
|
|
|
361 |
else
|
|
|
362 |
{
|
|
|
363 |
try
|
|
|
364 |
{
|
|
|
365 |
//manage login operation here and redirect to perspective link
|
|
|
366 |
$token = $provider->access($_GET['code']);
|
|
|
367 |
|
|
|
368 |
$user = $provider->get_user_info($token);
|
|
|
369 |
if(strcasecmp('facebook', $type) == 0){
|
|
|
370 |
$_POST['isFacebookUser'] = 'true';
|
|
|
371 |
$_POST['accessToken'] = $user['access_token'];
|
|
|
372 |
$_POST['facebookId'] = $user['uid'];
|
|
|
373 |
$_POST['email'] = $user['email'];
|
| 11631 |
lgm |
374 |
if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST['email'])) {
|
|
|
375 |
$authorized = $this->session->userdata('authorized');
|
|
|
376 |
if(isset($_POST) && !empty($_POST)){
|
|
|
377 |
if(isset($authorized) && !empty($authorized)){
|
|
|
378 |
$_POST['userId'] = $authorized['Id'];
|
|
|
379 |
$_POST['Id'] = $authorized['cartId'];
|
|
|
380 |
if($authorized['isLoggedIn'] == 1){
|
|
|
381 |
$_POST['isLoggedIn'] = 'true';
|
|
|
382 |
}
|
|
|
383 |
elseif(isset($authorized['isLoggedIn']) && empty($authorized['isLoggedIn'])) {
|
|
|
384 |
$_POST['isLoggedIn'] = 'false';
|
|
|
385 |
}
|
| 10582 |
lgm |
386 |
}
|
| 11631 |
lgm |
387 |
}
|
|
|
388 |
$data['response']=$this->oauth_model->getLogin($this->input->get(),$this->input->post(),$this->config->item('oauth_login'));
|
|
|
389 |
if(isset($data['response']['response']['login']['authorized']))
|
|
|
390 |
{
|
|
|
391 |
$this->session->set_userdata('authorized',$data['response']['response']['login']['authorized']);
|
|
|
392 |
$this->session->set_flashdata(array('msg'=>$data['response']['response']['login']['msg']));
|
|
|
393 |
$location = $this->session->userdata('location');
|
|
|
394 |
if(isset($location) && !empty($location)){
|
|
|
395 |
$this->session->unset_userdata('location');
|
|
|
396 |
redirect($location);
|
| 10582 |
lgm |
397 |
}
|
| 11631 |
lgm |
398 |
else{
|
|
|
399 |
redirect(base_url().$data['response']['response']['login']['redirect']);
|
|
|
400 |
}
|
| 10582 |
lgm |
401 |
}
|
| 11631 |
lgm |
402 |
else
|
|
|
403 |
{
|
|
|
404 |
$inputfile = base_url().'assets/css/auth.less';
|
|
|
405 |
$outputfile = base_url().'assets/css/auth.less';
|
|
|
406 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
|
|
407 |
$data['stylesheet'] = 'auth.css';
|
|
|
408 |
$this->layout->view(strtolower(__CLASS__).'/oauth_view',$data);
|
|
|
409 |
}
|
|
|
410 |
}else{
|
|
|
411 |
$this->session->set_flashdata(array('msg'=>'Some problem occured.Please try again!'));
|
|
|
412 |
redirect(base_url().'login');
|
| 10582 |
lgm |
413 |
}
|
|
|
414 |
}
|
|
|
415 |
// Here you should use this information to A) look for a user B) help a new user sign up with existing data.
|
|
|
416 |
// If you store it all in a cookie and redirect to a registration page this is crazy-simple.
|
|
|
417 |
//echo "<pre>Tokens: ";
|
|
|
418 |
//var_dump($token);
|
|
|
419 |
|
|
|
420 |
//echo "\n\nUser Info: ";
|
|
|
421 |
//var_dump($user);
|
|
|
422 |
}
|
|
|
423 |
|
|
|
424 |
catch (OAuth2_Exception $e)
|
|
|
425 |
{
|
|
|
426 |
show_error('That didnt work: '.$e);
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
|
| 14868 |
anikendra |
432 |
public function autologin() {
|
|
|
433 |
$getdata = $this->input->get();
|
|
|
434 |
//error_log(print_r($getdata,true));
|
| 15348 |
anikendra |
435 |
// $configdata = $this->config->item('gosf');
|
|
|
436 |
// $this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
| 14868 |
anikendra |
437 |
if(isset($getdata['data']) && !empty($getdata['data'])){
|
|
|
438 |
$data = $getdata['data'];
|
|
|
439 |
} else{
|
|
|
440 |
// $this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
|
|
|
441 |
redirect(base_url().'home');
|
|
|
442 |
}
|
|
|
443 |
$userData = unserialize(base64_decode($data));
|
|
|
444 |
if(isset($getdata['next']) && !empty($getdata['next'])){
|
|
|
445 |
$userData['next'] = $getdata['next'];
|
|
|
446 |
}
|
|
|
447 |
$userData['next'] = str_replace('&next=','',$userData['next']);
|
|
|
448 |
$authorized = $this->session->userdata('authorized');
|
|
|
449 |
//check if user is already logged in
|
| 15348 |
anikendra |
450 |
if(isset($authorized) && !empty($authorized) && $authorized['isLoggedIn'] == 1){
|
|
|
451 |
// $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
|
|
|
452 |
redirect(base_url().$userData['next']);
|
|
|
453 |
}
|
|
|
454 |
if(isset($getdata['v']) && !empty($getdata['v'])){
|
|
|
455 |
$url = $this->config->item('profitmandi_token_validation_url').$getdata['token'];
|
| 15354 |
anikendra |
456 |
error_log("token validation url ".$url);
|
| 15348 |
anikendra |
457 |
$ch = curl_init();
|
|
|
458 |
// Now set some options (most are optional)
|
|
|
459 |
// Set URL to download
|
|
|
460 |
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
461 |
// User agent
|
|
|
462 |
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
|
|
|
463 |
// Include header in result? (0 = yes, 1 = no)
|
|
|
464 |
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
465 |
// Should cURL return or print out the data? (true = return, false = print)
|
|
|
466 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
467 |
// Timeout in seconds
|
|
|
468 |
// curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
|
469 |
// Download the given URL, and return output
|
|
|
470 |
$output = curl_exec($ch);
|
|
|
471 |
// Close the cURL resource, and free system resources
|
|
|
472 |
curl_close($ch);
|
|
|
473 |
$response = json_decode($output,1);
|
|
|
474 |
error_log(print_r($response,1));
|
|
|
475 |
if(empty($response) || !$response['validToken']){
|
|
|
476 |
error_log("not authenticated");
|
|
|
477 |
redirect(base_url().$userData['next']);
|
|
|
478 |
}
|
|
|
479 |
if(!empty($response) && $response['validToken']){
|
|
|
480 |
$userData['isLoggedIn'] = true;
|
|
|
481 |
$this->session->set_userdata('authorized',$userData);
|
|
|
482 |
error_log("authenticated user ".print_r($userData,1));
|
|
|
483 |
redirect(base_url().$userData['next']);
|
|
|
484 |
}
|
|
|
485 |
}
|
|
|
486 |
// $userData['stylesheet'] = 'auth.css';
|
|
|
487 |
// $userData['title'] = 'Saholic';
|
| 14868 |
anikendra |
488 |
// if(isset($userData['next']) && !empty($userData['next'])){
|
|
|
489 |
// $next = $userData['next'];
|
|
|
490 |
// $this->session->set_userdata('location',$next);
|
|
|
491 |
// }
|
|
|
492 |
if(isset($getdata['token']) && !empty($getdata['token'])){
|
|
|
493 |
$token = $getdata['token'];
|
| 15348 |
anikendra |
494 |
} else{
|
|
|
495 |
redirect(base_url().$userData['next']);
|
| 14868 |
anikendra |
496 |
}
|
|
|
497 |
$hash = md5("21dtr022015|".$userData['Id']);
|
|
|
498 |
//error_log(print_r($hash,true));
|
|
|
499 |
if($hash != $token){
|
|
|
500 |
// $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
|
|
|
501 |
redirect(base_url().$userData['next']);
|
| 15348 |
anikendra |
502 |
}
|
| 14868 |
anikendra |
503 |
$userData['isLoggedIn'] = true;
|
|
|
504 |
$this->session->set_userdata('authorized',$userData);
|
| 15348 |
anikendra |
505 |
redirect(base_url().$userData['next']);
|
| 14868 |
anikendra |
506 |
// error_log("cookie ".print_r($_COOKIE,true));
|
| 15348 |
anikendra |
507 |
// $location = $this->session->userdata('location');
|
|
|
508 |
// if(isset($location) && !empty($location)){
|
|
|
509 |
// $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
|
|
|
510 |
// } else {
|
|
|
511 |
// $this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
|
|
|
512 |
// }
|
| 14868 |
anikendra |
513 |
}
|
|
|
514 |
|
|
|
515 |
/*
|
| 14165 |
anikendra |
516 |
public function autologin() {
|
| 14012 |
anikendra |
517 |
$getdata = $this->input->get();
|
| 15750 |
anikendra |
518 |
//error_log(print_r($getdata,true));
|
| 14165 |
anikendra |
519 |
$configdata = $this->config->item('gosf');
|
|
|
520 |
$this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
|
| 14442 |
anikendra |
521 |
if(isset($getdata['data']) && !empty($getdata['data'])){
|
| 14012 |
anikendra |
522 |
$data = $getdata['data'];
|
|
|
523 |
}else{
|
| 15750 |
anikendra |
524 |
//error_log("data not set");
|
| 14442 |
anikendra |
525 |
$this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
|
| 14456 |
anikendra |
526 |
}
|
|
|
527 |
$userData = unserialize(base64_decode($data));
|
| 15750 |
anikendra |
528 |
//error_log(print_r($userData,true));
|
| 14456 |
anikendra |
529 |
if(isset($getdata['next']) && !empty($getdata['next'])){
|
| 15750 |
anikendra |
530 |
//error_log("inside condition 1", 0);
|
|
|
531 |
//error_log(print_r($getdata['next'],true));
|
| 14456 |
anikendra |
532 |
$userData['next'] = $getdata['next'];
|
| 14012 |
anikendra |
533 |
}
|
| 14457 |
anikendra |
534 |
$userData['next'] = str_replace('&next=','',$userData['next']);
|
| 14442 |
anikendra |
535 |
$userData['stylesheet'] = 'auth.css';
|
|
|
536 |
$userData['title'] = 'Saholic';
|
| 15750 |
anikendra |
537 |
//error_log(print_r($userData,true));
|
| 14442 |
anikendra |
538 |
if(isset($userData['next']) && !empty($userData['next'])){
|
| 15750 |
anikendra |
539 |
//error_log("inside condition 2", 0);
|
| 14442 |
anikendra |
540 |
$next = $userData['next'];
|
|
|
541 |
$this->session->set_userdata('location',$next);
|
|
|
542 |
}
|
| 14012 |
anikendra |
543 |
if(isset($getdata['token']) && !empty($getdata['token'])){
|
|
|
544 |
$token = $getdata['token'];
|
| 15750 |
anikendra |
545 |
//error_log(print_r($token,true));
|
| 14012 |
anikendra |
546 |
}else{
|
| 14442 |
anikendra |
547 |
$this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
|
|
|
548 |
}
|
| 14165 |
anikendra |
549 |
$hash = md5("21dtr022015|".$userData['Id']);
|
| 15750 |
anikendra |
550 |
//error_log(print_r($hash,true));
|
| 14012 |
anikendra |
551 |
if($hash != $token){
|
| 15750 |
anikendra |
552 |
|
| 14442 |
anikendra |
553 |
$this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
|
| 14012 |
anikendra |
554 |
}
|
| 15750 |
anikendra |
555 |
error_log("inside condition 5", 0);
|
| 14165 |
anikendra |
556 |
$userData['isLoggedIn'] = true;
|
| 14012 |
anikendra |
557 |
$this->session->set_userdata('authorized',$userData);
|
| 15750 |
anikendra |
558 |
error_log("cookie ".print_r($_COOKIE,true));
|
| 14012 |
anikendra |
559 |
$location = $this->session->userdata('location');
|
|
|
560 |
if(isset($location) && !empty($location)){
|
| 15750 |
anikendra |
561 |
error_log("inside condition 6", 0);
|
|
|
562 |
// $this->session->unset_userdata('location');
|
| 14442 |
anikendra |
563 |
$this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
|
| 14012 |
anikendra |
564 |
}
|
|
|
565 |
else{
|
| 15750 |
anikendra |
566 |
error_log("inside condition 7", 0);
|
| 14442 |
anikendra |
567 |
$this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
|
| 14012 |
anikendra |
568 |
}
|
|
|
569 |
}
|
| 14868 |
anikendra |
570 |
*/
|
| 10582 |
lgm |
571 |
}
|
|
|
572 |
|
|
|
573 |
/***** FOR LOGIN AUTHENTICATION *****
|
|
|
574 |
* AUTHORIZE ARRAY + AUTHORIZE[AUTHORITY]=SUCCESS
|
|
|
575 |
* FOR SIGN UP -
|
|
|
576 |
*
|
|
|
577 |
*
|
|
|
578 |
|
|
|
579 |
/* End of file welcome.php */
|
| 15750 |
anikendra |
580 |
/* Location: ./application/controllers/welcome.php */
|