Skip to content

Commit

Permalink
Small fixes and improvements
Browse files Browse the repository at this point in the history
* Reset auth API access token when password is changed (fixes #370)
* Fix error with Rust servers (fixes #363)
* Fix username validation for Steam games (fixes #367)
* Use website name for Discord links (closes #365)
* Add support for new Discord usernames format
  • Loading branch information
MrMicky-FR committed Aug 27, 2023
1 parent 9f06caa commit 259ad01
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/Azuriom.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Azuriom
*
* @var string
*/
private const VERSION = '1.1.3';
private const VERSION = '1.1.4';

/**
* Get the current version of Azuriom CMS.
Expand Down
2 changes: 1 addition & 1 deletion app/Games/Steam/Servers/SteamBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function replaceSteamPlaceholders(string $command, User $user = null): st

return $this->replacePlaceholders($command, $user)
->replace('{steam_id}', $user->game_id)
->replace('{steam_id_32}', SteamID::convertTo32($user->game_id));
->replace('{steam_id_32}', SteamID::convertTo32((int) $user->game_id));
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected function mapCommands(Collection $commands): Collection
return [
'name' => $user->name,
'uid' => $user->game_id,
'steamid_32' => SteamID::convertTo32($user->game_id),
'steamid_32' => SteamID::convertTo32((int) $user->game_id),
'values' => $serverCommands->pluck('command'),
];
});
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public function updatePassword(Request $request)
$password = $request->input('password');
$user = $request->user();

$user->update(['password' => $password]);
$user->update([
'password' => $password,
'access_token' => null,
]);

Auth::logoutOtherDevices($password);
event(new PasswordReset($user));

Expand Down Expand Up @@ -254,6 +258,8 @@ public function unlinkDiscord(Request $request)
*/
public function discordCallback(Request $request)
{
abort_if(! $request->filled('code'), 401);

$user = $request->user();
$discordUser = Socialite::driver('discord')->user();

Expand Down
3 changes: 1 addition & 2 deletions app/Rules/Username.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Azuriom\Rules;

use Azuriom\Games\Minecraft\MinecraftBedrockGame;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

Expand All @@ -15,7 +14,7 @@ class Username implements ValidationRule
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (! oauth_login() && ! game() instanceof MinecraftBedrockGame) {
if (oauth_login()) {
return;
}

Expand Down
7 changes: 6 additions & 1 deletion app/Socialite/DiscordProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Azuriom\Socialite;

use Illuminate\Support\Str;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\ProviderInterface;
use Laravel\Socialite\Two\User;
Expand Down Expand Up @@ -70,9 +71,13 @@ protected function getUserByToken($token)
*/
protected function mapUserToObject(array $user)
{
$discriminator = $user['discriminator']
? '#'.Str::padLeft($user['discriminator'], 4, '0')
: '';

return (new User())->setRaw($user)->map([
'id' => $user['id'],
'nickname' => "{$user['username']}#{$user['discriminator']}",
'nickname' => $user['username'].$discriminator,
'name' => $user['username'],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Support/Discord/LinkedRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function linkRole(DiscordAccount $user, Role $role = null)

$url = self::BASE_URL."/users/@me/applications/{$clientId}/role-connection";
Http::asJson()->withToken($accessToken)->put($url, [
'platform_name' => 'Azuriom Discord Bridge',
'platform_name' => site_name(),
'metadata' => [
'role_id' => $role->id,
'role_power' => $role->power,
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
'discord' => [
'title' => 'Link Discord roles',
'enable' => 'Enable Discord roles link',
'enable_info' => 'Once enabled, edit the role on Discord, and add a requirement in the <b>Links</b> tab.',
'enable_info' => 'Once enabled, edit the role on Discord, and add a requirement in the <b>Links</b> tab. Users can get their Discord role in the server menu, in <b>Linked Roles</b>.',
'info' => 'You need to create an application on the <a href="https://discord.com/developers/applications" target="_blank">Discord developer dashboard</a> and set the <b>Linked Role Verification URL</b> to <code>:url</code>',
'oauth' => 'Then, in <b>OAuth2</b> and in <b>General</b>, you need to add <code>:url</code> in the <b>Redirects</b>.',
'token_info' => 'The Bot token can be obtained by creating a bot for your application, in the <b>Bot</b> tab on the left of the Discord developer dashboard.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
'discord' => [
'title' => 'Lier les grades avec Discord',
'enable' => 'Activer la liaison des grades avec Discord',
'enable_info' => 'Une fois activé, modifiez le rôle sur Discord, et ajoutez un pré-requis dans l\'onglet <b>Liens</b>.',
'enable_info' => 'Une fois activé, modifiez le rôle sur Discord, et ajoutez un pré-requis dans l\'onglet <b>Liens</b>. Les utilisateurs pourront récupérer leur rôle Discord dans le menu du serveur, dans <b>Rôles liés</b>.',
'info' => 'Vous devez créer une application sur le <a href="https://discord.com/developers/applications" target="_blank">portail développeur Discord</a> et définir <b>l\'URL de vérification</b> sur <code>:url</code>',
'oauth' => 'Puis, dans <b>OAuth2</b> et <b>Général</b>, vous devez ajouter <code>:url</code> dans les <b>Redirections</b>.',
'token_info' => 'Le token du Bot peut être obtenu en créant un bot pour votre application, dans l\'onglet <b>Bot</b> à gauche du portail développeur Discord.',
Expand Down

0 comments on commit 259ad01

Please sign in to comment.