Subversion Repositories SmartDukaan

Rev

Rev 14868 | Rev 15354 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14868 Rev 15348
Line 438... Line 438...
438
    }
438
    }
439
 
439
 
440
    public function autologin() {
440
    public function autologin() {
441
        $getdata = $this->input->get();
441
        $getdata = $this->input->get();
442
        //error_log(print_r($getdata,true));
442
        //error_log(print_r($getdata,true));
443
        $configdata = $this->config->item('gosf');
443
        // $configdata = $this->config->item('gosf');
444
        $this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');
444
        // $this->lessphp->object()->ccompile('assets/css/auth.less','assets/css/auth.css');        
445
        if(isset($getdata['data']) && !empty($getdata['data'])){
445
        if(isset($getdata['data']) && !empty($getdata['data'])){
446
            $data = $getdata['data'];
446
            $data = $getdata['data'];
447
        } else{
447
        } else{
448
            // $this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
448
            // $this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
449
            redirect(base_url().'home');
449
            redirect(base_url().'home');
Line 453... Line 453...
453
            $userData['next'] = $getdata['next'];
453
            $userData['next'] = $getdata['next'];
454
        }
454
        }
455
        $userData['next'] = str_replace('&next=','',$userData['next']);
455
        $userData['next'] = str_replace('&next=','',$userData['next']);
456
        $authorized = $this->session->userdata('authorized');
456
        $authorized = $this->session->userdata('authorized');
457
        //check if user is already logged in
457
        //check if user is already logged in
458
		if(isset($authorized) && !empty($authorized) && $authorized['isLoggedIn'] == 1){
458
        if(isset($authorized) && !empty($authorized) && $authorized['isLoggedIn'] == 1){
459
			// $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
459
            // $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
-
 
460
            redirect(base_url().$userData['next']);
-
 
461
        }
-
 
462
        if(isset($getdata['v']) && !empty($getdata['v'])){
-
 
463
        	$url = $this->config->item('profitmandi_token_validation_url').$getdata['token'];
-
 
464
    	 	echo $url;
-
 
465
    	 	$ch = curl_init();
-
 
466
			// Now set some options (most are optional)
-
 
467
			// Set URL to download
-
 
468
			curl_setopt($ch, CURLOPT_URL, $url);
-
 
469
			// User agent
-
 
470
			curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
-
 
471
			// Include header in result? (0 = yes, 1 = no)
-
 
472
			curl_setopt($ch, CURLOPT_HEADER, 0);
-
 
473
			// Should cURL return or print out the data? (true = return, false = print)
-
 
474
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
475
			// Timeout in seconds
-
 
476
			// curl_setopt($ch, CURLOPT_TIMEOUT, 10);
-
 
477
			// Download the given URL, and return output
-
 
478
			$output = curl_exec($ch);
-
 
479
			// Close the cURL resource, and free system resources
-
 
480
			curl_close($ch);
-
 
481
			$response = json_decode($output,1);
-
 
482
			error_log(print_r($response,1));
-
 
483
			if(empty($response) || !$response['validToken']){
-
 
484
				error_log("not authenticated");
460
			redirect(base_url().$userData['next']);
485
				redirect(base_url().$userData['next']);	
-
 
486
			}
-
 
487
			if(!empty($response) && $response['validToken']){
-
 
488
				$userData['isLoggedIn'] = true;
-
 
489
		        $this->session->set_userdata('authorized',$userData);
-
 
490
		        error_log("authenticated user ".print_r($userData,1));
-
 
491
		        redirect(base_url().$userData['next']);
-
 
492
			}
461
		}        
493
        }        
462
        $userData['stylesheet'] = 'auth.css';
494
        // $userData['stylesheet'] = 'auth.css';
463
        $userData['title'] = 'Saholic';
495
        // $userData['title'] = 'Saholic';
464
        // if(isset($userData['next']) && !empty($userData['next'])){
496
        // if(isset($userData['next']) && !empty($userData['next'])){
465
            // $next = $userData['next'];
497
            // $next = $userData['next'];
466
            // $this->session->set_userdata('location',$next);
498
            // $this->session->set_userdata('location',$next);
467
        // }
499
        // }
468
        if(isset($getdata['token']) && !empty($getdata['token'])){
500
        if(isset($getdata['token']) && !empty($getdata['token'])){
469
            $token = $getdata['token'];
501
            $token = $getdata['token'];
470
        } else{
502
        } else{        
471
        	// $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
-
 
472
        	redirect(base_url().$userData['next']);
503
            redirect(base_url().$userData['next']);
473
        }
504
        }
474
        $hash = md5("21dtr022015|".$userData['Id']);
505
        $hash = md5("21dtr022015|".$userData['Id']);
475
        //error_log(print_r($hash,true));
506
        //error_log(print_r($hash,true));
476
        if($hash != $token){
507
        if($hash != $token){
477
            // $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
508
            // $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
478
            redirect(base_url().$userData['next']);
509
            redirect(base_url().$userData['next']);
479
        }       
510
        }
480
        $userData['isLoggedIn'] = true;
511
        $userData['isLoggedIn'] = true;
481
        $this->session->set_userdata('authorized',$userData);
512
        $this->session->set_userdata('authorized',$userData);
-
 
513
        redirect(base_url().$userData['next']);
482
        // error_log("cookie ".print_r($_COOKIE,true));
514
        // error_log("cookie ".print_r($_COOKIE,true));
483
        $location = $this->session->userdata('location');
515
        // $location = $this->session->userdata('location');
484
        if(isset($location) && !empty($location)){
516
        // if(isset($location) && !empty($location)){
485
            // error_log("inside condition 6", 0);
-
 
486
//          $this->session->unset_userdata('location');
-
 
487
            $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
517
            // $this->layout->view(strtolower(__CLASS__).'/autologin',$userData);
488
  		} else {
518
        // } else {
489
       	    // error_log("inside condition 7", 0);
-
 
490
            $this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
519
            // $this->layout->view(strtolower(__CLASS__).'/autologin',array('next'=>base_url()));
491
        }
520
        // }
492
    }
521
    }
493
 
522
 
494
/*
523
/*
495
    public function autologin() {    
524
    public function autologin() {    
496
    	$getdata = $this->input->get();
525
    	$getdata = $this->input->get();