Merge pull request #58 from ControlPanel-gg/add_user_role_in_discord_server

adds the ability to give a role to the discord user on verify
This commit is contained in:
AVMG 2021-06-12 17:29:55 +02:00 committed by GitHub
commit e6159525c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 18 deletions

View file

@ -25,8 +25,10 @@ PAYPAL_EMAIL=
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
#set-up will join users automaticly to your discord
DISCORD_BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN
DISCORD_GUILD_ID=YOUR_DISCORD_SERVER_ID
DISCORD_BOT_TOKEN=
DISCORD_GUILD_ID=
#set-up will give the verified user the given role
DISCORD_ROLE_ID=
#nesseary URL's
PTERODACTYL_URL=https://panel.bitsec.dev

View file

@ -142,19 +142,6 @@ class UserController extends Controller
return redirect()->route('admin.users.index');
}
/**
* @param User $user
* @return RedirectResponse
*/
public function reSendVerificationEmail(User $user)
{
if ($user->hasVerifiedEmail())
return redirect()->back()->with('error', 'User has already verified their email');
$user->sendEmailVerificationNotification();
return redirect()->back()->with('success', 'User has been emailed again!');
}
/**
*
* @throws Exception
@ -187,7 +174,6 @@ class UserController extends Controller
})
->addColumn('actions', function (User $user) {
return '
<a data-content="Resend verification" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.reSendVerificationEmail', $user->id) . '" class="btn btn-sm text-white btn-light mr-1"><i class="far fa-envelope"></i></a>
<a data-content="Login as user" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.loginas', $user->id) . '" class="btn btn-sm btn-primary mr-1"><i class="fas fa-sign-in-alt"></i></a>
<a data-content="Show" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.show', $user->id) . '" class="btn btn-sm text-white btn-warning mr-1"><i class="fas fa-eye"></i></a>
<a data-content="Edit" data-toggle="popover" data-trigger="hover" data-placement="top" href="' . route('admin.users.edit', $user->id) . '" class="btn btn-sm btn-info mr-1"><i class="fas fa-pen"></i></a>

View file

@ -29,8 +29,9 @@ class SocialiteController extends Controller
$discord = Socialite::driver('discord')->user();
$discordUser = DiscordUser::find($discord->id);
$guildId = env('DISCORD_GUILD_ID');
$botToken = env('DISCORD_BOT_TOKEN');
$guildId = env('DISCORD_GUILD_ID');
$roleId = env('DISCORD_ROLE_ID');
//force user into discord server
//TODO Add event on failure, to notify ppl involved
@ -42,6 +43,17 @@ class SocialiteController extends Controller
]
)->put("https://discord.com/api/guilds/{$guildId}/members/{$discord->id}",
['access_token' => $discord->token]);
//give user a role in the discord server
if (!empty($roleId)){
$response = Http::withHeaders(
[
'Authorization' => 'Bot ' . $botToken,
'Content-Type' => 'application/json',
]
)->put("https://discord.com/api/guilds/{$guildId}/members/{$discord->id}/roles/{$roleId}",
['access_token' => $discord->token]);
}
}

View file

@ -70,7 +70,6 @@ Route::middleware('auth')->group(function () {
Route::resource('activitylogs', ActivityLogController::class);
Route::get('users/resendverificationemail/{user}', [UserController::class, 'reSendVerificationEmail'])->name('users.reSendVerificationEmail');
Route::get('users/loginas/{user}', [UserController::class, 'loginAs'])->name('users.loginas');
Route::get('users/datatable', [UserController::class, 'datatable'])->name('users.datatable');
Route::resource('users', UserController::class);