public function testEmail() { $result = SimpleValidator::email("68988"); $this->assertEquals(false, $result); $result = SimpleValidator::email("*****@*****.**"); $this->assertEquals(true, $result); $result = SimpleValidator::email("ugihui"); $this->assertEquals(false, $result); }
public function registerAction(Request $request) { $email = $request->get('email'); $nickname = $request->get('nickname'); $password = $request->get('password'); if (!$this->getAuthService()->isRegisterEnabled()) { return $this->createErrorResponse($request, 'register_closed', '注册已关闭,请联系管理员'); } if (!SimpleValidator::email($email)) { return $this->createErrorResponse($request, 'email_invalid', '邮箱地址格式不正确'); } if (!SimpleValidator::nickname($nickname)) { return $this->createErrorResponse($request, 'nickname_invalid', '用户名格式不正确'); } if (!SimpleValidator::password($password)) { return $this->createErrorResponse($request, 'password_invalid', '密码格式不正确'); } if (!$this->getUserService()->isEmailAvaliable($email)) { return $this->createErrorResponse($request, 'email_exist', '该邮箱已被注册'); } if (!$this->getUserService()->isNicknameAvaliable($nickname)) { return $this->createErrorResponse($request, 'nickname_exist', '该用户名已被注册'); } $user = $this->getAuthService()->register(array('email' => $email, 'nickname' => $nickname, 'password' => $password)); $token = $this->createToken($user, $request); return $this->createJson($request, array('user' => $this->filterUser($user), 'token' => $token)); }
public function regist() { $email = $this->getParam('email'); $nickname = $this->getParam('nickname'); $password = $this->getParam('password'); $auth = $this->getSettingService()->get('auth', array()); if (isset($auth['register_mode']) && $auth['register_mode'] == 'closed') { return $this->createErrorResponse('register_closed', '系统暂时关闭注册,请联系管理员'); } if ($auth['register_mode'] == 'mobile') { return $this->createErrorResponse('register_error', '移动端暂不支持手机注册,敬请期待!'); } if (!SimpleValidator::email($email)) { return $this->createErrorResponse('email_invalid', '邮箱地址格式不正确'); } if (!SimpleValidator::nickname($nickname)) { return $this->createErrorResponse('nickname_invalid', '用户名格式不正确'); } if (!SimpleValidator::password($password)) { return $this->createErrorResponse('password_invalid', '密码格式不正确'); } if (!$this->controller->getUserService()->isEmailAvaliable($email)) { return $this->createErrorResponse('email_exist', '该邮箱已被注册'); } if (!$this->controller->getUserService()->isNicknameAvaliable($nickname)) { return $this->createErrorResponse('nickname_exist', '该用户名已被注册'); } $registTypeName = $auth['register_mode'] == "email" ? "email" : "emailOrMobile"; $user = $this->controller->getAuthService()->register(array($registTypeName => $email, 'nickname' => $nickname, 'password' => $password)); $token = $this->controller->createToken($user, $this->request); $this->log("user_regist", "用户注册", array("user" => $user)); return array('user' => $this->controller->filterUser($user), 'token' => $token); }
public function existAction(Request $request, $type) { $token = $request->getSession()->get('oauth_token'); $client = $this->createOAuthClient($type); $oauthUser = $client->getUserInfo($token); $data = $request->request->all(); $message = 'Email地址或手机号码输入错误'; if (SimpleValidator::email($data['emailOrMobile'])) { $user = $this->getUserService()->getUserByEmail($data['emailOrMobile']); $message = '该Email地址尚未注册'; } else { if (SimpleValidator::mobile($data['emailOrMobile'])) { $user = $this->getUserService()->getUserByVerifiedMobile($data['emailOrMobile']); $message = '该手机号码尚未注册'; } } if (empty($user)) { $response = array('success' => false, 'message' => $message); } elseif (!$this->getUserService()->verifyPassword($user['id'], $data['password'])) { $response = array('success' => false, 'message' => '密码不正确,请重试!'); } elseif ($this->getUserService()->getUserBindByTypeAndUserId($type, $user['id'])) { $response = array('success' => false, 'message' => "该{{ {$this->setting}('site.name') }}帐号已经绑定了该第三方网站的其他帐号,如需重新绑定,请先到账户设置中取消绑定!"); } else { $response = array('success' => true, '_target_path' => $request->getSession()->get('_target_path', $this->generateUrl('homepage'))); $this->getUserService()->bindUser($type, $oauthUser['id'], $user['id'], $token); $this->authenticateUser($user); } return $this->createJsonResponse($response); }
public function register($registration, $type = 'default') { if (!SimpleValidator::nickname($registration['nickname'])) { throw $this->createServiceException('nickname error!'); } if (!$this->isNicknameAvaliable($registration['nickname'])) { throw $this->createServiceException('昵称已存在'); } if (!SimpleValidator::email($registration['email'])) { throw $this->createServiceException('email error!'); } if (!$this->isEmailAvaliable($registration['email'])) { throw $this->createServiceException('Email已存在'); } $user = array(); if (isset($registration['verifiedMobile'])) { $user['verifiedMobile'] = $registration['verifiedMobile']; } else { $user['verifiedMobile'] = ''; } $user['email'] = $registration['email']; $user['emailVerified'] = isset($registration['emailVerified']) ? $registration['emailVerified'] : 0; $user['nickname'] = $registration['nickname']; $user['roles'] = array('ROLE_USER'); $user['type'] = isset($registration['type']) ? $registration['type'] : $type; $user['createdIp'] = empty($registration['createdIp']) ? '' : $registration['createdIp']; $user['createdTime'] = time(); $thirdLoginInfo = $this->getSettingService()->get('login_bind', array()); if (in_array($type, array('default', 'phpwind', 'discuz'))) { $user['salt'] = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36); $user['password'] = $this->getPasswordEncoder()->encodePassword($registration['password'], $user['salt']); $user['setup'] = 1; } elseif (in_array($type, array('qq', 'weibo', 'renren', 'weixinweb', 'weixinmob')) && isset($thirdLoginInfo["{$type}_set_fill_account"]) && $thirdLoginInfo["{$type}_set_fill_account"]) { $user['salt'] = ''; $user['password'] = ''; $user['setup'] = 1; } else { $user['salt'] = ''; $user['password'] = ''; $user['setup'] = 0; } $user = UserSerialize::unserialize($this->getUserDao()->addUser(UserSerialize::serialize($user))); if (!empty($registration['invite_code'])) { $inviteUser = $this->getUserDao()->getUserByInviteCode($registration['invite_code']); } if (!empty($inviteUser)) { $this->getInviteRecordService()->createInviteRecord($inviteUser['id'], $user['id']); $inviteCoupon = $this->getCouponService()->generateInviteCoupon($user['id'], 'register'); if (!empty($inviteCoupon)) { $card = $this->getCardService()->getCardByCardId($inviteCoupon['id']); $this->getInviteRecordService()->addInviteRewardRecordToInvitedUser($user['id'], array('invitedUserCardId' => $card['cardId'])); } } if (isset($registration['mobile']) && $registration['mobile'] != "" && !SimpleValidator::mobile($registration['mobile'])) { throw $this->createServiceException('mobile error!'); } if (isset($registration['idcard']) && $registration['idcard'] != "" && !SimpleValidator::idcard($registration['idcard'])) { throw $this->createServiceException('idcard error!'); } if (isset($registration['truename']) && $registration['truename'] != "" && !SimpleValidator::truename($registration['truename'])) { throw $this->createServiceException('truename error!'); } $profile = array(); $profile['id'] = $user['id']; $profile['mobile'] = empty($registration['mobile']) ? '' : $registration['mobile']; $profile['idcard'] = empty($registration['idcard']) ? '' : $registration['idcard']; $profile['truename'] = empty($registration['truename']) ? '' : $registration['truename']; $profile['company'] = empty($registration['company']) ? '' : $registration['company']; $profile['job'] = empty($registration['job']) ? '' : $registration['job']; $profile['weixin'] = empty($registration['weixin']) ? '' : $registration['weixin']; $profile['weibo'] = empty($registration['weibo']) ? '' : $registration['weibo']; $profile['qq'] = empty($registration['qq']) ? '' : $registration['qq']; $profile['site'] = empty($registration['site']) ? '' : $registration['site']; $profile['gender'] = empty($registration['gender']) ? 'secret' : $registration['gender']; for ($i = 1; $i <= 5; $i++) { $profile['intField' . $i] = empty($registration['intField' . $i]) ? null : $registration['intField' . $i]; $profile['dateField' . $i] = empty($registration['dateField' . $i]) ? null : $registration['dateField' . $i]; $profile['floatField' . $i] = empty($registration['floatField' . $i]) ? null : $registration['floatField' . $i]; } for ($i = 1; $i <= 10; $i++) { $profile['varcharField' . $i] = empty($registration['varcharField' . $i]) ? "" : $registration['varcharField' . $i]; $profile['textField' . $i] = empty($registration['textField' . $i]) ? "" : $registration['textField' . $i]; } $this->getProfileDao()->addProfile($profile); if ($type != 'default') { $this->bindUser($type, $registration['token']['userId'], $user['id'], $registration['token']); } $this->getDispatcher()->dispatch('user.service.registered', new ServiceEvent($user)); return $user; }
public function checkEmailOrMobile($emailOrMobile) { if (SimpleValidator::email($emailOrMobile)) { return $this->checkEmail($emailOrMobile); } else { if (SimpleValidator::mobile($emailOrMobile)) { return $this->checkMobile($emailOrMobile); } else { return array('error_dateInput', '电子邮箱或者手机号码格式不正确!'); } } }
public function register($registration, $type = 'default') { if (!SimpleValidator::nickname($registration['nickname'])) { throw $this->createServiceException('nickname error!'); } if (!$this->isNicknameAvaliable($registration['nickname'])) { throw $this->createServiceException('用户名已存在'); } if (!SimpleValidator::email($registration['email'])) { throw $this->createServiceException('email error!'); } if (!$this->isEmailAvaliable($registration['email'])) { throw $this->createServiceException('Email已存在'); } $user = array(); if (isset($registration['verifiedMobile'])) { $user['verifiedMobile'] = $registration['verifiedMobile']; } else { $user['verifiedMobile'] = ''; } $user['email'] = $registration['email']; $user['nickname'] = $registration['nickname']; $user['roles'] = array('ROLE_USER'); $user['type'] = $type; $user['createdIp'] = empty($registration['createdIp']) ? '' : $registration['createdIp']; $user['createdTime'] = time(); if (in_array($type, array('default', 'phpwind', 'discuz'))) { $user['salt'] = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36); $user['password'] = $this->getPasswordEncoder()->encodePassword($registration['password'], $user['salt']); $user['setup'] = 1; } else { $user['salt'] = ''; $user['password'] = ''; $user['setup'] = 0; } $user = UserSerialize::unserialize($this->getUserDao()->addUser(UserSerialize::serialize($user))); if (isset($registration['mobile']) && $registration['mobile'] != "" && !SimpleValidator::mobile($registration['mobile'])) { throw $this->createServiceException('mobile error!'); } if (isset($registration['idcard']) && $registration['idcard'] != "" && !SimpleValidator::idcard($registration['idcard'])) { throw $this->createServiceException('idcard error!'); } if (isset($registration['truename']) && $registration['truename'] != "" && !SimpleValidator::truename($registration['truename'])) { throw $this->createServiceException('truename error!'); } $profile = array(); $profile['id'] = $user['id']; $profile['mobile'] = empty($registration['mobile']) ? '' : $registration['mobile']; $profile['idcard'] = empty($registration['idcard']) ? '' : $registration['idcard']; $profile['truename'] = empty($registration['truename']) ? '' : $registration['truename']; $profile['company'] = empty($registration['company']) ? '' : $registration['company']; $profile['job'] = empty($registration['job']) ? '' : $registration['job']; $profile['weixin'] = empty($registration['weixin']) ? '' : $registration['weixin']; $profile['weibo'] = empty($registration['weibo']) ? '' : $registration['weibo']; $profile['qq'] = empty($registration['qq']) ? '' : $registration['qq']; $profile['site'] = empty($registration['site']) ? '' : $registration['site']; $profile['gender'] = empty($registration['gender']) ? 'secret' : $registration['gender']; for ($i = 1; $i <= 5; $i++) { $profile['intField' . $i] = empty($registration['intField' . $i]) ? null : $registration['intField' . $i]; $profile['dateField' . $i] = empty($registration['dateField' . $i]) ? null : $registration['dateField' . $i]; $profile['floatField' . $i] = empty($registration['floatField' . $i]) ? null : $registration['floatField' . $i]; } for ($i = 1; $i <= 10; $i++) { $profile['varcharField' . $i] = empty($registration['varcharField' . $i]) ? "" : $registration['varcharField' . $i]; $profile['textField' . $i] = empty($registration['textField' . $i]) ? "" : $registration['textField' . $i]; } $this->getProfileDao()->addProfile($profile); if ($type != 'default') { $this->bindUser($type, $registration['token']['userId'], $user['id'], $registration['token']); } $this->getDispatcher()->dispatch('user.service.registered', new ServiceEvent($user)); return $user; }
public function regist() { $email = $this->getParam('email'); $password = $this->getParam('password'); $nickname = $this->getParam('nickname'); $phoneNumber = $this->getParam('phone'); $smsCode = $this->getParam('smsCode'); $result = array('meta' => null); $auth = $this->getSettingService()->get('auth', array()); if (isset($auth['register_mode']) && $auth['register_mode'] == 'closed') { return $this->createErrorResponse('register_closed', '系统暂时关闭注册,请联系管理员'); } if (!$nickname) { $nickname = "ES" . time(); while (!$this->controller->getUserService()->isNicknameAvaliable($nickname)) { $nickname = "ES" . time(); } } else { if (!$this->controller->getUserService()->isNicknameAvaliable($nickname)) { return $this->createErrorResponse('nickname_exist', '该昵称已被注册'); } } $user = null; if (!empty($email)) { if (!SimpleValidator::email($email)) { return $this->createErrorResponse('email_invalid', '邮箱地址格式不正确'); } if (!$this->controller->getUserService()->isEmailAvaliable($email)) { return $this->createErrorResponse('email_exist', '该邮箱已被注册'); } if (!SimpleValidator::password($password)) { return $this->createErrorResponse('password_invalid', '密码格式不正确'); } $registTypeName = $auth['register_mode'] == "email" ? "email" : "emailOrMobile"; $user = $this->controller->getAuthService()->register(array($registTypeName => $email, 'nickname' => $nickname, 'password' => $password)); } else { if (!$this->checkPhoneNum($phoneNumber)) { return $this->createErrorResponse('phone_invalid', '手机号格式不正确'); } if (!$this->getUserService()->isMobileUnique($phoneNumber)) { return $this->createErrorResponse('phone_exist', '该手机号码已被其他用户绑定'); } if ($this->controller->setting('cloud_sms.sms_enabled') == '1' && $this->controller->setting('cloud_sms.sms_registration', 'on') == 'on') { $requestInfo = array('sms_code' => $smsCode, 'mobile' => $phoneNumber); list($result, $sessionField) = $this->smsCheck($this->request, $requestInfo, 'sms_registration'); if ($result) { $user = $this->controller->getAuthService()->register(array('emailOrMobile' => $sessionField['to'], 'nickname' => $nickname, 'password' => $password)); $this->clearSmsSession($this->request, 'sms_registration'); } else { return $this->createErrorResponse('sms_invalid', '手机短信验证错误,请重新注册'); } } } if ($nickname && !SimpleValidator::nickname($nickname)) { return $this->createErrorResponse('nickname_invalid', '昵称格式不正确'); } $token = $this->controller->createToken($user, $this->request); if (!empty($user) && !isset($user["currentIp"])) { $user["currentIp"] = "127.0.0.1"; } $this->log("user_regist", "用户注册", array("user" => $user)); return array('user' => $this->controller->filterUser($user), 'token' => $token); }
public function existBindAction(Request $request) { $token = $request->getSession()->get('oauth_token'); $type = 'weixinmob'; $client = $this->createOAuthClient($type); $oauthUser = $client->getUserInfo($token); $olduser = $this->getCurrentUser(); $userBinds = $this->getUserService()->unBindUserByTypeAndToId($type, $olduser->id); $data = $request->request->all(); $message = 'Email地址或手机号码输入错误'; if (SimpleValidator::email($data['emailOrMobile'])) { $user = $this->getUserService()->getUserByEmail($data['emailOrMobile']); $message = '该Email地址尚未注册'; } elseif (SimpleValidator::mobile($data['emailOrMobile'])) { $user = $this->getUserService()->getUserByVerifiedMobile($data['emailOrMobile']); $message = '该手机号码尚未注册或绑定'; } if (empty($user)) { $response = array('success' => false, 'message' => $message); } elseif (!$this->getUserService()->verifyPassword($user['id'], $data['password'])) { $response = array('success' => false, 'message' => '密码不正确,请重试!'); } elseif ($this->getUserService()->getUserBindByTypeAndUserId($type, $user['id'])) { $response = array('success' => false, 'message' => '该帐号已经绑定了该第三方网站的其他帐号,如需重新绑定,请先到账户设置中取消绑定!'); } else { $response = array('success' => true, '_target_path' => $this->getTargetPath($request)); $this->getUserService()->bindUser($type, $oauthUser['id'], $user['id'], $token); $this->authenticateUser($user); } return $this->createJsonResponse($response); }