<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

// 会员密码
class UcPasswordAction extends UserCenterAction {
	public function index()
	{
		$user_info = D("User")->where("id=".intval($_SESSION['user_id']))->find();
		$this->assign("user_info",$user_info);
		$this->display("Page:user_center_frame");
	}
	
	//修改
	public function doModify()
	{
		if(sunnyiC("TOKEN_ON")&&!M()->autoCheckToken($_POST))
		{
			$this->error(L("TOKEN_ERROR"));
		}
		$data['id'] = intval($_SESSION['user_id']);
		$data['user_name'] = $_SESSION['user_name'];
		$user_pwd = trim($_POST['user_pwd']);
		$data['user_pwd'] = md5($user_pwd);
    	$check_pwd = md5(trim($_POST['user_old_pwd']));
		$confirm_pwd = md5(trim($_POST['user_pwd_confirm']));
		
		$origin_pwd = D("User")->where("id=".$data['id']." and status=1")->getField("user_pwd");
		if($check_pwd!=$origin_pwd)
		{
			$this->error(L("PWD_ERROR"));
		}
		if($confirm_pwd!=$data['user_pwd'])
		{
			$this->error(L("PWD_CONFIRM_FAILED"));
		}
		if(strlen($user_pwd)<6)
		{
			$this->error(L("PWD_TOO_SHORT"));
		}
     	$data['update_time']	=	gmtTime();
    	
    	$rs = D("User")->save($data);
    	if($rs>0)
    	{
    		$this->success(L("MODIFY_SUCCESS"));    		
    	}
    	else
    		$this->error(L("MODIFY_FAILED")); 
	}
	
}
?>