<?php
/**
 * Created by JetBrains PhpStorm.
 * User: yzxh24
 * Date: 12-2-6
 * Time: 下午4:36
 * To change this template use File | Settings | File Templates.
 */
class PasswordAction extends BaseAction
{
    public function run()
    {
        $model = Manager::model()->findByPk(Yii::app()->adminUser->id);
        if ($_POST['Manager'])
        {
            $model->setScenario('password');
            $model->attributes = $_POST['Manager'];
            $model->validate();
            if ($model->securePassword($model->oldPassword) != $model->password)
            {
                $model->addError('oldPassword', '旧密码不正确');
            }

            if ($model->newPassword != $model->newPasswordConfirm)
            {
                $model->addError('newPasswordConfirm','两次新密码输入不一致');
            }

            if (!$model->hasErrors())
            {
                $model->password = $model->securePassword($model->newPassword);
                $model->save();
                Yii::app()->adminUser->setFlash('ChangePassword', '密码修改成功');
                $this->getController()->refresh();
            }
        }

        $this->getController()->render('password', array('model' => $model));
    }
}