<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
* 系统设置相关
*/
class Sys extends MY_Controller
{
	
	function __construct()
	{
		parent::__construct();
	}

	/**
	*	修改用户密码
	*/
	public function changepwd()
	{
		$this->load->view('sys/index', $data);
	}

	/**
	*	更改密码
	*/
	public function actionchange()
	{
		$username 	= get_cookie('username');
		$oldpwd		= md5( $this->input->post('oldpwd') );
		$newpwd1	= $this->input->post('newpwd1');
		$newpwd2	= $this->input->post('newpwd2');

		$this->load->database();
		$query = $this->db->query("SELECT * FROM cmsadmin WHERE username = '{$username}'");
		$row = $query->row_array();
		$dbpwd = $row['pwd'];
		if ($oldpwd != $dbpwd) {
			die(json_encode(array('code' => -1, 'row' => $row, 'oldpwd' => $oldpwd, 'query' => $query)));
		}

		if ($newpwd1 != $newpwd2) {
			die(json_encode(array('code' => -2)));
		}

		//修改新密码
		$update = array('pwd' => md5($newpwd1));
		$this->db->where('username', $username);
		$this->db->update('cmsadmin', $update);

		//删除
		delete_cookie('username');
		delete_cookie('chinesename');

		die(json_encode(array('code' => 1)));
	}
}