<?php
!defined('WAP') && exit('FORBIDDEN');
define('CURSCRIPT','register');

$mobile_settings['register'] != 1 && errormsg('本站手机版已关闭注册功能！如需注册，请打开 '.$mymps_global[SiteUrl].' 网页后再进行注册！');

if($action == 'register'){

	include MYMPS_ROOT.'/member/include/common.func.php';
	
	$userid = isset($_POST['userid']) ? mhtmlspecialchars($_POST['userid']) : '';
	$userpwd = isset($_POST['userpwd']) ? mhtmlspecialchars($_POST['userpwd']) : '';
	$reuserpwd = isset($_POST['reuserpwd']) ? mhtmlspecialchars($_POST['reuserpwd']) : '';
	$email = isset($_POST['email']) ? mhtmlspecialchars($_POST['email']) : '';
	$agreergpermit = isset($_POST['agreergpermit']) ? mhtmlspecialchars($_POST['agreergpermit']) : '';
	$mixcode = isset($_POST['mixcode']) ? mhtmlspecialchars($_POST['mixcode']) : '';
	if(!$mixcode || $mixcode != md5($cookiepre)){
		errormsg('系统判断您的来路不正确！');
	}

	$checkcode = isset($_POST['checkcode']) ? mhtmlspecialchars($_POST['checkcode']) : '';
	if($mobile_settings['authcode'] == 1 && !mymps_chk_randcode($checkcode)){
		redirectmsg('验证码输入错误，请返回重新输入','index.php?mod=register');
	}
	if($agreergpermit != 1) redirectmsg('您必须同意条款内容方可注册','index.php?mod=register');
	$rs	= CheckUserID($userid,'用户名');
	$rs != 'ok' && redirectmsg($rs,'index.php?mod=register');
	if($userpwd != $reuserpwd) redirectmsg('您两次输入的密码不相同，请返回重新输入','index.php?mod=register');
	strlen($userid) > 20 && redirectmsg('您的用户名多于20个字符，不允许注册!','index.php?mod=register');
	(strlen($userid) < 3 || strlen($userpwd) < 5) && redirectmsg('你的用户名或密码过短(不能少于3个字符)，不允许注册!','index.php?mod=register');
	!is_email($email) && redirectmsg('Email格式不正确！','index.php?mod=register');
	$db->getOne("SELECT id FROM `{$db_mymps}member` WHERE userid = '$userid' ") && redirectmsg('你指定的用户名 '.$userid.' 已存在，请使用别的用户名!','index.php?mod=register');
	member_reg($userid,md5($userpwd),$email,$safequestion,$safeanswer);
	$member_log -> in($userid,md5($userpwd),'off','noredirect');
	redirectmsg('恭喜! 您已经注册成功','index.php?mod=index');
	
} else {
	$mixcode = md5($cookiepre);
	include mymps_tpl('member_register');
}
?>