Skip to content

Commit

Permalink
🚧 Webhook fixes, test for admin app
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHackGUT committed Sep 29, 2019
1 parent f7eb6e7 commit 57e8557
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function handle()
'redirectUri' => $this->provider->getRedirectUri($this->providerEntity),
];

return $this->controller->view('SModders\TelegramCore:AuthMethod\OAuth', 'smodders_tgcore.authmethod_oauth', $viewParams);
return $this->controller->view('SModders\TelegramCore:AuthMethod\OAuth', 'public:smodders_tgcore.authmethod_oauth', $viewParams);
}
}
5 changes: 5 additions & 0 deletions upload/src/addons/SModders/TelegramCore/Cron/LongPoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class LongPoll
public static function process()
{
$app = \XF::app();
if ($app->options()->smodders_tgcore__updateMode != 'longpoll')
{
return;
}

$registry = $app->registry();

// Get offset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,37 @@

class Telegram extends AbstractController
{
public function handleWebhookAction(ParameterBag $params)
public function checkCsrfIfNeeded($action, ParameterBag $params)
{
$this->assertWebHookToken($params->token);
if (strtolower($action) == 'handlewebhook')
{
return;
}

return parent::checkCsrfIfNeeded($action, $params);
}

public function actionHandleWebhook(ParameterBag $params)
{
$this->assertPostOnly();
$this->assertWebHookToken($this->request->get('token'));

try {
$this->getTelegramContainer()
->client()->run();
} catch (\Exception $e) {
\XF::logException($e);
return $this->error($e->getMessage(), 500);
}

return $this->message('Ok');
}

protected function assertWebHookToken($token)
{
if ($token != Hash::hashText($this->getTelegramContainer()['bot.token']))
if ($token != Hash::hashText($this->getTelegramContainer()->get('bot.token')))
{
return $this->noPermission();
throw $this->exception($this->noPermission());
}
}

Expand Down
6 changes: 3 additions & 3 deletions upload/src/addons/SModders/TelegramCore/Service/WebHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


use XF\Service\AbstractService;
use XF\Util\Hash;

class WebHook extends AbstractService
{
Expand All @@ -34,15 +35,14 @@ protected static function getWebhookUrl()
$app = \XF::app();
$options = $app->options();

$link = $options->boardUrl . \XF::app()->router('public')->buildLink('smodders_tgcore/handle-webhook');
$link = $options->boardUrl . \XF::app()->router('public')->buildLink('smodders_telegram/handle-webhook', null, ['token' => Hash::hashText($app->get('smodders.telegram')->get('bot.token'))]);

$webProxy = $options['smodders_tgcore__webHookProxy'];
if (!empty($webProxy))
{
$link = str_replace('{webHook}', urlencode($link), $webProxy);
}

\XF::logError($link);

return $link;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"version_string": "2.0.0 Alpha 1",
"hash": "1dc6980006dcb793901f61fc92250178"
},
"admin/connected_account_provider_test_smodders_telegram.html": {
"version_id": 2000052,
"version_string": "2.0.0 Release Candidate 2",
"hash": "d7f1ece8e61476831c5ef286db77b19a"
},
"public/connected_account_associated_smodders_telegram.html": {
"version_id": 2000013,
"version_string": "2.0.0 Alpha 3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<xf:if is="!$providerData">
<xf:inforow>
{{ phrase('this_will_test_x_connected_account_provider_explain', {'title': $provider.title}) }}
</xf:inforow>
<xf:else />
<xf:inforow rowtype="confirm"><strong>{{ phrase('test_passed') }}</strong></xf:inforow>
<xf:formrow label="{{ phrase('name') }}">{{ $providerData.get('username') ?: phrase('n_a') }}</xf:formrow>
<xf:formrow label="{{ phrase('picture') }}">
<xf:if is="$providerData.get('username')">
<img src="{$providerData.getAvatar()}" width="48" />
<xf:else />
{{ phrase('n_a') }}
</xf:if>
</xf:formrow>
</xf:if>
4 changes: 2 additions & 2 deletions upload/src/addons/SModders/TelegramCore/addon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"legacy_addon_id": "",
"title": "[Telegram] Core",
"description": "Provides the ability to log in via Telegram",
"version_id": 2000051,
"version_string": "2.0.0 Release Candidate 1",
"version_id": 2000052,
"version_string": "2.0.0 Release Candidate 2",
"dev": "SourceModders",
"dev_url": "https://board.kruzya.me",
"faq_url": "https://github.com/XF-Telegram/Core/wiki/FAQ",
Expand Down

0 comments on commit 57e8557

Please sign in to comment.