<commit_before><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); //防止用户直接访问

class User extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('Http_model');
	}
	function userList()
	{
		$data['pageTitle'] = '所有用户';
		$this->load->model('User_model');
		$data['userList'] = $this->User_model->getAll();
		$this->load->view('admin_header',$data);		
		$this->load->view('user_list');
		$this->load->view('admin_footer');
	}
	function registerPage(){
		$data['pageTitle']='添加用户';
		$this->load->view('admin_header',$data);
		$this->load->view('add_user');
		$this->load->view('admin_footer');
	}
	function register(){
		$this->load->model('User_model');
		$data['name']=$_POST['name'];
		$data['university']=$_POST['university'];
		$data['email'] = $_POST['email'];
		date_default_timezone_set('PRC');
		$data['createTime'] = date('Y-m-d h:i:s');

		if(empty($name)){
			$time = 3;
			header("refresh:$time;url=registerPage");
			print('信息错误，添加失败...<br>'.$time.'秒后自动跳转。');
		}
		if (!$this->User_model->add($data)) {
			$time = 3;
			header("refresh:$time;url=registerPage");
			print('信息错误，添加失败...<br>'.$time.'秒后自动跳转。');
		}else{
			redirect('user/userList');
		}
	}
	function loginPage(){
		$this->load->view('userHeader');
		$this->load->view('userLogin');
		$this->load->view('userFooter');
	}
	function login(){
		$this->load->model('User_model');
		$name = $_POST['name'];
		$user = $this->User_model->searchByName($name);
		if($user){
			session_start();
			$_SESSION['user'] = $user;	
			redirect('user/orderPage');
		}else{
			$time = 3;
			header("refresh:$time;url=loginPage");
			print('用户名错误，登陆失败...<br>'.$time.'秒后自动跳转。');
		}
	}
	function orderPage(){
			$this->checkLogin();

		  	$data['pageTitle'] = 'All Orders';
			$this->load->view('userHeader',$data);
			$this->load->view('addOrder');
			$this->load->view('userFooter');
	}
	function checkLogin(){
		if(isset($_GET['code'])) {
			$appid = 'wxcd901e4412fc040b';
			$appsecret = '16a24c163a44ee41fa3ef630c1c455ec';
			$code = $_GET['code'];
			$para = array('appid'=>$appid, 'secret'=>$appsecret, 'code'=>$code, 'grant_type'=>'authorization_code');
			$ret = $this->Http_model->doCurlGetRequest('https://api.weixin.qq.com/sns/oauth2/access_token',$para);
		  	$retData = json_decode($ret);

		  	$openid = $retData['openid'];
		  	$access_token = $retData['access_token'];

		  	$this->load->model('User_model');
		  	$this->load->model('Weixin_model');
		  	$result = $this->User_model->searchById($openid);
		  	if(isset($result[0])){
		  		$user = $result[0];
		  	}else{
		  		$user = $this->Weixin_model->getFollowerInfo($openid);
		  		if(isset($user['errorcode'])){
		  			echo '登陆失败, 请关闭网页重连';
					exit(0);
		  		}
		  		date_default_timezone_set('PRC');
		  		$user['createTime'] = date('Y-m-d h:i:s'); 
		  		$this->User_model->add($user);
		  	}
	  		if (!session_id()) session_start();<commit_msg>fix json_decode bug<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); //防止用户直接访问

class User extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('Http_model');
	}
	function userList()
	{
		$data['pageTitle'] = '所有用户';
		$this->load->model('User_model');
		$data['userList'] = $this->User_model->getAll();
		$this->load->view('admin_header',$data);		
		$this->load->view('user_list');
		$this->load->view('admin_footer');
	}
	function registerPage(){
		$data['pageTitle']='添加用户';
		$this->load->view('admin_header',$data);
		$this->load->view('add_user');
		$this->load->view('admin_footer');
	}
	function register(){
		$this->load->model('User_model');
		$data['name']=$_POST['name'];
		$data['university']=$_POST['university'];
		$data['email'] = $_POST['email'];
		date_default_timezone_set('PRC');
		$data['createTime'] = date('Y-m-d h:i:s');

		if(empty($name)){
			$time = 3;
			header("refresh:$time;url=registerPage");
			print('信息错误，添加失败...<br>'.$time.'秒后自动跳转。');
		}
		if (!$this->User_model->add($data)) {
			$time = 3;
			header("refresh:$time;url=registerPage");
			print('信息错误，添加失败...<br>'.$time.'秒后自动跳转。');
		}else{
			redirect('user/userList');
		}
	}
	function loginPage(){
		$this->load->view('userHeader');
		$this->load->view('userLogin');
		$this->load->view('userFooter');
	}
	function login(){
		$this->load->model('User_model');
		$name = $_POST['name'];
		$user = $this->User_model->searchByName($name);
		if($user){
			session_start();
			$_SESSION['user'] = $user;	
			redirect('user/orderPage');
		}else{
			$time = 3;
			header("refresh:$time;url=loginPage");
			print('用户名错误，登陆失败...<br>'.$time.'秒后自动跳转。');
		}
	}
	function orderPage(){
			$this->checkLogin();

		  	$data['pageTitle'] = 'All Orders';
			$this->load->view('userHeader',$data);
			$this->load->view('addOrder');
			$this->load->view('userFooter');
	}
	function checkLogin(){
		if(isset($_GET['code'])) {
			$appid = 'wxcd901e4412fc040b';
			$appsecret = '16a24c163a44ee41fa3ef630c1c455ec';
			$code = $_GET['code'];
			$para = array('appid'=>$appid, 'secret'=>$appsecret, 'code'=>$code, 'grant_type'=>'authorization_code');
			$ret = $this->Http_model->doCurlGetRequest('https://api.weixin.qq.com/sns/oauth2/access_token',$para);
		  	$retData = json_decode($ret, true);

		  	$openid = $retData['openid'];
		  	$access_token = $retData['access_token'];

		  	$this->load->model('User_model');
		  	$this->load->model('Weixin_model');
		  	$result = $this->User_model->searchById($openid);
		  	if(isset($result[0])){
		  		$user = $result[0];
		  	}else{
		  		$user = $this->Weixin_model->getFollowerInfo($openid);
		  		if(isset($user['errorcode'])){
		  			echo '登陆失败, 请关闭网页重连';
					exit(0);
		  		}
		  		date_default_timezone_set('PRC');
		  		$user['createTime'] = date('Y-m-d h:i:s'); 
		  		$this->User_model->add($user);
		  	}
	  		if (!session_id()) session_start();
{'fraction_non_alphanumeric': 0.23824714573539288, 'fraction_numerical': 0.01208865010073875, 'mean_word_length': 4.641098484848484, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 123, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2247160', 'n_tokens_mistral': 2625, 'n_tokens_neox': 2410, 'n_words': 270}