<?php

	namespace app\admin\controller;
	use cmf\controller\AdminBaseController;
	use think\Db;
	class IndexController extends AdminBaseController {

		public function index(){
			$this->assign('dhxz',1);
			$this->assign('title','我的桌面');
			$user = Db::name('user')->field('avatar,user_nickname,last_login_time')->order('last_login_time desc')->limit(6)->select();
			$this->assign('user',$user);
			return $this->fetch();
		}

		//修改密码
		public function password(){
			if ($this->request->isPost()) {
				$admin_user_info = session('admin_user_info');
				$shuju = $this->request->param();
				$password1 = empty($shuju['password1']) ? '' : $shuju['password1'];
				$password2 = empty($shuju['password2']) ? '' : $shuju['password2'];
				if ($password1 != $password2) {
					$data = array('status'=>0,'info'=>'两次输入的密码不相同');
				} else {
					if ($password1) {
						if (cmf_compare_password($password1, $admin_user_info['user_pass'])) {
							$data = array('status'=>0,'info'=>'密码未变动！');
						} else {
							$isok = Db::name('user')->where(array('id'=>$admin_user_info['id']))->setField('user_pass',cmf_password($password1));
							if ($isok) {
								$data = array('status'=>1,'info'=>'修改成功！');
							} else {
								$data = array('status'=>0,'info'=>'修改失败！');
							}
						}
					} else {
						$data = array('status'=>0,'info'=>'请输入密码！');
					}
				}
				return json($data);
			} else {
				return $this->fetch();
			}
		}

	}