forked from miguel456/rbrecruiter
Made Profile & Account Settings functional
Also moved redundant HTML markup to component file for reuse. Username to UUID converter also added as Middleware
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Profile;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use function GuzzleHttp\Psr7\str;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
@@ -50,6 +52,7 @@ class RegisterController extends Controller
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'uuid' => ['required', 'string', 'unique:users', 'min:32', 'max:32'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||
@@ -64,11 +67,24 @@ class RegisterController extends Controller
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
|
||||
$user = User::create([
|
||||
'uuid' => $data['uuid'],
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
'originalIP' => request()->ip()
|
||||
]);
|
||||
|
||||
Profile::create([
|
||||
|
||||
'profileShortBio' => 'Write a one-liner about you here!',
|
||||
'profileAboutMe' => 'Tell us a bit about you.',
|
||||
'socialLinks' => '{}',
|
||||
'userID' => $user->id
|
||||
|
||||
]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LogController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
@@ -2,15 +2,81 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileSave;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Profile;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
public function showProfile()
|
||||
{
|
||||
|
||||
return view('dashboard.user.profile.userprofile');
|
||||
$socialMediaProfiles = json_decode(Auth::user()->profile->socialLinks, true);
|
||||
|
||||
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',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function saveProfile(ProfileSave $request)
|
||||
{
|
||||
// TODO: Implement profile security policy for logged in users
|
||||
|
||||
$profile = Profile::find(Auth::user()->id);
|
||||
$social = [];
|
||||
|
||||
if (!is_null($profile))
|
||||
{
|
||||
switch ($request->avatarPref)
|
||||
{
|
||||
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);
|
||||
|
||||
$profile->save();
|
||||
|
||||
$request->session()->flash('success', 'Profile settings saved successfully.');
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$gm = 'Guru Meditation #' . rand(0, 1000);
|
||||
Log::alert('[GURU MEDITATION]: Could not find profile for authenticated user ' . Auth::user()->name . 'whilst trying to update it! Please verify that profiles are being created automatically during signup.',
|
||||
[
|
||||
'uuid' => Auth::user()->uuid,
|
||||
'timestamp' => now(),
|
||||
'route' => $request->route()->getName(),
|
||||
'gmcode' => $gm // If this error is reported, the GM code, denoting a severe error, will help us find this entry in the logs
|
||||
|
||||
]);
|
||||
$request->session()->flash('error', 'A technical error has occurred whilst trying to save your profile. Incident details have been recorded. Please report this incident to administrators with the following case number: ' . $gm);
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,14 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ChangeEmailRequest;
|
||||
use App\Http\Requests\ChangePasswordRequest;
|
||||
use App\Http\Requests\FlushSessionsRequest;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@@ -16,4 +23,76 @@ class UserController extends Controller
|
||||
{
|
||||
return view('dashboard.administration.players');
|
||||
}
|
||||
|
||||
public function showAccount()
|
||||
{
|
||||
return view('dashboard.user.profile.useraccount')
|
||||
->with('ip', request()->ip());
|
||||
}
|
||||
|
||||
|
||||
public function flushSessions(FlushSessionsRequest $request)
|
||||
{
|
||||
// TODO: Move all log calls to a listener, which binds to an event fired by each significant event, such as this one
|
||||
// This will allow for other actions to be performed on certain events (like login failed event)
|
||||
|
||||
Auth::logoutOtherDevices($request->currentPasswordFlush);
|
||||
Log::notice('User ' . Auth::user()->name . ' has logged out other devices in their account',
|
||||
[
|
||||
'originIPAddress' => $request->ip(),
|
||||
'userID' => Auth::user()->id,
|
||||
'timestamp' => now()
|
||||
]);
|
||||
|
||||
$request->session()->flash('success', 'Successfully logged out other devices. Remember to change your password if you think you\'ve been compromised.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function changePassword(ChangePasswordRequest $request)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
if (!is_null($user))
|
||||
{
|
||||
$user->password = Hash::make($request->newPassword);
|
||||
$user->save();
|
||||
|
||||
Log::info('User ' . $user->name . ' has changed their password', [
|
||||
'originIPAddress' => $request->ip(),
|
||||
'userID' => $user->id,
|
||||
'timestamp' => now()
|
||||
]);
|
||||
Auth::logout();
|
||||
|
||||
// After logout, the user gets caught by the auth filter, and it automatically redirects back to the previous page
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function changeEmail(ChangeEmailRequest $request)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
if (!is_null($user))
|
||||
{
|
||||
$user->email = $request->newEmail;
|
||||
$user->save();
|
||||
|
||||
Log::notice('User ' . $user->name . ' has just changed their contact email address', [
|
||||
'originIPAddress' => $request->ip(),
|
||||
'userID' => $user->id,
|
||||
'timestamp' => now()
|
||||
]);
|
||||
|
||||
$request->session()->flash('success', 'Your email address has been changed!');
|
||||
}
|
||||
else
|
||||
{
|
||||
$request->session()->flash('error', 'There has been an error whilst trying to update your account. Please contact administrators.');
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user