/** * register 注册页面 */ public function register($domain = null) { // $domain = return_url(); //获取参数 $aUsername = $username = I('post.username', '', 'op_t'); $aNickname = I('post.nickname', '', 'op_t'); $aPassword = I('post.password', '', 'op_t'); $aVerify = I('post.verify', '', 'op_t'); $aRegVerify = I('post.reg_verify', 0, 'intval'); $aRegType = I('post.reg_type', '', 'op_t'); $aStep = I('get.step', 'start', 'op_t'); $aRole = I('post.role', 0, 'intval'); $acid = I('post.cid', '', 'op_t'); $aCompany = ''; if (!modC('REG_SWITCH', '', 'USERCONFIG')) { $this->error('注册已关闭'); } if (IS_POST) { //注册用户 $return = check_action_limit('reg', 'ucenter_member', 1, 1, true); if ($return && !$return['state']) { $this->error($return['info'], $return['url']); } /* 检测验证码 */ if (check_verify_open('reg')) { if (!check_verify($aVerify)) { $this->error('验证码输入错误。'); } } /** * 手机验证码和邮箱验证码的验证 */ if ($aRegType == 'mobile' && modC('MOBILE_VERIFY_TYPE', 0, 'USERCONFIG') == 1 || modC('EMAIL_VERIFY_TYPE', 0, 'USERCONFIG') == 2 && $aRegType == 'email') { if (!D('Verify')->checkVerify($aUsername, $aRegType, $aRegVerify, 0)) { $str = $aRegType == 'mobile' ? '手机' : '邮箱'; $this->error($str . '验证失败'); } } /** * 根据编号查询集团 // 判断用户IP是否是公司集团IP */ if (!empty($acid) && $aRegType == 'company') { $company = M('Company')->find((int) $acid); $aCompany = $company['cname']; $checkIp = new \Expend\CheckIP($company['cip']); if (TRUE !== $checkIp->check(get_client_ip()) && ip2long(get_client_ip()) !== ip2long($company['cip'])) { $this->error('你的IP地址不是集团IP'); } } else { $acid = 0; } $aUnType = 0; //获取注册类型 check_username($aUsername, $email, $mobile, $aCompany, $aUnType); if ($aRegType == 'email' && $aUnType != 2) { $this->error('邮箱格式不正确'); } if ($aRegType == 'mobile' && $aUnType != 3) { $this->error('手机格式不正确'); } if ($aRegType == 'username' && $aUnType != 1) { $this->error('用户名格式不正确'); } if (!check_reg_type($aUnType)) { $this->error('该类型未开放注册。'); } /* 注册用户 */ $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $acid, $aUnType, $domain); if (0 < $uid) { #初始化角色用户,并设置相关的用户角色信息 $this->initRoleUser($aRole, $uid); if (modC('EMAIL_VERIFY_TYPE', 0, 'USERCONFIG') == 1 && $aUnType == 2) { set_user_status($uid, 3); $verify = D('Verify')->addVerify($email, 'email', $uid); $res = $this->sendActivateEmail($email, $verify, $uid); //发送激活邮件 } $this->success('注册成功', U('Ucenter/member/register', array('mes' => 'login'))); } else { //注册失败,显示错误信息 $this->error($this->showRegError($uid)); } } else { //显示注册表单 if (is_login()) { redirect(U(C('AFTER_LOGIN_JUMP_URL'))); } if ($_GET['mes']) { $this->assign('mes', 'login'); } //显示集团 $company = D('Admin/Company')->show_company(); $this->assign('company_list', $company); $this->checkRegisterType(); $aType = I('get.type', '', 'op_t'); $regSwitch = modC('REG_SWITCH', '', 'USERCONFIG'); $regSwitch = explode(',', $regSwitch); $this->assign('regSwitch', $regSwitch); $this->assign('step', $aStep); $this->assign('type', $aType == '' ? 'username' : $aType); $this->display(); } }
/** * 判断客户端的IP是否是集团IP */ function checkUserIp() { $iptype = -1; $company = D('Admin/Company')->show_company(); foreach ($company as $k) { $checkIp = new \Expend\CheckIP($k['cip']); //如果客户端IP是集团IP if (TRUE === $checkIp->check(get_client_ip()) || ip2long(get_client_ip()) === ip2long($k['cip'])) { $iptype = 1; break; } } return $iptype; }
/** * 集团用户登录 */ public function company_dologin() { $aUsername = I('post.username', '', 'op_t'); $aUnType = 5; $aPassword = null; if (empty($aUsername)) { $res['info'] = '用户名不能为空'; } else { $uid = UCenterMember()->cLogin($aUsername); $sessid = UCenterMember()->sessid($aUsername, $aPassword, $aUnType); // 登录成功 if ($uid > 0) { $Member = D('Member'); $args['uid'] = $uid; $args = array('uid' => $uid, 'nickname' => $aUsername); //判断用户IP和集团IP是否一致 $user = $Member->where($args)->find(); if (!empty($user)) { $cmap['id'] = $user['cid']; $company = M('Company')->where($cmap)->find(); if (!empty($company)) { $checkIp = new \Expend\CheckIP($company['cip']); //如果客户端IP是集团IP if (TRUE === $checkIp->check(get_client_ip()) || ip2long(get_client_ip()) === ip2long($company['cip'])) { //登录用户 if ($Member->login($uid, $aRemember == 1)) { $res['sessid'] = $sessid; $res['status'] = 1; } else { $res['info'] = $Member->getError(); } } else { $res['info'] = '用户名与集团IP不匹配'; } } else { $res['info'] = '用户名与集团IP不匹配'; } } } else { switch ($uid) { case -1: $res['info'] = '用户不存在或被禁用'; break; case -3: $res['info'] = '用户不为集团用户'; break; default: $res['info'] = $uid; break; // 0-接口参数错误(调试阶段使用) } } } return $res; }