This commit is contained in:
pbao9
2025-10-09 10:37:30 +07:00
parent 1384a2ec1c
commit 7916a00dc3
156 changed files with 95 additions and 29 deletions
+31 -22
View File
@@ -7,7 +7,7 @@ use App\Models\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class LoginController extends Controller
{
//
@@ -17,32 +17,41 @@ class LoginController extends Controller
}
public function store(Request $request)
{
$request->validate([
'username' => 'required|min:3',
'password' => 'required|min:3'
]);
try {
$request->validate([
'username' => 'required|min:3',
'password' => 'required|min:3'
]);
$user = User::where('username',$request->username)->first();
if (! $user) return back()->withErrors('Không tìm thấy thông tin người dùng');
$user = User::where('username', $request->username)->first();
if (!$user)
return back()->withErrors('Không tìm thấy thông tin người dùng');
if (Auth::guard('admins')->attempt(['username' => $request->username,'password' => $request->password],$request->remember))
{
if (\auth()->user()->status)
{
$token = \auth()->user()->createToken('access_token',['*'],Carbon::now()->addDay())->plainTextToken;
Cookie::queue('accessToken',$token,24*60);
if (Auth::guard('admins')->attempt(['username' => $request->username, 'password' => $request->password], $request->remember)) {
if (\auth()->user()->status) {
$token = \auth()->user()->createToken('access_token', ['*'], Carbon::now()->addDay())->plainTextToken;
Cookie::queue('accessToken', $token, 24 * 60);
if (Cookie::has('admin_prev_url'))
{
Cookie::queue(Cookie::forget('admin_prev_url'));
return redirect(Cookie::get('admin_prev_url'));
if (Cookie::has('admin_prev_url')) {
Cookie::queue(Cookie::forget('admin_prev_url'));
return redirect(Cookie::get('admin_prev_url'));
}
return redirect()->route('dashboard')->with('success', 'Đã đăng nhập thành công!');
}
return redirect()->route('dashboard')->with('success', 'Đã đăng nhập thành công!');
auth('admins')->logout();
return back()->withErrors('Tài khoản bị khoá, vui lòng liên hệ quản trị viên');
}
auth('admins')::logout();
return back()->withErrors('Tài khoản bị khoá, vui lòng liên hệ quản trị viên');
}
return back()->withErrors('Thông tin đăng nhập không hợp lệ');
return back()->withErrors('Thông tin đăng nhập không hợp lệ');
} catch (\Exception $e) {
// Log the error for debugging
Log::error('Login error: ' . $e->getMessage(), [
'username' => $request->username,
'ip' => $request->ip(),
'user_agent' => $request->userAgent()
]);
return back()->withErrors('Có lỗi xảy ra trong quá trình đăng nhập. Vui lòng thử lại sau.');
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Vm;
namespace App\Http\Requests\VM;
use Illuminate\Foundation\Http\FormRequest;
+2 -2
View File
@@ -1,6 +1,6 @@
<?php
<?php
namespace App\Services\Caches;
namespace App\Services\Cache;
interface CacheServiceInterface
{
Regular → Executable
View File
+2 -2
View File
@@ -18,9 +18,9 @@ class AdminSeeder extends Seeder
'firstname' => 'Admin',
'lastname' => 'System',
'username' => 'admin',
'email' => 'admin@example.com',
'email' => 'admin@tgs.com.vn',
'email_verified_at' => now(),
'password' => Hash::make('123456789'),
'password' => Hash::make('!admin@123!@#'),
'status' => 1,
'created_at' => now(),
'updated_at' => now(),
+59 -2
View File
@@ -17,6 +17,9 @@
<link rel="stylesheet" type="text/css" href="{{ asset('lib/fui-toast/fuiToast.min.css') }}">
</head>
<body class="hold-transition login-page">
<!-- FUI Toast Container - Required for FuiToast to work -->
<div id="fui-toast"></div>
<div class="login-box">
<!-- login-logo -->
<div class="card card-outline card-primary">
@@ -44,7 +47,6 @@
</div>
</div>
</div>
@include("alerts")
<div class="row">
<div class="col-8">
<div class="icheck-primary">
@@ -76,6 +78,61 @@
<script src="{{ asset('lib/adminlte/adminlte.min.js') }}"></script>
<!-- Toast js -->
<script type="text/javascript" src="{{ asset('lib/fui-toast/fuiToast.min.js') }}"></script>
@include("alerts")
<script type="text/javascript">
// Function to safely show toast notifications
function showToast(message, type = 'error', title = '') {
// Check if FuiToast is available and container exists
if (typeof FuiToast !== 'undefined' && document.getElementById('fui-toast')) {
try {
if (type === 'success') {
FuiToast.success(message, title || 'Success!');
} else {
FuiToast.error(message, title || 'Error!');
}
return true;
} catch (e) {
console.error('FuiToast failed:', e);
return false;
}
}
return false;
}
// Function to show alerts with fallback
function showAlerts() {
@if ($errors->any() || session()->has('success'))
@foreach ($errors->all() as $item)
if (!showToast('{{ addslashes($item) }}', 'error', 'Opp!')) {
alert('{{ addslashes($item) }}');
}
@endforeach
@if (session()->has('success'))
if (!showToast('{{ addslashes(session()->get('success')) }}', 'success', 'Success!')) {
alert('{{ addslashes(session()->get('success')) }}');
}
@endif
@endif
}
// Wait for all scripts to load and DOM to be ready
document.addEventListener('DOMContentLoaded', function() {
// Initialize FuiToast configuration
if (typeof FuiToast !== 'undefined' && FuiToast.config) {
try {
FuiToast.config({
position: "top-center",
});
} catch (e) {
console.warn('FuiToast config failed:', e);
}
}
// Add a small delay to ensure everything is fully initialized
setTimeout(function() {
showAlerts();
}, 100);
});
</script>
</body>
</html>

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 297 KiB

Before

Width:  |  Height:  |  Size: 391 KiB

After

Width:  |  Height:  |  Size: 391 KiB

Before

Width:  |  Height:  |  Size: 297 KiB

After

Width:  |  Height:  |  Size: 297 KiB

Before

Width:  |  Height:  |  Size: 391 KiB

After

Width:  |  Height:  |  Size: 391 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 606 B

After

Width:  |  Height:  |  Size: 606 B

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 381 B

After

Width:  |  Height:  |  Size: 381 B

View File

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

View File

Before

Width:  |  Height:  |  Size: 322 KiB

After

Width:  |  Height:  |  Size: 322 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 169 KiB

After

Width:  |  Height:  |  Size: 169 KiB

View File

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

View File

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

View File

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

View File

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

View File

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

Before

Width:  |  Height:  |  Size: 517 KiB

After

Width:  |  Height:  |  Size: 517 KiB

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

View File

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

View File

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

View File

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

Before

Width:  |  Height:  |  Size: 517 KiB

After

Width:  |  Height:  |  Size: 517 KiB

View File
View File
View File

Before

Width:  |  Height:  |  Size: 653 B

After

Width:  |  Height:  |  Size: 653 B

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 773 B

After

Width:  |  Height:  |  Size: 773 B

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File
View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Before

Width:  |  Height:  |  Size: 233 KiB

After

Width:  |  Height:  |  Size: 233 KiB

View File
View File

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

View File
View File
View File
View File
View File

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View File
View File
View File

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

View File
View File
View File
View File
View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File
View File
View File

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

View File
View File
View File
View File
View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File
View File
View File
View File
View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File
View File
View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File
View File
View File
View File
View File

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File
View File
View File

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

View File
View File

Some files were not shown because too many files have changed in this diff Show More