<?php
namespace app\admin\controller;
use  app\model\Master as MasterModel;

class Master extends AdminController{

    // 修改密码
    public function pass(){
        return view() ;
    }

    public function modPass(){

        $d = request()->post();

        $validated = $this->validate($d,'Master.pass');
        if( $validated !== true ){
            return $this->responseError($validated);
        }

        $user = MasterModel::find($this->user['id']) ;

        if( $user->userpass !== MasterModel::entrySalt($d['userpass'] , $user->salt) ){
            return $this->responseError('旧密码错误');
        }

        $user->userpass = MasterModel::entrySalt($d['nuserpass'],$user->salt);
        $rs = $user->save();

        if( $rs !== FALSE ){
            return $this->responseSuccess('修改成功');
        }

        return $this->responseError('修改失败');
    }
}
