Skip to content

Commit

Permalink
formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
T1Il committed May 24, 2023
1 parent 809b9a8 commit 3f013ff
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 82 deletions.
133 changes: 52 additions & 81 deletions login.php
Original file line number Diff line number Diff line change
@@ -1,100 +1,71 @@
<?php
include_once 'pdo.php';
require 'vendor/autoload.php';
include_once 'php/login.inc.php';
require_once 'pdo.php';
require_once 'vendor/autoload.php';
require_once 'php/login.inc.php';

try {
$provider = new \Wohali\OAuth2\Client\Provider\Discord([
'clientId' => getenv("BOT_CLIENT_ID"),
'clientSecret' => getenv("BOT_CLIENT_SECRET"),
'redirectUri' => getenv("BOT_REDIRECT_URI"),
]);

$options = [
'scope' => ['guilds', 'identify'],
];

if (empty($_GET['code'])) {
$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();

if (isset($_GET['action'], $_GET['req_id'])) {
$_SESSION['action'] = $_GET['action'];
$_SESSION['req_id'] = $_GET['req_id'];
} elseif (isset($_GET['redirect'])) {
$_SESSION['redirect'] = $_GET['redirect'];
}

$provider = new \Wohali\OAuth2\Client\Provider\Discord([
'clientId' => getenv("BOT_CLIENT_ID"),
'clientSecret' => getenv("BOT_CLIENT_SECRET"),
'redirectUri' => getenv("BOT_REDIRECT_URI"),
]);

$options = [

'scope'=> [

'guilds',
'identify',

],

];

if (!isset($_GET['code'])) {

$authUrl = $provider->getAuthorizationUrl($options);
$_SESSION['oauth2state'] = $provider->getState();

if(isset($_GET['action'],$_GET['req_id'])) {

$_SESSION['action'] = $_GET['action'];
$_SESSION['req_id'] = $_GET['req_id'];

} else if(isset($_GET['redirect'])) {

$_SESSION['redirect'] = $_GET['redirect'];

header('Location: ' . $authUrl);
exit;
}

header('Location: ' . $authUrl);

} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

unset($_SESSION['oauth2state']);
exit('Invalid state');

} else {

try {

$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);

$mysql = new MySQL();
$pdo = $mysql->getPDO();

$user = $provider->getResourceOwner($token);
$login = new User($user->getId());

if ($login->exists) {

$login->login($token->getToken(), $token->getRefreshToken());

if(isset($_SESSION['action'],$_SESSION['req_id'])) {

header('Location: process.php?action=' .$_SESSION['action'] . '&req_id=' . $_SESSION['req_id'] . '&from=login');
unset($_SESSION['action'],$_SESSION['req_id']);
exit(1);
if (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
}

} else if(isset($_SESSION['redirect'])) {
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code'],
]);

header('Location: ' . $_SESSION['redirect']);
unset($_SESSION['redirect']);
exit(1);
$mysql = new MySQL();
$pdo = $mysql->getPDO();

}
$user = $provider->getResourceOwner($token);
$login = new User($user->getId());

header('Location: index.php');
if ($login->exists) {
$login->login($token->getToken(), $token->getRefreshToken());

if (isset($_SESSION['action'], $_SESSION['req_id'])) {
$url = 'process.php?action=' . $_SESSION['action'] . '&req_id=' . $_SESSION['req_id'] . '&from=login';
unset($_SESSION['action'], $_SESSION['req_id']);
} elseif (isset($_SESSION['redirect'])) {
$url = $_SESSION['redirect'];
unset($_SESSION['redirect']);
} else {

$login->register($token->getToken(), $token->getRefreshToken());
header('Location: index.php');

$url = 'index.php';
}

} catch (Exception $e) {
echo $e->getMessage();
header('Location: login.php');
header('Location: ' . $url);
exit(1);
}

}
$login->register($token->getToken(), $token->getRefreshToken());
header('Location: index.php');
exit(1);

} catch(Exception $e) {

header('Location: login.php');

}
exit;
}
2 changes: 1 addition & 1 deletion process.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use JetBrains\PhpStorm\Pure;

include_once('pdo.php');
require 'vendor/autoload.php';
require_once 'vendor/autoload.php';
include_once('php/checklogin.php');
include_once('php/token.inc.php');
include_once('php/login.inc.php');
Expand Down

0 comments on commit 3f013ff

Please sign in to comment.