Removed chat token creation.
This commit is contained in:
parent
6d3a24c723
commit
51bc99e454
2 changed files with 11 additions and 42 deletions
|
@ -271,47 +271,15 @@ final class SockChatHandler extends Handler {
|
|||
|
||||
public function login(HttpResponse $response, HttpRequest $request) {
|
||||
$currentUser = User::getCurrent();
|
||||
|
||||
if($currentUser === null) {
|
||||
$response->redirect(url('auth-login'));
|
||||
return;
|
||||
}
|
||||
|
||||
$params = $request->getQueryParams();
|
||||
|
||||
try {
|
||||
$token = UserChatToken::create($currentUser);
|
||||
} catch(UserChatTokenCreationFailedException $ex) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
if(MSZ_DEBUG && isset($params['dump'])) {
|
||||
$ipAddr = $request->getRemoteAddress();
|
||||
$hash = hash_hmac('sha256', implode('#', [$token->getUserId(), $token->getToken(), $ipAddr]), $this->hashKey);
|
||||
|
||||
$response->setText(sprintf(
|
||||
'/_sockchat.php?user_id=%d&token=%s&ip=%s&hash=%s',
|
||||
$token->getUserId(),
|
||||
$token->getToken(),
|
||||
urlencode($ipAddr),
|
||||
$hash
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
$cookieName = Config::get('sockChat.cookie', Config::TYPE_STR, 'sockchat_auth');
|
||||
$cookieData = implode('_', [$token->getUserId(), $token->getToken()]);
|
||||
$cookieDomain = '.' . $request->getHeaderLine('Host');
|
||||
setcookie($cookieName, $cookieData, $token->getExpirationTime(), '/', $cookieDomain);
|
||||
|
||||
$configKey = isset($params['legacy']) ? 'sockChat.chatPath.legacy' : 'sockChat.chatPath.normal';
|
||||
$chatPath = Config::get($configKey, Config::TYPE_STR, '/');
|
||||
|
||||
if(MSZ_DEBUG) {
|
||||
$response->setText(sprintf('Umi.Cookies.Set(\'%s\', \'%s\');', $cookieName, $cookieData));
|
||||
} else {
|
||||
$response->redirect($chatPath);
|
||||
}
|
||||
$response->redirect(
|
||||
$currentUser === null
|
||||
? url('auth-login', ['redirect' => $chatPath])
|
||||
: $chatPath
|
||||
);
|
||||
}
|
||||
|
||||
public function bump(HttpResponse $response, HttpRequest $request): void {
|
||||
|
|
11
src/url.php
11
src/url.php
|
@ -265,13 +265,14 @@ function url_prefix(bool $trailingSlash = true): string {
|
|||
function is_local_url(string $url): bool {
|
||||
$length = mb_strlen($url);
|
||||
|
||||
if($length < 1) {
|
||||
if($length < 1)
|
||||
return false;
|
||||
}
|
||||
|
||||
if($url[0] === '/' && ($length > 1 ? $url[1] !== '/' : true)) {
|
||||
if($url[0] === '/' && ($length > 1 ? $url[1] !== '/' : true))
|
||||
return true;
|
||||
}
|
||||
|
||||
return starts_with($url, url_prefix());
|
||||
if(starts_with($url, url_prefix()))
|
||||
return true;
|
||||
|
||||
return ends_with(parse_url($url, PHP_URL_HOST), '.' . $_SERVER['HTTP_HOST']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue