/** * Find a route * * @return Route */ public function findRoute(Request $request) { $path = $request->path(); $method = $request->method(); for ($i = 0; $i < count($this->routes); ++$i) { if ($this->routes[$i]->testPath($path, $method)) { return $this->routes[$i]; } } return null; }
/** * @param Request $request * @return Route|null */ public function findRoute(Request $request) { $method = $request->method(); $rawPath = $request->path(); $preparedPath = $this->prepareUriPath($rawPath); for ($i = 0; $i < count($this->routes); ++$i) { if ($this->testRoute($this->routes[$i], $preparedPath, $rawPath, $method)) { return $this->routes[$i]; } } return null; }
/** * @Route ("/banned") * @Secure ({"USER"}) * * @param array $params * @param ViewModel $model * @return string */ public function banned(array $params, ViewModel $model, Request $request) { $userService = UserService::instance(); $creds = Session::getCredentials(); $model->ban = $userService->getUserActiveBan($creds->getUserId(), $request->ipAddress()); $model->banType = 'none'; if (!empty($model->ban)) { if (!$model->ban['endtimestamp']) { $model->banType = 'permanent'; } else { $model->banType = 'temporary'; } } $model->user = $creds->getData(); return 'banned'; }
/** * @Route ("/register") * @HttpMethod ({"POST"}) * @Transactional * * Handle the confirmation request * @param array $params * @throws Exception */ public function registerProcess(array $params, ViewModel $model, Request $request) { $userService = UserService::instance(); $authService = AuthenticationService::instance(); $authCreds = $this->getSessionAuthenticationCredentials($params); $username = isset($params['username']) && !empty($params['username']) ? $params['username'] : ''; $email = isset($params['email']) && !empty($params['email']) ? $params['email'] : ''; $country = isset($params['country']) && !empty($params['country']) ? $params['country'] : ''; $rememberme = isset($params['rememberme']) && !empty($params['rememberme']) ? true : false; $authCreds->setUsername($username); $authCreds->setEmail($email); try { if (!isset($params['g-recaptcha-response']) || empty($params['g-recaptcha-response'])) { throw new Exception('You must solve the recaptcha.'); } $googleRecaptchaHandler = new GoogleRecaptchaHandler(); $googleRecaptchaHandler->resolve(Config::$a['g-recaptcha']['secret'], $params['g-recaptcha-response'], $request->ipAddress()); $authService->validateUsername($username); $authService->validateEmail($email); if (!empty($country)) { $countryArr = Country::getCountryByCode($country); if (empty($countryArr)) { throw new Exception('Invalid country'); } $country = $countryArr['alpha-2']; } $user = array(); $user['username'] = $username; $user['email'] = $email; $user['userStatus'] = 'Active'; $user['country'] = $country; $user['userId'] = $userService->addUser($user); $userService->addUserAuthProfile(array('userId' => $user['userId'], 'authProvider' => $authCreds->getAuthProvider(), 'authId' => $authCreds->getAuthId(), 'authCode' => $authCreds->getAuthCode(), 'authDetail' => $authCreds->getAuthDetail())); Session::set('authSession'); $authCredHandler = new AuthenticationRedirectionFilter(); return $authCredHandler->execute($authCreds); } catch (Exception $e) { $model->title = 'Register Error'; $model->username = $username; $model->email = $email; $model->follow = isset($params['follow']) ? $params['follow'] : ''; $model->authProvider = $authCreds->getAuthProvider(); $model->code = $authCreds->getAuthCode(); $model->error = $e; return 'register'; } }
/** * @Route ("/profile/authtoken/create") * @HttpMethod ({"POST"}) * @Secure ({"USER"}) * * @param array $params * @param Request $request * @return string * @throws \Exception */ public function profileAuthTokenCreate(array $params, Request $request) { if (!isset($params['g-recaptcha-response']) || empty($params['g-recaptcha-response'])) { throw new Exception('You must solve the recaptcha.'); } $googleRecaptchaHandler = new GoogleRecaptchaHandler(); $googleRecaptchaHandler->resolve(Config::$a['g-recaptcha']['secret'], $params['g-recaptcha-response'], $request->ipAddress()); $apiAuthService = ApiAuthenticationService::instance(); $userId = Session::getCredentials()->getUserId(); $tokens = $apiAuthService->getAuthTokensByUserId($userId); if (count($tokens) >= 5) { throw new Exception('You have reached the maximum [5] allowed login keys.'); } $log = Application::instance()->getLogger(); $conn = Application::instance()->getConnection(); $conn->beginTransaction(); try { $token = $apiAuthService->createAuthToken($userId); $apiAuthService->addAuthToken($userId, $token); $conn->commit(); } catch (\Exception $e) { $log->critical("Error creating auth token"); $conn->rollBack(); throw $e; } Session::set('modelSuccess', 'Auth token created!'); return 'redirect: /profile/authentication'; }