diff --git a/VKAPI/Handlers/Messages.php b/VKAPI/Handlers/Messages.php index 75034d91..2d9b575e 100644 --- a/VKAPI/Handlers/Messages.php +++ b/VKAPI/Handlers/Messages.php @@ -280,7 +280,7 @@ final class Messages extends VKAPIRequestHandler if($group_id > 0) $this->fail(-151, "Not implemented"); - $url = "http" . ($_SERVER["HTTPS"] === "on" ? "s" : "") . "://$_SERVER[HTTP_HOST]/nim" . $this->getUser()->getId(); + $url = "http" . (ovk_is_ssl() ? "s" : "") . "://$_SERVER[HTTP_HOST]/nim" . $this->getUser()->getId(); $key = openssl_random_pseudo_bytes(8); $key = bin2hex($key) . bin2hex($key ^ ( ~CHANDLER_ROOT_CONF["security"]["secret"] | ((string) $this->getUser()->getId()) )); $res = [ diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index e73bfb29..3555d30f 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -498,10 +498,9 @@ class User extends RowModel function getRefLinkId(): string { - $rand = openssl_random_pseudo_bytes(SODIUM_CRYPTO_STREAM_NONCEBYTES); # anime :) - $key = substr(hex2bin(CHANDLER_ROOT_CONF["security"]["secret"]), 0, SODIUM_CRYPTO_STREAM_KEYBYTES); + $hash = hash_hmac("Snefru", (string) $this->getId(), CHANDLER_ROOT_CONF["security"]["secret"], true); - return bin2hex($rand) . bin2hex(sodium_crypto_stream_xor((string) $this->getId(), $rand, $key)); + return dechex($this->getId()) . " " . base64_encode($hash); } function getNsfwTolerance(): int diff --git a/Web/Presenters/AboutPresenter.php b/Web/Presenters/AboutPresenter.php index 0978b550..411b01de 100644 --- a/Web/Presenters/AboutPresenter.php +++ b/Web/Presenters/AboutPresenter.php @@ -37,7 +37,9 @@ final class AboutPresenter extends OpenVKPresenter {} function renderInvite(): void - {} + { + $this->assertUserLoggedIn(); + } function renderDonate(): void { diff --git a/Web/Presenters/AuthPresenter.php b/Web/Presenters/AuthPresenter.php index 7ebead1c..9699568b 100644 --- a/Web/Presenters/AuthPresenter.php +++ b/Web/Presenters/AuthPresenter.php @@ -57,6 +57,26 @@ final class AuthPresenter extends OpenVKPresenter if(!$this->hasPermission("user", "register", -1)) exit("Вас забанили"); + $referer = NULL; + if(!is_null($refLink = $this->queryParam("ref"))) { + $pieces = explode(" ", $refLink, 2); + if(sizeof($pieces) !== 2) + $this->flashFail("err", "Пригласительная ссылка кривая", "Пригласительная ссылка недействительна."); + + [$ref, $hash] = $pieces; + $ref = hexdec($ref); + $hash = base64_decode($hash); + + $referer = (new Users)->get($ref); + if(!$referer) + $this->flashFail("err", "Пригласительная ссылка кривая", "Пригласительная ссылка недействительна."); + + if($referer->getRefLinkId() !== $refLink) + $this->flashFail("err", "Пригласительная ссылка кривая", "Пригласительная ссылка недействительна."); + } + + $this->template->referer = $referer; + if($_SERVER["REQUEST_METHOD"] === "POST") { $this->assertCaptchaCheckPassed(); @@ -80,6 +100,11 @@ final class AuthPresenter extends OpenVKPresenter $user->setRegistering_Ip(CONNECTING_IP); $user->save(); + if(!is_null($referer)) { + $user->toggleSubscription($referer); + $referer->toggleSubscription($user); + } + $this->authenticator->authenticate($chUser->getId()); $this->redirect("/id" . $user->getId(), static::REDIRECT_TEMPORARY); } diff --git a/Web/Presenters/templates/About/Invite.xml b/Web/Presenters/templates/About/Invite.xml index 0708ea76..95b101e3 100644 --- a/Web/Presenters/templates/About/Invite.xml +++ b/Web/Presenters/templates/About/Invite.xml @@ -8,11 +8,7 @@ {block content} Вы можете пригласить своих друзей или знакомых в сеть с помощью индивидуальной ссылки:

- getRefLinkId()}" size="50" /> + getRefLinkId())}" size="50" />

Приложите эту ссылку к вашему сообщению. Пользователь зарегистрируется, и он сразу появится у вас в друзьях.

-
- Пока не работает
- Надо индивидуальный токен создать для такой ссылки, а то пиздец будет. -
{/block} diff --git a/Web/Presenters/templates/Auth/Register.xml b/Web/Presenters/templates/Auth/Register.xml index 2a641bc9..988998b4 100644 --- a/Web/Presenters/templates/Auth/Register.xml +++ b/Web/Presenters/templates/Auth/Register.xml @@ -1,78 +1,94 @@ -{extends "../@layout.xml"} -{block title}{_"registration"}{/block} - -{block header} - {_"registration"} -{/block} - -{block content} -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- {_"name"}: - - -
- {_"surname"}: - - -
- {_"gender"}: - - {var femalePreferred = OPENVK_ROOT_CONF["openvk"]["preferences"]["femaleGenderPriority"]} - -
- {_"email"}: - - -
- {_"password"}: - - -
- CAPTCHA: - - {captcha_template()|noescape} -
- - - - - {_"log_in"} -
-
-{/block} +{extends "../@layout.xml"} +{block title}{_"registration"}{/block} + +{block header} + {_"registration"} +{/block} + +{block headIncludes} + {if !$referer} + + {else} + + + + + {/if} +{/block} + +{block content} +

+ {$referer->getFullName()} приглашает вас в OpenVK! +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {_"name"}: + + +
+ {_"surname"}: + + +
+ {_"gender"}: + + {var femalePreferred = OPENVK_ROOT_CONF["openvk"]["preferences"]["femaleGenderPriority"]} + +
+ {_"email"}: + + +
+ {_"password"}: + + +
+ CAPTCHA: + + {captcha_template()|noescape} +
+ + + + + {_"log_in"} +
+
+{/block} diff --git a/Web/di.yml b/Web/di.yml index a91d4f2a..19bdc527 100644 --- a/Web/di.yml +++ b/Web/di.yml @@ -2,6 +2,7 @@ services: - openvk\Web\Presenters\AwayPresenter - openvk\Web\Presenters\AboutPresenter - openvk\Web\Presenters\AuthPresenter + - openvk\Web\Presenters\AudiosPresenter - openvk\Web\Presenters\UserPresenter - openvk\Web\Presenters\WallPresenter - openvk\Web\Presenters\CommentPresenter diff --git a/Web/routes.yml b/Web/routes.yml index 963c53eb..7db983e1 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -151,6 +151,24 @@ routes: handler: "User->groups" - url: "/groups_create" handler: "Group->create" + - url: "/audios{num}" + handler: "Audios->app" + - url: "/audios{num}.json" + handler: "Audios->apiListSongs" + - url: "/audios/popular.json" + handler: "Audios->apiListPopSongs" + - url: "/audios/playlist{num}.json" + handler: "Audios->apiListPlaylists" + - url: "/audios/search.json" + handler: "Audios->apiSearch" + - url: "/audios/add.json" + handler: "Audios->apiAdd" + - url: "/audios/playlist.json" + handler: "Audios->apiAddPlaylist" + - url: "/audios/upload.json" + handler: "Audios->apiUpload" + - url: "/audios/beacon" + handler: "Audios->apiBeacon" - url: "/im" handler: "Messenger->index" - url: "/im/sel{num}"