做注册的验证,在服务器端处理,客服端ajax异步提交数据

/*
     * 会员注册模块
     */
    public function insertreginfo(){
$user_info = M('user_info');

$data['identity'] = 1;
do {
$sn = productSN(true);
if(!$this->where('user_no=\'' . $sn . '\'')->field('user_no')->find()) break;
} while(true);
$data['user_no'] = $sn;
//用户名
$data['username'] = I('username');
if(empty($data['username'])) return array('info' => '请输入您的用户名', 'temp' => 'username', 'status' => 0);
if(preg_match("/([\x81-\xfe][\x40-\xfe])/", $data['username'])) return array('info' => '用户名请勿使用中文', 'temp' => 'username', 'status' => 0);
if($user_info->where('username=\'' . $data['username'] . '\'')->getField('uid')) return array('info' => '用户名已存在', 'temp' => 'username', 'status' => 0);
if(strlen($data['username']) < 6 or strlen($data['username']) > 20) return array('info' => '用户名长度须保持在6~20位之间', 'temp' => 'username', 'status' => 0);
//密码
$data['password'] = I('password');
if(empty($data['password'])) return array('info' => '请输入密码', 'temp' => 'password', 'status' => 0);
if(strlen($data['password']) < 6 or strlen($data['password']) > 20) return array('info' => '密码长度须保持在6~20位之间', 'temp' => 'password', 'status' => 0);
$password2 = I('password2');
if(empty($password2)) return array('info' => '请确认密码', 'temp' => 'password2', 'status' => 0);
if($data['password'] != I('password2')) return array('info' => '确认密码有误', 'temp' => 'password2', 'status' => 0);
$data['password'] = encrypt($data['password']);
// 姓名
$data['realname'] = I('realname');
if(empty($data['realname'])) return array('info' => '请输入您的姓名', 'temp' => 'realname', 'status' => 0);
// 身份证号
$data['idcard'] = I('idcard');
if(empty($data['idcard'])) return array('info' => '请输入您的身份证号', 'temp' => 'idcard', 'status' => 0);
if(!check_idcard($data['idcard'])) return array('info' => '请输入正确的身份证号', 'temp' => 'idcard', 'status' => 0);
if($user_info->where('idcard=\'' . $data['idcard'] . '\'')->getField('uid')) return array('info' => '该身份证号已被使用', 'temp' => 'idcard', 'status' => 0);
// 手机
$data['mobile'] = I('mobile');
if(empty($data['mobile'])) return array('info' => '请输入您的手机号码', 'temp' => 'mobile', 'status' => 0);
if(!check_mobile($data['mobile'])) return array('info' => '手机号输入有误', 'temp' => 'mobile', 'status' => 0);
if($user_info->where('mobile=\'' . $data['mobile'] . '\'')->getField('uid')) return array('info' => '该手机号已被使用', 'temp' => 'mobile', 'status' => 0);
// 推荐人信息
$rec_uid = I('rec_uid');
$rec_username = I('rec_username');
if(empty($rec_uid)) return array('info' => '请输入推荐人的ID', 'temp' => 'rec_uid', 'status' => 0);
if(!$recommand = $user_info->where('user_no=\'' . $rec_uid . '\'')->field('uid, username')->find()) return array('info' => '推荐人编号不存在', 'temp' => 'rec_uid', 'status' => 0);
if(empty($rec_username)) return array('info' => '请输入推荐人的用户名', 'temp' => 'rec_username', 'status' => 0);
if($recommand['username'] != $rec_username) return array('info' => '推荐人的编号与用户名不匹配', 'temp' => 'rec_username', 'status' => 0);

$merchant_registinput = intval(I('merchant_registinput'));
if($merchant_registinput != 1) return array('info' => '请确认是否同意《亿嘉客用户注册协议》', 'temp' => 'other', 'status' => 0);

$data['regtime'] = time();

$result = $user_info->add($data);
if($result) {
$command['uid'] = $recommand['uid'];
$command['rec_uid'] = $result;
$command['rec_time'] = $_SERVER['REQUEST_TIME'];
M('user_recommand')->add($command);

return array('info' => '', 'status' => 1);
} else {
return array('info' => '很遗憾!注册失败!', 'temp' => 'other', 'status' => 0);
}
    }

你可能感兴趣的:(做注册的验证,在服务器端处理,客服端ajax异步提交数据)