Skip to content

Commit

Permalink
⚡ add device management function and route
Browse files Browse the repository at this point in the history
This feature allows you to log out from different devices using a single button click. For this function to work, the SESSION_DRIVER must be a database. In addition, the function "Remember Me" cannot be used and is therefore hidden.
  • Loading branch information
roelreijneveld committed Dec 13, 2020
1 parent 03ce47e commit e3a5ae9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
16 changes: 14 additions & 2 deletions stubs/app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function editProfile(){
/**
* Update the Avatar
*
* @param Request
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function updateAvatar(Request $request){
Expand Down Expand Up @@ -103,4 +103,16 @@ public function removeOldAvatar($internalRequest = false){
return \Redirect::back()->with('success', 'The avatar has been deleted successfully!');
}
}
}

/**
* Remove unused device
*
* @param \Illuminate\Http\Request $request
* @param $id
* @return \Illuminate\Http\Response
*/
public function removeDevice(Request $request, $id){
$delete = \DB::table('sessions')->where('id', $id)->delete();
return \Redirect::back()->with('success', 'The device has been deleted successfully!');
}
}
4 changes: 2 additions & 2 deletions stubs/resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
</div>
</div>

<div class="mb-2">
{{-- <div class="mb-2">
<label class="form-check">
<input type="checkbox" name="remember" class="form-check-input" tabindex="3" />
<span class="form-check-label">{{ __('auth.rememberme') }}</span>
</label>
</div>
</div> --}}
<div class="form-footer">
<button type="submit" class="btn btn-primary w-100" tabindex="4">{{ __('auth.loginbutton') }}</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion stubs/resources/views/profile/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class="avatar avatar-xl"></span>
@if(\Session::getId() == $device->id)
<button disabled="disabled" class="btn btn-primary">Current Device</button>
@else
<form action="{{ route('profile.deletedevice', $device->id) }}"
<form action="{{ route('profile.deletedevice', ['id' => $device->id]) }}"
method="post">
@csrf
@method('DELETE')
Expand Down
2 changes: 1 addition & 1 deletion stubs/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
Route::get('/profile', [ProfileController::class, 'editProfile'])->name('profile');
Route::post('/profile/avatar', [ProfileController::class, 'updateAvatar'])->name('profile.avatar');
Route::delete('/profile/avatar', [ProfileController::class, 'removeOldAvatar'])->name('profile.deleteavatar');
Route::delete('/profile/device', [ProfileController::class, ''])->name('profile.deletedevice');
Route::delete('/profile/device/{id}', [ProfileController::class, 'removeDevice'])->name('profile.deletedevice');
});

0 comments on commit e3a5ae9

Please sign in to comment.