Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5ea1852
Merge pull request #35 from Glennmen/develop
Glennmen Feb 19, 2018
d448786
Merge pull request #107 from Glennmen/develop
Glennmen Mar 20, 2018
7cfb9ce
Merge branch 'develop' of https://github.com/Glennmen/PMSF
mfaalk Apr 4, 2018
f0ace57
[add]from PR 108
mfaalk Apr 4, 2018
df239e9
[add]disable IV etc for non logged on & non donators
mfaalk Apr 4, 2018
035ec03
[fix]admin page correction
mfaalk Apr 4, 2018
c495506
fixes
mfaalk Apr 10, 2018
8ec19b4
minor text fixes
mfaalk Apr 10, 2018
8e81175
[add]store cookie and destroy previous sessions
mfaalk Apr 11, 2018
3a92b28
[remove]checklogin.php
mfaalk Apr 11, 2018
c4a7681
[fix]extend the cookie if it's still valid
mfaalk Apr 11, 2018
f061e6c
minor text fix
mfaalk Apr 11, 2018
913680b
[Discord Login]First draft
mfaalk Apr 12, 2018
1875ad5
[Discord Login]indents...
mfaalk Apr 12, 2018
b265cb9
[Discord Login]Move settings to config files
Apr 12, 2018
72f6a22
[fix]config changes and minor text fixes
mfaalk Apr 13, 2018
c4e9b5d
[fix]id in db
mfaalk Apr 13, 2018
16db706
minor text fixes
mfaalk Apr 13, 2018
3b85b21
minor text fixes
mfaalk Apr 13, 2018
4575ff5
[fix]comments from iroken
mfaalk Apr 16, 2018
64644c4
oooops... indents
mfaalk Apr 16, 2018
e3508aa
variables
mfaalk Apr 16, 2018
de27df2
map.js camel case
mfaalk Apr 16, 2018
23d8d79
styleci
mfaalk Apr 16, 2018
3969099
styleci
mfaalk Apr 16, 2018
65ad092
styleci
mfaalk Apr 16, 2018
0a197f5
styleci
mfaalk Apr 16, 2018
0f5cfe9
multiple fixes
mfaalk Apr 16, 2018
d802d11
small fixes
mfaalk Apr 17, 2018
7dffd88
oops
mfaalk Apr 17, 2018
9cca1ae
styleci
mfaalk Apr 17, 2018
136a464
styleci
mfaalk Apr 17, 2018
6354947
[add]allow visitors to create accounts and more...
mfaalk Apr 17, 2018
e5566a5
small changes
mfaalk Apr 17, 2018
60eb6b0
styleci
mfaalk Apr 17, 2018
8806128
small updates
mfaalk Apr 17, 2018
e032150
styleci
mfaalk Apr 17, 2018
788191c
rename session_id column to lower case
mfaalk Apr 21, 2018
d55c76b
rename session_id column to lower case
mfaalk Apr 21, 2018
1a4d418
Make sure the payment is sent from selly and not a fake request :-)
mfaalk Apr 23, 2018
9fb544e
styleci
mfaalk Apr 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ package-lock.json
index.php
.DS_Store
static/.DS_Store
vendor
composer.lock
2 changes: 2 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ RewriteRule ^gym_data$ gym_data.php?$1 [QSA,L]
RewriteRule ^motd_data$ motd_data.php?$1 [QSA,L]
RewriteRule ^weather_data$ weather_data.php?$1 [QSA,L]
RewriteRule ^serviceWorker.min.js$ static/dist/js/serviceWorker.min.js?$1 [QSA,L]
RewriteRule ^user$ user.php?$1 [QSA,L]
RewriteRule ^discord-login$ discord-login.php?$1 [QSA,L]
77 changes: 77 additions & 0 deletions DiscordAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
require_once("config/config.php");
require_once("DiscordRedirector.php");
use EasyBib\OAuth2\Client\AuthorizationCodeGrant\ClientConfig;
use EasyBib\OAuth2\Client\AuthorizationCodeGrant\ServerConfig;
use EasyBib\OAuth2\Client\AuthorizationCodeGrant\AuthorizationCodeSession;
use EasyBib\OAuth2\Client\AuthorizationCodeGrant\Authorization\AuthorizationResponse;
use EasyBib\OAuth2\Client\Scope;
use GuzzleHttp\Client;

class DiscordAuth
{
protected $oauthSession;
protected $resource;

protected function setUpOAuth()
{
$httpClient = new Client(['base_uri' => 'https://discordapp.com']);
$redirector = new DiscordRedirector($this);

global $discord_bot_client_id, $discord_bot_client_secret, $discord_bot_redirect_uri;

$clientConfig = new ClientConfig([
'client_id' => $discord_bot_client_id,
'client_secret' => $discord_bot_client_secret,
'redirect_uri' => $discord_bot_redirect_uri
]);

$serverConfig = new ServerConfig([
'authorization_endpoint' => '/api/oauth2/authorize',
'token_endpoint' => '/api/oauth2/token',
]);

$this->oauthSession = new AuthorizationCodeSession(
$httpClient,
$redirector,
$clientConfig,
$serverConfig
);

$scope = new Scope(['identify']);
$this->oauthSession->setScope($scope);
}

public function gotoDiscord(){
$this->setUpOAuth();
return $this->oauthSession->authorize();

}

public function handleAuthorizationResponse()
{
$this->setUpOAuth();
$authorizationResponse = new AuthorizationResponse($_GET);
$this->oauthSession->handleAuthorizationResponse($authorizationResponse);
}

private function setUpResource(){
if ($this->resource != null) {
return $this->resource;
}
$handler = \GuzzleHttp\HandlerStack::create();
$handler->before('http_errors', function ($callable) {
return new \EasyBib\Guzzle\BearerAuthMiddleware($callable, $this->oauthSession);
});
$this->resource = new \GuzzleHttp\Client([
'base_uri' => 'https://discordapp.com',
'handler' => $handler,
]);

}

public function get($uri) {
$this->setUpResource();
return $this->resource->get($uri)->getBody()->getContents();
}
}
18 changes: 18 additions & 0 deletions DiscordRedirector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
require_once("vendor/autoload.php");
use EasyBib\OAuth2\Client\AuthorizationCodeGrant\RedirectorInterface;

class DiscordRedirector implements RedirectorInterface
{
private $controller;

public function __construct()
{
}

public function redirect($url)
{
// does something which eventually calls header() to redirect user
return header("Location: $url");
}
}
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Discord Login",
"description": "Discord Login for PMSF",
"require": {
"easybiblabs/oauth2-client-php": "^4.1"
}
}
92 changes: 76 additions & 16 deletions config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,98 @@
$motdTitle = "";
$motdContent = "";

//-----------------------------------------------------
// Login
//-----------------------------------------------------

$noNativeLogin = true; // true/false - This will enable the built in login system.

$noDiscordLogin = true; // true/false - This will enable login through discord. A discord bot is needed for this to work.
// Composer is also needed. Type "composer install" to install the dependencies.
// Enter client_id, client_secret and callback uri from your discord bot to DiscordAuth.php
// https://discordapp.com/developers/applications/me
$discord_bot_client_id = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert to Camel Case Like $discordBotClientID = 0;

$discord_bot_client_secret = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert to Camel Case Like $discordBotClientSecret = '';

$discord_bot_redirect_uri = "https://example.com/discord-callback.php";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert to Camel Case Like $discordBotRedirectURI= "https://example.com/discord-callback.php";


$adminUsers = array('admin@example.com', 'Superadmin#13337'); // You can add multiple admins by adding them to the array.
$logfile = '../members.log'; // Path to log file. Make sure this works as it will be your life saver if your db crashes.

//-----------------------------------------------------
// FRONTEND SETTINGS
//-----------------------------------------------------

if ($noNativeLogin === true && $noDiscordLogin == true || (($noNativeLogin === false || $noDiscordLogin === false) && !empty($_SESSION['user']->expire_timestamp) && $_SESSION['user']->expire_timestamp > time())) {

/*
THESE SETTINGS WILL BE APPLIED IF:
- LOGIN IS DISABLED
- LOGIN IS ENABLED AND THE USER IS LOGGED ON
*/

/* Marker Settings */
$noExcludeMinIV = false; // true/false
$noMinIV = false; // true/false
$noMinLevel = false; // true/false
$noHighLevelData = false; // true/false

/* Notification Settings */
$noNotifyPokemon = false; // true/false
$noNotifyRarity = false; // true/false
$noNotifyIv = false; // true/false
$noNotifyLevel = false; // true/false
$noNotifyRaid = false; // true/false
$noNotifySound = false; // true/false
$noCriesSound = false; // true/false
$noNotifyBounce = false; // true/false
$noNotifyNotification = false; // true/false

/* Style Settings */
$iconNotifySizeModifier = 15; // 0, 15, 30, 45

} else {

/*
THESE SETTINGS WILL BE APPLIED IF:
- LOGIN IS ENABLED AND THE USER IS NOT A DONATOR
*/

/* Marker Settings */
$noExcludeMinIV = true; // true/false
$noMinIV = true; // true/false
$noMinLevel = true; // true/false
$noHighLevelData = true; // true/false

/* Notification Settings */
$noNotifyPokemon = true; // true/false
$noNotifyRarity = true; // true/false
$noNotifyIv = true; // true/false
$noNotifyLevel = true; // true/false
$noNotifyRaid = true; // true/false
$noNotifySound = true; // true/false
$noCriesSound = true; // true/false
$noNotifyBounce = true; // true/false
$noNotifyNotification = true; // true/false

/* Style Settings */
$iconNotifySizeModifier = 0; // 0, 15, 30, 45

}

/* Marker Settings */

$noPokemon = false; // true/false
$enablePokemon = 'true'; // true/false
$noPokemonNumbers = false; // true/false
$noHighLevelData = false; // true/false
$noHidePokemon = false; // true/false
$hidePokemon = '[10, 13, 16, 19, 21, 29, 32, 41, 46, 48, 50, 52, 56, 74, 77, 96, 111, 133,
161, 163, 167, 177, 183, 191, 194, 168]'; // [] for empty
$hidePokemonCoords = true; // true/false

$noExcludeMinIV = false; // true/false
$hidePokemonCoords = false; // true/false

$excludeMinIV = '[131, 143, 147, 148, 149, 248]'; // [] for empty

$noMinIV = false; // true/false
$minIV = '0'; // "0" for empty or a number

$noMinLevel = false; // true/false
$minLevel = '0'; // "0" for empty or a number

$noBigKarp = false; // true/false
Expand Down Expand Up @@ -148,31 +218,22 @@

/* Notification Settings */

$noNotifyPokemon = false; // true/false
$notifyPokemon = '[201]'; // [] for empty

$noNotifyRarity = false; // true/false
$notifyRarity = '[]'; // "Common", "Uncommon", "Rare", "Very Rare", "Ultra Rare"

$noNotifyIv = false; // true/false
$notifyIv = '""'; // "" for empty or a number

$noNotifyLevel = false; // true/false
$notifyLevel = '""'; // "" for empty or a number

$noNotifyRaid = false; // true/false
$notifyRaid = 5; // O to disable

$noNotifySound = false; // true/false
$notifySound = 'false'; // true/false

$noCriesSound = false; // true/false
$criesSound = 'false'; // true/false

$noNotifyBounce = false; // true/false
$notifyBounce = 'true'; // true/false

$noNotifyNotification = false; // true/false
$notifyNotification = 'true'; // true/false

/* Style Settings */
Expand All @@ -189,7 +250,6 @@
$iconSize = 0; // -8, 0, 10, 20

$noIconNotifySizeModifier = false; // true/false | Increase size of notified Pokemon
$iconNotifySizeModifier = 15; // 0, 15, 30, 45

$noGymStyle = false; // true/false
$gymStyle = 'ingame'; // ingame, shield
Expand Down
Loading