<?php
/**
 * Created by JetBrains PhpStorm.
 * User: yzxh24
 * Date: 12-2-5
 * Time: 下午3:36
 * To change this template use File | Settings | File Templates.
 */
class UsernameAction extends BaseAction
{
    public function run()
    {
        $uid = Yii::app()->request->getQuery('uid');
        $member = Member::model()->findByPk($uid);

        $this->performAjaxValidation($member, 'uname');

        if (isset($_POST['Member']) && Yii::app()->request->isAjaxRequest)
        {
            $member->attributes = $_POST['Member'];
            if ($member->save())
            {
                $member->save();
                echo CJSON::encode(1);
            }
            else
            {
                echo CActiveForm::validate($member);
            }
            Yii::app()->end();
        }

        $this->getController()->renderPartial('username', array('member'=>$member), false, true);

    }
}
