<?php

class login_sxExe extends xIExecutor {

	public function main() {
		if(xUser::$cur->isGuest()) {
			$user = new xUser($_POST['username']);
			try {
				$user->login($_POST['password']);
				echo json_encode(array(
					'result' => '1'
				));
			} catch(xError $e) {
				if($e->getCode() == xUser::ERR_BAD_PASSWORD || $e->getCode() == xUser::ERR_BAD_USERNAME) {
					echo json_encode(array(
						'result' => '0',
						'msg' => '用户名或密码错误'
					));
				} else if($e->getCode() == xUser::ERR_BANNED) {
					echo json_encode(array(
						'result' => '0',
						'msg' => '您的账户被禁止登录'
					));
				}
			}
		} else {
			echo json_encode(array(
				'result' => xUser::$cur->id
			));
		}
	}

	public function onError($result) {

	}
}

