/** * @see Validator::isValid() * * @param mixed $value */ public function isValid($value) { $language = OW::getLanguage(); if (!UTIL_Validator::isUserNameValid($value)) { $this->setErrorMessage($language->text('base', 'join_error_username_not_valid')); return false; } else { if (BOL_UserService::getInstance()->isExistUserName($value)) { $this->setErrorMessage($language->text('base', 'join_error_username_already_exist')); return false; } else { if (BOL_UserService::getInstance()->isRestrictedUsername($value)) { $this->setErrorMessage($language->text('base', 'join_error_username_restricted')); return false; } } } return true; }
public function createUser($username, $password, $email, $accountType = null, $emailVerify = false) { if (!UTIL_Validator::isEmailValid($email)) { throw new InvalidArgumentException('Invalid email!', self::CREATE_USER_INVALID_EMAIL); } if (!UTIL_Validator::isUserNameValid($username)) { throw new InvalidArgumentException('Invalid username!', self::CREATE_USER_INVALID_USERNAME); } if (!isset($password) || strlen($password) === 0) { throw new InvalidArgumentException('Invalid password!', self::CREATE_USER_INVALID_PASSWORD); } if ($this->isExistUserName($username)) { throw new LogicException('Duplicate username!', self::CREATE_USER_DUPLICATE_USERNAME); } if ($this->isExistEmail($email)) { throw new LogicException('Duplicate email!', self::CREATE_USER_DUPLICATE_EMAIL); } $userAccountType = $accountType; if ($userAccountType === null) { $userAccountType = ''; $accountTypes = BOL_QuestionService::getInstance()->findAllAccountTypes(); if (count($accountTypes) === 1) { $userAccountType = $accountTypes[0]->name; } } $user = new BOL_User(); $user->username = trim($username); $user->password = BOL_UserService::getInstance()->hashPassword($password); $user->email = trim($email); $user->joinStamp = time(); $user->activityStamp = time(); $user->accountType = $userAccountType; $user->joinIp = ip2long(OW::getRequest()->getRemoteAddress()); if ($emailVerify === true) { $user->emailVerify = true; } $this->saveOrUpdate($user); BOL_AuthorizationService::getInstance()->assignDefaultRoleToUser($user->id); return $user; }
public function login($params) { $backUri = empty($_GET['backUri']) ? '' : urldecode($_GET['backUri']); $backUrl = OW_URL_HOME . $backUri; $language = OW::getLanguage(); $fbUser = $this->service->fbRequireUser(); $authAdapter = new FBCONNECT_CLASS_AuthAdapter($fbUser); // Login and redirect if already registered if ($authAdapter->isRegistered()) { $authResult = OW::getUser()->authenticate($authAdapter); if ($authResult->isValid()) { OW::getFeedback()->info($language->text('fbconnect', 'login_success_msg')); } else { OW::getFeedback()->error($language->text('fbconnect', 'login_failure_msg')); } $this->redirect($backUrl); } //Register if not registered $questions = $this->service->requestQuestionValueList($fbUser); if (empty($questions["email"]) || empty($questions["username"])) { OW::getFeedback()->error($language->text('fbconnect', 'join_incomplete')); $this->redirect($backUrl); } $username = $questions['username']; $password = uniqid(); $userByEmail = BOL_UserService::getInstance()->findByEmail($questions['email']); if ($userByEmail !== null) { OW::getUser()->login($userByEmail->id); OW::getFeedback()->info($language->text('fbconnect', 'login_success_msg')); $this->redirect($backUrl); } $validUsername = UTIL_Validator::isUserNameValid($username); $username = $validUsername ? $username : uniqid("user_"); try { $user = BOL_UserService::getInstance()->createUser($username, $password, $questions['email'], null, true); if (!$validUsername) { $user->username = "******" . $user->id; BOL_UserService::getInstance()->saveOrUpdate($user); } unset($questions['username']); unset($questions['email']); } catch (Exception $e) { switch ($e->getCode()) { case BOL_UserService::CREATE_USER_DUPLICATE_EMAIL: OW::getFeedback()->error($language->text('fbconnect', 'join_dublicate_email_msg')); $this->redirect($backUrl); break; case BOL_UserService::CREATE_USER_INVALID_USERNAME: OW::getFeedback()->error($language->text('fbconnect', 'join_incorrect_username')); $this->redirect($backUrl); break; default: OW::getFeedback()->error($language->text('fbconnect', 'join_incomplete')); $this->redirect($backUrl); } } if (!empty($questions['picture_big'])) { BOL_AvatarService::getInstance()->setUserAvatar($user->id, $questions['picture_big']); unset($questions['picture_small']); unset($questions['picture_medium']); unset($questions['picture_big']); } BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($questions), $user->id); $authAdapter->register($user->id); $authResult = OW_Auth::getInstance()->authenticate($authAdapter); if ($authResult->isValid()) { $event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => $_GET)); OW::getEventManager()->trigger($event); OW::getFeedback()->info($language->text('fbconnect', 'join_success_msg')); } else { OW::getFeedback()->error($language->text('fbconnect', 'join_failure_msg')); } $this->redirect($backUrl); }
/** * @see Validator::isValid() * * @param mixed $value */ public function isValid($value) { $language = OW::getLanguage(); if (!UTIL_Validator::isUserNameValid($value)) { $this->setErrorMessage($language->text('base', 'join_error_username_not_valid')); return false; } if (BOL_UserService::getInstance()->isExistUserName($value)) { $userId = OW::getUser()->getId(); if (!empty($this->userId)) { $userId = $this->userId; } $user = BOL_UserService::getInstance()->findUserById($userId); if ($value !== $user->username) { $this->setErrorMessage($language->text('base', 'join_error_username_already_exist')); return false; } } if (BOL_UserService::getInstance()->isRestrictedUsername($value)) { $this->setErrorMessage($language->text('base', 'join_error_username_restricted')); return false; } return true; }
public function site() { $this->setPageTitle('Site'); INSTALL::getStepIndicator()->activate('site'); $fieldData = array(); $fieldData['site_url'] = OW_URL_HOME; $fieldData['site_path'] = OW_DIR_ROOT; $sessionData = INSTALL::getStorage()->getAll(); $fieldData = array_merge($fieldData, $sessionData); $this->assign('data', $fieldData); $errors = array(); if (OW::getRequest()->isPost()) { $data = $_POST; $data = array_filter($data, 'trim'); $success = true; if (empty($data['site_title'])) { $errors[] = 'site_title'; } if (empty($data['site_url']) || !trim($data['site_url'])) { $errors[] = 'site_url'; } if (empty($data['site_path']) || !is_dir($data['site_path'])) { $errors[] = 'site_path'; } if (empty($data['admin_username']) || !UTIL_Validator::isUserNameValid($data['admin_username'])) { $errors[] = 'admin_username'; } if (empty($data['admin_password']) || strlen($data['admin_password']) < 3) { $errors[] = 'admin_password'; } if (empty($data['admin_email']) || !UTIL_Validator::isEmailValid($data['admin_email'])) { $errors[] = 'admin_email'; } $this->processData($data); if (empty($errors)) { $this->redirect(OW::getRouter()->urlForRoute('db')); } foreach ($errors as $flag) { INSTALL::getFeedback()->errorFlag($flag); } $this->redirect(); } }