This repository was archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Login & automatic membership system #109
Open
mfaalk
wants to merge
41
commits into
Glennmen:develop
Choose a base branch
from
mfaalk:loginbranch2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 d448786
Merge pull request #107 from Glennmen/develop
Glennmen 7cfb9ce
Merge branch 'develop' of https://github.com/Glennmen/PMSF
mfaalk f0ace57
[add]from PR 108
mfaalk df239e9
[add]disable IV etc for non logged on & non donators
mfaalk 035ec03
[fix]admin page correction
mfaalk c495506
fixes
mfaalk 8ec19b4
minor text fixes
mfaalk 8e81175
[add]store cookie and destroy previous sessions
mfaalk 3a92b28
[remove]checklogin.php
mfaalk c4a7681
[fix]extend the cookie if it's still valid
mfaalk f061e6c
minor text fix
mfaalk 913680b
[Discord Login]First draft
mfaalk 1875ad5
[Discord Login]indents...
mfaalk b265cb9
[Discord Login]Move settings to config files
72f6a22
[fix]config changes and minor text fixes
mfaalk c4e9b5d
[fix]id in db
mfaalk 16db706
minor text fixes
mfaalk 3b85b21
minor text fixes
mfaalk 4575ff5
[fix]comments from iroken
mfaalk 64644c4
oooops... indents
mfaalk e3508aa
variables
mfaalk de27df2
map.js camel case
mfaalk 23d8d79
styleci
mfaalk 3969099
styleci
mfaalk 65ad092
styleci
mfaalk 0a197f5
styleci
mfaalk 0f5cfe9
multiple fixes
mfaalk d802d11
small fixes
mfaalk 7dffd88
oops
mfaalk 9cca1ae
styleci
mfaalk 136a464
styleci
mfaalk 6354947
[add]allow visitors to create accounts and more...
mfaalk e5566a5
small changes
mfaalk 60eb6b0
styleci
mfaalk 8806128
small updates
mfaalk e032150
styleci
mfaalk 788191c
rename session_id column to lower case
mfaalk d55c76b
rename session_id column to lower case
mfaalk 1a4d418
Make sure the payment is sent from selly and not a fake request :-)
mfaalk 9fb544e
styleci
mfaalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,5 @@ package-lock.json | |
| index.php | ||
| .DS_Store | ||
| static/.DS_Store | ||
| vendor | ||
| composer.lock | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| $discord_bot_client_secret = ""; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 */ | ||
|
|
@@ -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 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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;