<?php
include "../core.php";
header( "Content-Type:text/html;charset=" . SAXUE_SYSTEM_CHARSET );
saxue_getconfigs( 'configs', 'member' );
include SAXUE_ROOT_PATH . "/model/member_users.php";
$users_handler = &saxuememberusershandler :: getinstance( "saxuememberusershandler" );
$_ret = 0;
switch ( $_GET['item'] ) {
		case "u" :
				$closearr = array();
				$_GET['uname'] = trim( $_GET['uname'] );
				if ( isset( $saxueConfigs['member']['regclosewords'] ) ) {
						$closewords = $saxueConfigs['member']['regclosewords'];
						$closearr = explode( ',', $closewords );
				} 
				if ( strlen( $_GET['uname'] ) == 0 ) {
						// 用户名为空
						$_ret = 1;
				} else if ( ( !empty( $saxueConfigs['member']['regminname'] ) && strlen( $_GET['uname'] ) < $saxueConfigs['member']['regminname'] ) || ( !empty( $saxueConfigs['member']['regmaxname'] ) && strlen( $_GET['uname'] ) > $saxueConfigs['member']['regmaxname'] ) ) {
						// 用户名长度错误
						$_ret = 2;
				} else if ( preg_match( "/^\\s*\$|^c:\\con\\con\$|[@%,;:\\.\\|\\*\\\"'\\\\\\/\\s\\t\\<\\>\\&]|　/is", $_GET['uname'] ) ) {
						// 用户名包含特殊字符
						$_ret = 3;
				} else if ( $saxueConfigs['member']['unamelimit'] == 1 && !preg_match( "/^[A-Za-z0-9]+\$/", $_GET['uname'] ) ) {
						// 用户名不允许中文
						$_ret = 4;
				} else if ( !empty( $closearr ) && in_array( $_GET['uname'], $closearr ) ) {
						// 用户名禁止注册
						$_ret = 5;
				} else if ( 0 < $users_handler -> getcount( new criteria( "uname", $_GET['uname'], "=" ) ) ) {
						// 用户名重复
						$_ret = 6;
				} 
				echo $_ret;
				break;
		case "p" :
				if ( strlen( $_GET['password'] ) == 0 ) {
						// 密码为空
						$_ret = 5;
				} 
				echo $_ret;
				break;
		case "r" :
				if ( strlen( $_GET['password'] ) == 0 || strlen( $_GET['repassword'] ) == 0 ) {
						// 密码为空
						$_ret = 2;
				} else if ( $_GET['password'] != $_GET['repassword'] ) {
						// 两次输入的密码不一致
						$_ret = 1;
				} 
				echo $_ret;
				break;
		case "m" :
				$_GET['email'] = trim( $_GET['email'] );
				if ( strlen( $_GET['email'] ) == 0 ) {
						// 邮箱为空
						$_ret = 1;
				} else if ( !preg_match( "/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+([\\.][a-z0-9-]+)+\$/i", $_GET['email'] ) ) {
						// 邮箱格式错误
						$_ret = 2;
				} else if ( 0 < $users_handler -> getcount( new criteria( "email", $_GET['email'], "=" ) ) ) {
						// 邮箱重复
						$_ret = 3;
				} 
				echo $_ret;
				break;
		case "mob" :
				$_GET['mobile'] = trim( $_GET['mobile'] );
				if ( strlen( $_GET['mobile'] ) == 0 ) {
						// 手机为空
						$_ret = 1;
				} else if ( !preg_match( "/^1[34578]{1}[0-9]{9}$/i", $_GET['mobile'] ) ) {
						// 手机格式错误
						$_ret = 2;
				} else if ( 0 < $users_handler -> getcount( new criteria( "mobile", $_GET['mobile'], "=" ) ) ) {
						// 手机重复
						$_ret = 3;
				} 
				echo $_ret;
				break;
		case "v" :
				$_GET['checkcode'] = trim( $_GET['checkcode'] );
				if ( strlen( $_GET['checkcode'] ) == 0 ) {
						// 验证码为空
						$_ret = 1;
				} else if ( strtolower( $_GET['checkcode'] ) != strtolower( $_SESSION['saxueCheckCode'] ) ) {
						// 验证码错误
						$_ret = 2;
				} 
				echo $_ret;
				break;
		default :
} 
