<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Agent\Controller;

/**
 * 后台用户设置控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class AccountController extends AdminController {

    /*
     * 管理员Edit personal information
    */
    public function update(){
        if(IS_POST){
            $model = D('Agent');
            $info = $model->getUserInfo(UID);
            $oldpwd = md5(I('oldpassword',''));
            if($oldpwd!=$info['password'])
                $this->error('The current password is incorrect');
            if($data=$model->create()){
                $status = $model->save($data);
                if($status){
                    $this->success('Edit personal information succeeded',U('index'));
                }else{
                    $this->error('Failure to edit personal information');
                }
            }else{
                $message = $model->getError();
                $this->error($message);
            }

        } else {
            $info = D('Agent')->getUserInfo(UID);
            $this->assign('info',$info);
            $this->meta_title = 'Edit personal information';
            $this->display('update');
        }
    }

}