2020-05-02 23:45:29 +00:00
< ? php
namespace App\Http\Controllers ;
2020-05-13 21:47:51 +00:00
use App\Http\Requests\ChangeEmailRequest ;
use App\Http\Requests\ChangePasswordRequest ;
use App\Http\Requests\FlushSessionsRequest ;
use App\User ;
2020-05-02 23:45:29 +00:00
use Illuminate\Http\Request ;
2020-05-13 21:47:51 +00:00
use Illuminate\Support\Facades\Auth ;
use Illuminate\Support\Facades\Hash ;
use Illuminate\Support\Facades\Log ;
2020-05-02 23:45:29 +00:00
class UserController extends Controller
{
public function showStaffMembers ()
{
2020-05-03 03:10:33 +00:00
return view ( 'dashboard.administration.staff-members' );
2020-05-02 23:45:29 +00:00
}
public function showPlayers ()
{
2020-05-03 03:31:02 +00:00
return view ( 'dashboard.administration.players' );
2020-05-02 23:45:29 +00:00
}
2020-05-13 21:47:51 +00:00
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 ();
}
2020-05-02 23:45:29 +00:00
}