2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2020 Miguel Nogueira
|
|
|
|
*
|
|
|
|
* This file is part of Raspberry Staff Manager.
|
|
|
|
*
|
|
|
|
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
use App\Facades\IP;
|
2020-05-13 21:47:51 +00:00
|
|
|
use App\Http\Requests\ProfileSave;
|
2020-06-26 23:32:33 +00:00
|
|
|
use App\User;
|
|
|
|
use Carbon\Carbon;
|
2020-04-29 17:15:54 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-05-13 21:47:51 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-06-26 23:32:33 +00:00
|
|
|
use Spatie\Permission\Models\Role;
|
2020-04-29 17:15:54 +00:00
|
|
|
|
|
|
|
class ProfileController extends Controller
|
|
|
|
{
|
2020-10-10 16:30:26 +00:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return view('dashboard.user.directory')
|
2020-06-27 18:15:33 +00:00
|
|
|
->with('users', User::with('profile', 'bans')->paginate(9));
|
2020-10-10 16:30:26 +00:00
|
|
|
}
|
2020-06-27 18:15:33 +00:00
|
|
|
|
2020-05-13 21:47:51 +00:00
|
|
|
public function showProfile()
|
|
|
|
{
|
2020-10-10 16:30:26 +00:00
|
|
|
$socialLinks = Auth::user()->profile->socialLinks ?? '[]';
|
2020-06-26 23:32:33 +00:00
|
|
|
$socialMediaProfiles = json_decode($socialLinks, true);
|
2020-05-13 21:47:51 +00:00
|
|
|
|
|
|
|
return view('dashboard.user.profile.userprofile')
|
|
|
|
->with([
|
|
|
|
'profile' => Auth::user()->profile,
|
|
|
|
'github' => $socialMediaProfiles['links']['github'] ?? 'UpdateMe',
|
|
|
|
'twitter' => $socialMediaProfiles['links']['twitter'] ?? 'UpdateMe',
|
|
|
|
'insta' => $socialMediaProfiles['links']['insta'] ?? 'UpdateMe',
|
|
|
|
'discord' => $socialMediaProfiles['links']['discord'] ?? 'UpdateMe#12345',
|
|
|
|
]);
|
|
|
|
}
|
2020-04-30 21:53:57 +00:00
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
// Route model binding
|
|
|
|
public function showSingleProfile(Request $request, User $user)
|
2020-04-30 21:53:57 +00:00
|
|
|
{
|
2020-06-26 23:32:33 +00:00
|
|
|
$socialMediaProfiles = json_decode($user->profile->socialLinks, true);
|
|
|
|
$createdDate = Carbon::parse($user->created_at);
|
|
|
|
|
|
|
|
$systemRoles = Role::all()->pluck('name')->all();
|
|
|
|
$userRoles = $user->roles->pluck('name')->all();
|
|
|
|
|
|
|
|
$roleList = [];
|
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
foreach ($systemRoles as $role) {
|
|
|
|
if (in_array($role, $userRoles)) {
|
|
|
|
$roleList[$role] = true;
|
|
|
|
} else {
|
|
|
|
$roleList[$role] = false;
|
|
|
|
}
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 21:35:49 +00:00
|
|
|
$suspensionInfo = null;
|
|
|
|
if ($user->isBanned())
|
|
|
|
{
|
|
|
|
$suspensionInfo = [
|
|
|
|
|
|
|
|
'isPermanent' => $user->bans->isPermanent,
|
|
|
|
'reason' => $user->bans->reason,
|
|
|
|
'bannedUntil' => $user->bans->bannedUntil
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
if (Auth::user()->is($user) || Auth::user()->can('profiles.view.others')) {
|
2020-06-26 23:32:33 +00:00
|
|
|
return view('dashboard.user.profile.displayprofile')
|
|
|
|
->with([
|
|
|
|
'profile' => $user->profile,
|
|
|
|
'github' => $socialMediaProfiles['links']['github'] ?? 'UpdateMe',
|
|
|
|
'twitter' => $socialMediaProfiles['links']['twitter'] ?? 'UpdateMe',
|
|
|
|
'insta' => $socialMediaProfiles['links']['insta'] ?? 'UpdateMe',
|
|
|
|
'discord' => $socialMediaProfiles['links']['discord'] ?? 'UpdateMe#12345',
|
2020-10-10 16:30:26 +00:00
|
|
|
'since' => $createdDate->englishMonth.' '.$createdDate->year,
|
2020-06-26 23:32:33 +00:00
|
|
|
'ipInfo' => IP::lookup($user->originalIP),
|
2020-10-10 16:30:26 +00:00
|
|
|
'roles' => $roleList,
|
2021-07-20 21:35:49 +00:00
|
|
|
'suspensionInfo' => $suspensionInfo
|
2020-06-26 23:32:33 +00:00
|
|
|
]);
|
2020-10-10 16:30:26 +00:00
|
|
|
} else {
|
2021-07-19 23:35:03 +00:00
|
|
|
abort(403, __('You cannot view someone else\'s profile.'));
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function saveProfile(ProfileSave $request)
|
|
|
|
{
|
|
|
|
$profile = User::find(Auth::user()->id)->profile;
|
2020-05-13 21:47:51 +00:00
|
|
|
$social = [];
|
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
if (! is_null($profile)) {
|
|
|
|
switch ($request->avatarPref) {
|
2020-05-13 21:47:51 +00:00
|
|
|
case 'MOJANG':
|
|
|
|
$avatarPref = 'crafatar';
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'GRAVATAR':
|
|
|
|
$avatarPref = strtolower($request->avatarPref);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$social['links']['github'] = $request->socialGithub;
|
|
|
|
$social['links']['twitter'] = $request->socialTwitter;
|
|
|
|
$social['links']['insta'] = $request->socialInsta;
|
|
|
|
$social['links']['discord'] = $request->socialDiscord;
|
|
|
|
|
|
|
|
$profile->profileShortBio = $request->shortBio;
|
|
|
|
$profile->profileAboutMe = $request->aboutMe;
|
|
|
|
$profile->avatarPreference = $avatarPref;
|
|
|
|
$profile->socialLinks = json_encode($social);
|
|
|
|
|
2020-06-26 23:32:33 +00:00
|
|
|
$newProfile = $profile->save();
|
2020-05-13 21:47:51 +00:00
|
|
|
|
2021-07-19 23:35:03 +00:00
|
|
|
$request->session()->flash('success', __('Profile settings saved successfully.'));
|
2020-05-13 21:47:51 +00:00
|
|
|
}
|
2020-04-30 21:53:57 +00:00
|
|
|
|
2020-05-13 21:47:51 +00:00
|
|
|
return redirect()->back();
|
2020-04-30 21:53:57 +00:00
|
|
|
}
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|