Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen committed Mar 9, 2024
1 parent d0f5d28 commit 154ee83
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 80 deletions.
79 changes: 1 addition & 78 deletions core/classes/Misc/NamelessOAuth.php
Expand Up @@ -48,7 +48,7 @@ public function getProviders(): array
/**
* Get or create an instance of a specific provider.
*
* @param string $provider The provider name
* @param string $provider The provider name
* @return null|array An array of registered OAuth provider.
*/
public function getProvider(string $provider): ?array
Expand Down Expand Up @@ -176,10 +176,6 @@ public function setEnabled(string $provider, int $enabled): void
*/
public function isSetup(string $provider): bool
{
if (!$this->isEnabled($provider)) {
return false;
}

[$client_id, $client_secret] = $this->getCredentials($provider);

return $client_id !== '' && $client_secret !== '';
Expand Down Expand Up @@ -232,79 +228,6 @@ public function setCredentials(string $provider, string $client_id, string $clie
);
}

/**
* Check if a NamelessMC user has already connected their account to a specific provider.
*
* @param string $provider The provider name
* @param string $provider_id The provider user ID
* @return bool Whether the user is already linked to the provider
*/
public function userExistsByProviderId(string $provider, string $provider_id): bool
{
return $this->_db->query(
'SELECT user_id FROM nl2_oauth_users WHERE provider = ? AND provider_id = ?',
[$provider, $provider_id]
)->count() > 0;
}

/**
* Get the NamelessMC user ID for a specific provider user ID.
*
* @param string $provider The provider name
* @param string $provider_id The provider user ID for lookup
* @return int The NamelessMC user ID of the user linked to the provider
*/
public function getUserIdFromProviderId(string $provider, string $provider_id): int
{
return $this->_db->query(
'SELECT user_id FROM nl2_oauth_users WHERE provider = ? AND provider_id = ?',
[$provider, $provider_id]
)->first()->user_id;
}

/**
* Save a new user linked to a specific provider.
*
* @param string $user_id The NamelessMC user ID
* @param string $provider The provider name
* @param string $provider_id The provider user ID
*/
public function saveUserProvider(string $user_id, string $provider, string $provider_id): void
{
$this->_db->query(
'INSERT INTO nl2_oauth_users (user_id, provider, provider_id) VALUES (?, ?, ?)',
[$user_id, $provider, $provider_id]
);
}

/**
* Get an array of provider names and provider user IDs for a specific user.
*
* @param int $user_id The NamelessMC user ID
* @return array The array
*/
public function getAllProvidersForUser(int $user_id): array
{
return $this->_db->query(
'SELECT * FROM nl2_oauth_users WHERE user_id = ?',
[$user_id]
)->results();
}

/**
* Delete a user's provider data.
*
* @param int $user_id The provider name
* @param string $provider The provider user ID
*/
public function unlinkProviderForUser(int $user_id, string $provider): void
{
$this->_db->query(
'DELETE FROM nl2_oauth_users WHERE user_id = ? AND provider = ?',
[$user_id, $provider]
);
}

/**
* Format an array of CSS rules into a string, appending `!important` to each rule.
*
Expand Down
4 changes: 2 additions & 2 deletions custom/panel_templates/Default/core/integrations_edit.tpl
Expand Up @@ -123,15 +123,15 @@
<div class="form-group">
<label for="client-id">{$CLIENT_ID}</label>
<input type="text" name="client-id" class="form-control"
id="client-id" placeholder="Client ID"
id="client-id" placeholder="{$CLIENT_ID}"
value="{$OAUTH_PROVIDER_DATA['client_id']}">
</div>

<div class="form-group">
<label for="client-secret">{$CLIENT_SECRET}</label>
<input type="password" name="client-secret"
class="form-control" id="client-secret"
placeholder="Client Secret" value="{$OAUTH_PROVIDER_DATA['client_secret']}">
placeholder="{$CLIENT_SECRET}" value="{$OAUTH_PROVIDER_DATA['client_secret']}">
</div>

<div class="form-group">
Expand Down

0 comments on commit 154ee83

Please sign in to comment.