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

class Action extends MY_Controller{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('admin_model');
    }

    public function revise()
    {
        $data['title'] = '修改密码';
        $this->_login_view('revisePwd',$data);
    }

    /**
     * [quit 退出]
     * @return [type] [description]
     */
    public function quit()
    {
        unset($_SESSION['userid']);
        unset($_SESSION['username']);
        redirect(base_url());
    }
    /**
     * [change 管理员密码修改]
     * @return [type] [description]
     */
    
    public function change()
    {
        // $rules_config = array(
        //     array(
        //         'field' => 'username',
        //         'label' => '用户名',
        //         'rules' => 'trim|required'
        //     ),
        //     array(
        //         'field' => 'oldpwd',
        //         'label' => '原密码',
        //         'rules' => 'trim|required'
        //     ),
        //     array(
        //         'field' => 'password',
        //         'label' => '登录密码',
        //         'rules' => 'trim|required|matches[passconf]'
        //     ), 
        //     array(
        //         'field' => 'passconf',
        //         'label' => '密码确认',
        //         'rules' => 'trim|required'
        //     )           
        // );
                
        // $this->load->library('form_validation',$rules_config);
        if( ! preg_match('/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$/',$this->input->post('password')))
        {
            return $this->json(0,'新密码为6-18位数字与字母组合');
        }

        if($this->input->post('password') === $this->input->post('oldpwd'))
        {
            return $this->json(0,'新密码不能和原密码一样');
        }

        if($this->input->post('password') !== $this->input->post('passconf') )
        {
            return $this->json(0,'两次密码不一致');
        }

        $bool = $this->admin_model->pwd_change($this->input->post('username',TRUE),$this->input->post('oldpwd'),$this->input->post('password'));
        if( ! $bool)
        {
            return $this->json(0,'请确认账号和原密码是否正确');
        }
        else
        {
            unset($_SESSION['userid']);
            unset($_SESSION['username']);
            return $this->json(1,'');
        }     
    }
}
/* End of file action.php */
/* Location: /application/controllers/admin/action.php */