[ "prefilters" => [new HttpMethod([HttpMethod::METHOD_POST]), new Csrf(), new FormGuard(FormGuard::TIMING_ELAPSED)], ], ]; } public function createAction( string $name, string $email, string $password, string $consent = "", string $back = "", string $lang = "en", string $website = "", int $elapsed = 0, string $altcha = "" ): ?array { $lang = Redirect::language($lang); if ($website !== "") { return ["ok" => true, "redirect" => Redirect::home($lang)]; } $session = Application::getInstance()->getSession(); $now = time(); $log = array_values(array_filter((array)($session->get("vino_register_log") ?? []), static fn($at): bool => (int)$at > $now - self::WINDOW_SECONDS)); if (count($log) >= self::MAX_PER_WINDOW) { $this->addError(new Error("Too many attempts", "too_often")); return null; } $log[] = $now; $session->set("vino_register_log", $log); $name = trim((string)preg_replace('/\s+/u', " ", $name)); $email = mb_strtolower(trim($email)); $length = mb_strlen($password); if ( $consent !== "1" || $name === "" || mb_strlen($name) > self::NAME_MAX || !mb_check_encoding($name, "UTF-8") || preg_match('/[<>\x00-\x1f\x7f]/', $name) || !check_email($email) || mb_strlen($email) > 254 || $length < self::PASSWORD_MIN || $length > self::PASSWORD_MAX || mb_strtolower($password) === $email ) { $this->addError(new Error("Registration failed", "failed")); return null; } $exists = UserTable::getRow([ "select" => ["ID"], "filter" => ["LOGIC" => "OR", "=EMAIL" => $email, "=LOGIN" => $email], ]); if ($exists !== null) { $this->addError(new Error("Registration failed", "failed")); return null; } $groups = array_values(array_filter(array_map("intval", explode(",", (string)Option::get("main", "new_user_registration_def_group", ""))))); $user = new \CUser(); $id = (int)$user->Add([ "LOGIN" => $email, "EMAIL" => $email, "NAME" => $name, "PASSWORD" => $password, "CONFIRM_PASSWORD" => $password, "ACTIVE" => "Y", "LID" => SITE_ID, "GROUP_ID" => $groups, "UF_CONSENT_TIME" => (string)new DateTime(), "UF_CONSENT_VERSION" => Consent::VERSION, "UF_CONSENT_PAGE" => $this->consentPage(), "UF_CONSENT_URL" => Config::host() . SITE_DIR . "consent/", ]); if ($id <= 0) { $this->addError(new Error("Registration failed", "failed")); return null; } global $USER; $USER->Authorize($id); return ["ok" => true, "redirect" => Redirect::back($back, $lang)]; } private function consentPage(): string { $path = (string)parse_url((string)($this->getRequest()->getHeader("Referer") ?? ""), PHP_URL_PATH); return mb_check_encoding($path, "UTF-8") && !preg_match('/[\x00-\x1f\x7f]/', $path) ? mb_substr($path, 0, 200) : ""; } }