Commit 01aa7e6d authored by Jacob Priddy's avatar Jacob Priddy 👌

redirect to admin login page on admin logout. also modify routes and

rename a gate
parent 9bec04d2
......@@ -149,10 +149,12 @@ class AuthController extends ApiController
{
$this->cookieJar->queue($this->cookieJar->forget('api_token'));
return redirect()->to(
$authenticateUseCase->samlLogout(
$this->request->cookie('api_token')
)
);
$logout = $authenticateUseCase->samlLogout($this->request->cookie('api_token'));
if ($this->request->has('intended')) {
$logout = $this->request->input('intended');
}
return redirect($logout);
}
}
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$users = User::count();
$widget = [
'users' => $users,
//...
];
return view('home', compact('widget'));
}
}
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class ProfileController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('profile');
}
public function update(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'last_name' => 'nullable|string|max:255',
'email' => 'required|string|email|max:255|unique:users,email,' . Auth::user()->id,
'current_password' => 'nullable|required_with:new_password',
'new_password' => 'nullable|min:8|max:12|required_with:current_password',
'password_confirmation' => 'nullable|min:8|max:12|required_with:new_password|same:new_password'
]);
$user = User::findOrFail(Auth::user()->id);
$user->name = $request->input('name');
$user->last_name = $request->input('last_name');
$user->email = $request->input('email');
if (!is_null($request->input('current_password'))) {
if (Hash::check($request->input('current_password'), $user->password)) {
$user->password = $request->input('new_password');
} else {
return redirect()->back()->withInput();
}
}
$user->save();
return redirect()->route('profile');
}
}
......@@ -4,9 +4,20 @@
namespace App\Http\Controllers\Web\Admin;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function index(): View
{
$users = \App\User::count();
$widget = [
'users' => $users,
//...
];
return view('admin.home', compact('widget'));
}
}
......@@ -27,7 +27,7 @@ class AuthServiceProvider extends ServiceProvider
$this->registerGateMapping($authorizer);
Gate::define('view-admin-page', static function (Authenticatable $user) use ($authorizer) {
Gate::define('view-admin-panel', static function (Authenticatable $user) use ($authorizer) {
$authorizer->setCurrentUserId($user->getAuthIdentifier());
try {
......
......@@ -10,7 +10,7 @@
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<title>E-Lock Admin - @yield('title')</title>
<!-- Fonts -->
<link href="{{ asset('vendor/fontawesome-free/css/all.min.css') }}" rel="stylesheet">
......@@ -32,17 +32,17 @@
<!-- Sidebar - Brand -->
<a class="sidebar-brand d-flex align-items-center justify-content-center" href="index.html">
<div class="sidebar-brand-icon rotate-n-15">
<i class="fas fa-laugh-wink"></i>
<i class="fas fa-door-open"></i>
</div>
<div class="sidebar-brand-text mx-3">SB Admin <sup>2</sup></div>
<div class="sidebar-brand-text mx-3">E-Lock</div>
</a>
<!-- Divider -->
<hr class="sidebar-divider my-0">
<!-- Nav Item - Dashboard -->
<li class="nav-item {{ Nav::isRoute('home') }}">
<a class="nav-link" href="{{ route('home') }}">
<li class="nav-item {{ Nav::isRoute('web.admin.home') }}">
<a class="nav-link" href="{{ route('web.admin.home') }}">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>{{ __('Dashboard') }}</span></a>
</li>
......@@ -56,16 +56,16 @@
</div>
<!-- Nav Item - Profile -->
<li class="nav-item {{ Nav::isRoute('profile') }}">
<a class="nav-link" href="{{ route('profile') }}">
<li class="nav-item {{ Nav::isRoute('web.admin.profile') }}">
<a class="nav-link" href="{{ route('web.admin.profile') }}">
<i class="fas fa-fw fa-user"></i>
<span>{{ __('Profile') }}</span>
</a>
</li>
<!-- Nav Item - About -->
<li class="nav-item {{ Nav::isRoute('about') }}">
<a class="nav-link" href="{{ route('about') }}">
<li class="nav-item {{ Nav::isRoute('web.admin.about') }}">
<a class="nav-link" href="{{ route('web.admin.about') }}">
<i class="fas fa-fw fa-hands-helping"></i>
<span>{{ __('About') }}</span>
</a>
......@@ -246,7 +246,7 @@
</a>
<!-- Dropdown - User Information -->
<div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
<a class="dropdown-item" href="{{ route('profile') }}">
<a class="dropdown-item" href="{{ route('web.admin.profile') }}">
<i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
{{ __('Profile') }}
</a>
......@@ -286,7 +286,7 @@
<footer class="sticky-footer bg-white">
<div class="container my-auto">
<div class="copyright text-center my-auto">
<span>Copyright &copy; Alejandro RH 2020</span>
<span>Copyright &copy; Jacob Priddy {{ \Carbon\Carbon::now()->year }}</span>
</div>
</div>
</footer>
......@@ -315,9 +315,10 @@
<div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
<div class="modal-footer">
<button class="btn btn-link" type="button" data-dismiss="modal">{{ __('Cancel') }}</button>
<a class="btn btn-danger" href="{{ route('logout') }}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">{{ __('Logout') }}</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
<a class="btn btn-danger" href="{{ route('web.logout') }}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">{{ __('Logout') }}</a>
<form id="logout-form" action="{{ route('web.logout') }}" method="POST" style="display: none;">
@csrf
<input type="hidden" name="intended" value="{{ route('web.admin.login_page') }}">
</form>
</div>
</div>
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{-- <link rel="icon" href="/docs/4.1/assets/img/favicons/favicon.ico">--}}
{{-- <link rel="icon" href="/docs/4.1/assets/img/favicons/favicon.ico">--}}
<title>E-Lock - @yield('title')</title>
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
......@@ -16,9 +16,9 @@
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
@can(\Source\Authorization\Permissions::ADMIN)
@can('view-admin-panel')
<li class="nav-item mr-2">
<a class="nav-link" href="#">Admin Panel</a>
<a class="nav-link" href="{{ route('web.admin.home') }}">Admin Panel</a>
</li>
@endauth
<li class="nav-item mr-2">
......
......@@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Web\MeController;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Web\Admin\HomeController;
use App\Http\Controllers\Web\Admin\LoginController;
/*
......@@ -23,7 +24,7 @@ Route::post('/admin/login', [LoginController::class, 'login'])->name('web.admin.
Route::name('web.')->middleware(['auth:api'])->group(static function () {
Route::view('/', 'home')->name('index');
Route::get('/logout', [AuthController::class, 'samlLogout'])->name('logout');
Route::post('/logout', [AuthController::class, 'samlLogout'])->name('logout');
Route::view('/door-code', 'doorcode')->name('doorcode');
Route::post('/door-code', [MeController::class, 'doorcodeUpdate'])->name('doorcode.change');
Route::view('/password', 'password')->name('password');
......@@ -34,11 +35,15 @@ Route::name('web.')->middleware(['auth:api'])->group(static function () {
Route::name('admin.')
->prefix('admin')
->middleware('can:view-admin-page')
->middleware('can:view-admin-panel')
->group(static function () {
Route::get('/', static function () {
return 'hi';
})->name('home');
});
Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/about', static function () {
return 'about';
})->name('about');
Route::get('/profile', static function () {
return 'profile';
})->name('profile');
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment