mc-cms-namelessmc/core/classes/Integrations/Integrations.php

85 lines
2.1 KiB
PHP
Raw Permalink Normal View History

User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
<?php
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
/**
* Integrations class.
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
*
* @package NamelessMC\Integrations
* @author Partydragen
* @version 2.0.0-pr13
* @license MIT
*/
class Integrations extends Instanceable
{
/**
* @var IntegrationBase[] The array of integrations
*/
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
private array $_integrations = [];
/**
* Register an integration to the integration list.
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
*
* @param IntegrationBase $integration Instance of intagration to register.
*/
public function registerIntegration(IntegrationBase $integration): void
{
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
$this->_integrations[$integration->getName()] = $integration;
}
/**
* Get a integration by name.
*
* @param string $name Name of integration to get.
*
* @return IntegrationBase|null Instance of integration with same name, null if it doesnt exist.
*/
public function getIntegration(string $name): ?IntegrationBase
{
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
foreach ($this->_integrations as $integration) {
if (strcasecmp($name, $integration->getName()) == 0) {
return $integration;
}
}
return null;
}
/**
* List all integrations, sorted by their order.
*
* @return IntegrationBase[] List of integrations.
*/
public function getAll(): iterable
{
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
$integrations = $this->_integrations;
uasort($integrations, static function (IntegrationBase $a, IntegrationBase $b) {
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
return $a->getOrder() - $b->getOrder();
});
return $integrations;
}
/**
* List all enabled integrations, sorted by their order.
*
* @return IntegrationBase[] List of integrations.
*/
public function getEnabledIntegrations(): iterable
{
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
$integrations = $this->_integrations;
User Integrations systems (#2606) * Initial work for User Integrations systems * Convert a few endpoints to new user integration system * Finish minecraft part to new User Integration system * Fixes verify banner issue https://github.com/NamelessMC/Nameless/issues/2052 Fixes https://github.com/NamelessMC/Nameless/issues/2052 * Convert discord to new user integrations system * Update fields to show user integrations * Add user integrations to StaffCP user page / move over * Update UserInfo and Rename MinecraftVerify endpoint * Rework user listing endpoint * Password check never returns null * Add support for offline mode uuid * Fix documentation phpstan warnings * else if * remove die() * Revamp registration page * add integrations settings page * Convert authme & fix phpstan issues * refix settings page * Load uuid when user is loaded * Redirect user to complete required integrations * Fix translation for user connections page * Rework integrations registration in Register Endpoint Completes https://github.com/NamelessMC/Nameless/issues/2516 * make getIntegration ignore case sensitive * Update installer * Update upgrader script to convert users * Fix index for user integrations * Remove uuid from user data * Misc * Remove one unused query * Add event for integration linking, verify and unlink * Finish user transformer, Finish user integrations * Thx phpstan * Fix phpdocs * Fix user reports page * Remove validation banner * Change default field value * resolve samerton feedback * don't clean when inserting data * don't clean event data * remove more clean * increase reset_code length from 60 to 64 * pr13 confirmed * one more clean * Remove API verification setting * Register integrations edit permission * Resolve a few requested changes * Rework username and identifier validation * Add button to sync user integration * Fix Synchronisation text * Fix is verified term Co-authored-by: Robin <robinslot@hotmail.nl> Co-authored-by: Robin <robin+git@rkslot.nl>
2022-04-16 18:42:24 +02:00
$enabled_integrations = [];
foreach ($integrations as $integration) {
if ($integration->isEnabled()) {
$enabled_integrations[] = $integration;
}
}
uasort($enabled_integrations, static function ($a, $b) {
return $a->getOrder() - $b->getOrder();
});
return $enabled_integrations;
}
}