Use redirect() instead of header("Location: ...")

This commit is contained in:
Ilya Prokopenko 2022-08-09 12:52:36 +07:00
parent 26d5553ca0
commit 200414b67d
No known key found for this signature in database
GPG key ID: 7736BBBB05F14A56
13 changed files with 52 additions and 87 deletions

View file

@ -14,20 +14,14 @@ final class AboutPresenter extends OpenVKPresenter
function renderIndex(): void
{
if(!is_null($this->user)) {
header("HTTP/1.1 302 Found");
if($this->user->identity->getMainPage())
header("Location: /feed");
$this->redirect("/feed");
else
header("Location: /id" . $this->user->id);
exit;
$this->redirect($this->user->identity->getURL());
}
if($_SERVER['REQUEST_URI'] == "/id0") {
header("HTTP/1.1 302 Found");
header("Location: /");
exit;
$this->redirect("/");
}
$this->template->stats = (new Users)->getStatistics();
@ -127,16 +121,11 @@ final class AboutPresenter extends OpenVKPresenter
function renderHumansTxt(): void
{
# :D
header("HTTP/1.1 302 Found");
header("Location: https://github.com/openvk/openvk#readme");
exit;
$this->redirect("https://github.com/openvk/openvk#readme");
}
function renderDev(): void
{
header("HTTP/1.1 302 Found");
header("Location: https://docs.openvk.su/");
exit;
$this->redirect("https://docs.openvk.su/");
}
}

View file

@ -170,8 +170,7 @@ final class AdminPresenter extends OpenVKPresenter
$voucher->save();
$this->redirect("/admin/vouchers/id" . $voucher->getId(), static::REDIRECT_TEMPORARY);
exit;
$this->redirect("/admin/vouchers/id" . $voucher->getId());
}
function renderGiftCategories(): void
@ -193,7 +192,7 @@ final class AdminPresenter extends OpenVKPresenter
if(!$cat)
$this->notFound();
else if($cat->getSlug() !== $slug)
$this->redirect("/admin/gifts/" . $cat->getSlug() . "." . $id . ".meta", static::REDIRECT_TEMPORARY);
$this->redirect("/admin/gifts/" . $cat->getSlug() . "." . $id . ".meta");
} else {
$gen = true;
$cat = new GiftCategory;
@ -234,7 +233,7 @@ final class AdminPresenter extends OpenVKPresenter
$cat->setDescription($code, $this->postParam("description_$code"));
}
$this->redirect("/admin/gifts/" . $cat->getSlug() . "." . $cat->getId() . ".meta", static::REDIRECT_TEMPORARY);
$this->redirect("/admin/gifts/" . $cat->getSlug() . "." . $cat->getId() . ".meta");
}
function renderGifts(string $catSlug, int $catId): void
@ -245,7 +244,7 @@ final class AdminPresenter extends OpenVKPresenter
if(!$cat)
$this->notFound();
else if($cat->getSlug() !== $catSlug)
$this->redirect("/admin/gifts/" . $cat->getSlug() . "." . $catId . "/", static::REDIRECT_TEMPORARY);
$this->redirect("/admin/gifts/" . $cat->getSlug() . "." . $catId . "/");
$this->template->cat = $cat;
$this->template->gifts = iterator_to_array($cat->getGifts((int) ($this->queryParam("p") ?? 1), NULL, $this->template->count));
@ -284,7 +283,7 @@ final class AdminPresenter extends OpenVKPresenter
$name = $catTo->getName();
$this->flash("succ", "Gift moved successfully", "This gift will now be in <b>$name</b>.");
$this->redirect("/admin/gifts/" . $catTo->getSlug() . "." . $catTo->getId() . "/", static::REDIRECT_TEMPORARY);
$this->redirect("/admin/gifts/" . $catTo->getSlug() . "." . $catTo->getId() . "/");
break;
default:
case "edit":
@ -328,7 +327,7 @@ final class AdminPresenter extends OpenVKPresenter
$cat->addGift($gift);
}
$this->redirect("/admin/gifts/id" . $gift->getId(), static::REDIRECT_TEMPORARY);
$this->redirect("/admin/gifts/id" . $gift->getId());
}
}

View file

@ -51,7 +51,7 @@ final class AuthPresenter extends OpenVKPresenter
function renderRegister(): void
{
if(!is_null($this->user))
$this->redirect("/id" . $this->user->id, static::REDIRECT_TEMPORARY);
$this->redirect($this->user->identity->getURL());
if(!$this->hasPermission("user", "register", -1)) exit("Вас забанили");
@ -129,7 +129,7 @@ final class AuthPresenter extends OpenVKPresenter
}
$this->authenticator->authenticate($chUser->getId());
$this->redirect("/id" . $user->getId(), static::REDIRECT_TEMPORARY);
$this->redirect("/id" . $user->getId());
}
}
@ -138,12 +138,11 @@ final class AuthPresenter extends OpenVKPresenter
$redirUrl = $this->requestParam("jReturnTo");
if(!is_null($this->user))
$this->redirect($redirUrl ?? "/id" . $this->user->id, static::REDIRECT_TEMPORARY);
$this->redirect($redirUrl ?? $this->user->identity->getURL());
if(!$this->hasPermission("user", "login", -1)) exit("Вас забанили");
if($_SERVER["REQUEST_METHOD"] === "POST") {
$user = $this->db->table("ChandlerUsers")->where("login", $this->postParam("login"))->fetch();
if(!$user)
$this->flashFail("err", tr("login_failed"), tr("invalid_username_or_password"));
@ -172,8 +171,7 @@ final class AuthPresenter extends OpenVKPresenter
}
$this->authenticator->authenticate($user->id);
$this->redirect($redirUrl ?? "/id" . $user->related("profiles.user")->fetch()->id, static::REDIRECT_TEMPORARY);
exit;
$this->redirect($redirUrl ?? $ovkUser->getURL());
}
}
@ -184,7 +182,7 @@ final class AuthPresenter extends OpenVKPresenter
if($uuid === "unset") {
Session::i()->set("_su", NULL);
$this->redirect("/", static::REDIRECT_TEMPORARY);
$this->redirect("/");
}
if(!$this->db->table("ChandlerUsers")->where("id", $uuid))
@ -193,8 +191,7 @@ final class AuthPresenter extends OpenVKPresenter
$this->assertPermission('openvk\Web\Models\Entities\User', 'substitute', 0);
Session::i()->set("_su", $uuid);
$this->flash("succ", tr("profile_changed"), tr("profile_changed_comment"));
$this->redirect("/", static::REDIRECT_TEMPORARY);
exit;
$this->redirect("/");
}
function renderLogout(): void
@ -204,7 +201,7 @@ final class AuthPresenter extends OpenVKPresenter
$this->authenticator->logout();
Session::i()->set("_su", NULL);
$this->redirect("/", static::REDIRECT_TEMPORARY_PRESISTENT);
$this->redirect("/");
}
function renderFinishRestoringPassword(): void
@ -244,7 +241,7 @@ final class AuthPresenter extends OpenVKPresenter
function renderRestore(): void
{
if(!is_null($this->user))
$this->redirect("/id" . $this->user->id, static::REDIRECT_TEMPORARY);
$this->redirect($this->user->identity->getURL());
if(($this->queryParam("act") ?? "default") === "finish")
$this->pass("openvk!Auth->finishRestoringPassword");
@ -274,7 +271,6 @@ final class AuthPresenter extends OpenVKPresenter
];
$this->sendmail($uRow->login, "password-reset", $params); #Vulnerability possible
$this->flashFail("succ", tr("information_-1"), tr("password_reset_email_sent"));
}
}
@ -282,7 +278,7 @@ final class AuthPresenter extends OpenVKPresenter
function renderResendEmail(): void
{
if(!is_null($this->user) && $this->user->identity->isActivated())
$this->redirect("/id" . $this->user->id, static::REDIRECT_TEMPORARY);
$this->redirect($this->user->identity->getURL());
if($_SERVER["REQUEST_METHOD"] === "POST") {
$user = $this->user->identity;
@ -330,6 +326,6 @@ final class AuthPresenter extends OpenVKPresenter
$this->user->identity->reactivate();
$this->redirect("/", 2);
$this->redirect("/");
}
}

View file

@ -24,7 +24,7 @@ final class CommentPresenter extends OpenVKPresenter
if(!is_null($this->user)) $comment->toggleLike($this->user->identity);
$this->redirect($_SERVER["HTTP_REFERER"], static::REDIRECT_TEMPORARY);
$this->redirect($_SERVER["HTTP_REFERER"]);
}
function renderMakeComment(string $repo, int $eId): void

View file

@ -91,7 +91,7 @@ final class GiftsPresenter extends OpenVKPresenter
$gift->used();
$this->flash("succ", "Подарок отправлен", "Вы отправили подарок <b>" . $user->getFirstName() . "</b> за " . $gift->getPrice() . " голосов.");
$this->redirect($user->getURL(), static::REDIRECT_TEMPORARY);
$this->redirect($user->getURL());
}
function renderStub(): void

View file

@ -54,8 +54,7 @@ final class GroupPresenter extends OpenVKPresenter
}
$club->toggleSubscription($this->user->identity);
header("HTTP/1.1 302 Found");
header("Location: /club" . $club->getId());
$this->redirect("/club" . $club->getId());
}else{
$this->flashFail("err", "Ошибка", "Вы не ввели название группы.");
}
@ -74,9 +73,7 @@ final class GroupPresenter extends OpenVKPresenter
$club->toggleSubscription($this->user->identity);
header("HTTP/1.1 302 Found");
header("Location: /club" . $club->getId());
exit;
$this->redirect($club->getURL());
}
function renderFollowers(int $id): void

View file

@ -61,9 +61,7 @@ abstract class OpenVKPresenter extends SimplePresenter
$this->flash($type, $title, $message, $code);
$referer = $_SERVER["HTTP_REFERER"] ?? "/";
header("HTTP/1.1 302 Found");
header("Location: $referer");
exit;
$this->redirect($referer);
}
}
@ -99,9 +97,8 @@ abstract class OpenVKPresenter extends SimplePresenter
}
$this->flash("err", tr("login_required_error"), tr("login_required_error_comment"));
header("HTTP/1.1 302 Found");
header("Location: $loginUrl");
exit;
$this->redirect($loginUrl);
}
}
@ -111,9 +108,7 @@ abstract class OpenVKPresenter extends SimplePresenter
if($model !== "user") {
$this->flash("info", tr("login_required_error"), tr("login_required_error_comment"));
header("HTTP/1.1 302 Found");
header("Location: /login");
exit;
$this->redirect("/login");
}
return ($action === "register" || $action === "login");
@ -227,7 +222,7 @@ abstract class OpenVKPresenter extends SimplePresenter
Authenticator::i()->logout();
Session::i()->set("_su", NULL);
$this->flashFail("err", tr("error"), tr("profile_not_found"));
$this->redirect("/", static::REDIRECT_TEMPORARY);
$this->redirect("/");
}
exit;
}

View file

@ -83,9 +83,9 @@ final class PhotosPresenter extends OpenVKPresenter
$album->save();
if(isset($club))
$this->redirect("/album-" . $album->getOwner()->getId() . "_" . $album->getId(), static::REDIRECT_TEMPORARY);
$this->redirect("/album-" . $album->getOwner()->getId() . "_" . $album->getId());
else
$this->redirect("/album" . $album->getOwner()->getId() . "_" . $album->getId(), static::REDIRECT_TEMPORARY);
$this->redirect("/album" . $album->getOwner()->getId() . "_" . $album->getId());
}
}
@ -204,7 +204,7 @@ final class PhotosPresenter extends OpenVKPresenter
$photo->save();
$this->flash("succ", "Изменения сохранены", "Обновлённое описание появится на странице с фоткой.");
$this->redirect("/photo" . $photo->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/photo" . $photo->getPrettyId());
}
$this->template->photo = $photo;
@ -245,7 +245,7 @@ final class PhotosPresenter extends OpenVKPresenter
$album->setEdited(time());
$album->save();
$this->redirect("/photo" . $photo->getPrettyId() . "?from=album" . $album->getId(), static::REDIRECT_TEMPORARY);
$this->redirect("/photo" . $photo->getPrettyId() . "?from=album" . $album->getId());
} else {
$this->template->album = $album;
}
@ -270,7 +270,7 @@ final class PhotosPresenter extends OpenVKPresenter
$album->save();
$this->flash("succ", "Фотография удалена", "Эта фотография была успешно удалена.");
$this->redirect("/album" . $album->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/album" . $album->getPrettyId());
}
}
@ -289,6 +289,6 @@ final class PhotosPresenter extends OpenVKPresenter
$photo->delete();
$this->flash("succ", "Фотография удалена", "Эта фотография была успешно удалена.");
$this->redirect("/id0", static::REDIRECT_TEMPORARY);
$this->redirect("/id0");
}
}

View file

@ -100,8 +100,7 @@ final class SupportPresenter extends OpenVKPresenter
Telegram::send($helpdeskChat, $telegramText);
}
header("HTTP/1.1 302 Found");
header("Location: /support/view/" . $ticket->getId());
$this->redirect("/support/view/" . $ticket->getId());
} else {
$this->flashFail("err", tr("error"), tr("you_have_not_entered_name_or_text"));
}
@ -192,8 +191,7 @@ final class SupportPresenter extends OpenVKPresenter
$comment->setCreated(time());
$comment->save();
header("HTTP/1.1 302 Found");
header("Location: /support/view/" . $id);
$this->redirect("/support/view/" . $id);
} else {
$this->flashFail("err", tr("error"), tr("you_have_not_entered_text"));
}

View file

@ -108,7 +108,7 @@ final class TopicsPresenter extends OpenVKPresenter
}
} catch(ISE $ex) {
$this->flash("err", "Не удалось опубликовать комментарий", "Файл медиаконтента повреждён или слишком велик.");
$this->redirect("/topic" . $topic->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/topic" . $topic->getPrettyId());
}
if(!empty($this->postParam("text")) || $photo || $video) {
@ -123,7 +123,7 @@ final class TopicsPresenter extends OpenVKPresenter
$comment->save();
} catch (\LengthException $ex) {
$this->flash("err", "Не удалось опубликовать комментарий", "Комментарий слишком большой.");
$this->redirect("/topic" . $topic->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/topic" . $topic->getPrettyId());
}
if(!is_null($photo))
@ -133,7 +133,7 @@ final class TopicsPresenter extends OpenVKPresenter
$comment->attach($video);
}
$this->redirect("/topic" . $topic->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/topic" . $topic->getPrettyId());
}
$this->template->club = $club;
@ -167,7 +167,7 @@ final class TopicsPresenter extends OpenVKPresenter
$topic->save();
$this->flash("succ", tr("changes_saved"), tr("topic_changes_saved_comment"));
$this->redirect("/topic" . $topic->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/topic" . $topic->getPrettyId());
}
$this->template->topic = $topic;
@ -189,6 +189,6 @@ final class TopicsPresenter extends OpenVKPresenter
$this->willExecuteWriteAction();
$topic->deleteTopic();
$this->redirect("/board" . $topic->getClub()->getId(), static::REDIRECT_TEMPORARY);
$this->redirect("/board" . $topic->getClub()->getId());
}
}

View file

@ -80,7 +80,7 @@ final class UserPresenter extends OpenVKPresenter
$name = $user->getFullName();
$this->flash("err", "Ошибка доступа", "Вы не можете просматривать полный список подписок $name.");
$this->redirect("/id$id", static::REDIRECT_TEMPORARY_PRESISTENT);
$this->redirect($user->getURL());
}
}
}
@ -281,7 +281,7 @@ final class UserPresenter extends OpenVKPresenter
$user->toggleSubscription($this->user->identity);
$this->redirect("/id" . $user->getId());
$this->redirect($user->getURL());
}
function renderSetAvatar(): void
@ -587,7 +587,7 @@ final class UserPresenter extends OpenVKPresenter
$this->user->identity->save();
}
$this->redirect("/", static::REDIRECT_TEMPORARY_PRESISTENT);
$this->redirect("/");
}
function renderCoinsTransfer(): void

View file

@ -80,7 +80,7 @@ final class VideosPresenter extends OpenVKPresenter
$video->save();
$this->redirect("/video" . $video->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/video" . $video->getPrettyId());
} else {
$this->flashFail("err", "Произошла ошибка", "Видео не может быть опубликовано без названия.");
}
@ -104,7 +104,7 @@ final class VideosPresenter extends OpenVKPresenter
$video->save();
$this->flash("succ", "Изменения сохранены", "Обновлённое описание появится на странице с видосиком.");
$this->redirect("/video" . $video->getPrettyId(), static::REDIRECT_TEMPORARY);
$this->redirect("/video" . $video->getPrettyId());
}
$this->template->video = $video;
@ -128,7 +128,6 @@ final class VideosPresenter extends OpenVKPresenter
$this->flashFail("err", "Не удалось удалить пост", "Вы не вошли в аккаунт.");
}
$this->redirect("/videos".$owner, static::REDIRECT_TEMPORARY);
exit;
$this->redirect("/videos" . $owner);
}
}

View file

@ -294,11 +294,7 @@ final class WallPresenter extends OpenVKPresenter
if($wall > 0 && $wall !== $this->user->identity->getId())
(new WallPostNotification($wallOwner, $post, $this->user->identity))->emit();
if($wall > 0)
$this->redirect("/id$wall", 2); #Will exit
$wall = $wall * -1;
$this->redirect("/club$wall", 2);
$this->redirect($wallOwner->getURL());
}
function renderPost(int $wall, int $post_id): void
@ -337,10 +333,7 @@ final class WallPresenter extends OpenVKPresenter
$post->toggleLike($this->user->identity);
}
$this->redirect(
"$_SERVER[HTTP_REFERER]#postGarter=" . $post->getId(),
static::REDIRECT_TEMPORARY
);
$this->redirect("$_SERVER[HTTP_REFERER]#postGarter=" . $post->getId());
}
function renderShare(int $wall, int $post_id): void
@ -392,8 +385,7 @@ final class WallPresenter extends OpenVKPresenter
$this->flashFail("err", tr("failed_to_delete_post"), tr("login_required_error_comment"));
}
$this->redirect($wall < 0 ? "/club".($wall*-1) : "/id".$wall, static::REDIRECT_TEMPORARY);
exit;
$this->redirect($wall < 0 ? "/club" . ($wall*-1) : "/id" . $wall);
}
function renderPin(int $wall, int $post_id): void