- Added main application entry point (app.jsx) and bootstrap file for React setup. - Created Wiki index page (Index.jsx) for documentation and file management. - Implemented utility functions for formatting and status handling in utils.js. - Set up Blade template (app.blade.php) for Inertia.js integration. - Defined API routes for metrics and terminal access in api.php. - Established console commands for scheduled tasks in console.php. - Created web routes for various application features including authentication, hypervisors, containers, cloud accounts, security, backups, and wiki management in web.php. - Developed setup scripts for Windows (setup.ps1) and Linux (setup.sh) environments. - Configured Tailwind CSS for styling with custom themes and animations in tailwind.config.js. - Set up Vite for asset bundling and development server in vite.config.js.
84 lines
2.2 KiB
PHP
84 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\Str;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class AuthController extends Controller
|
|
{
|
|
public function showLogin(): Response
|
|
{
|
|
return Inertia::render('Auth/Login', [
|
|
'ldapEnabled' => config('ldap.auth.enabled', false),
|
|
]);
|
|
}
|
|
|
|
public function login(Request $request)
|
|
{
|
|
$request->validate([
|
|
'email' => 'required|string',
|
|
'password' => 'required|string',
|
|
]);
|
|
|
|
// Rate limiting
|
|
$key = 'login:' . $request->ip();
|
|
if (RateLimiter::tooManyAttempts($key, 5)) {
|
|
$seconds = RateLimiter::availableIn($key);
|
|
return back()->withErrors([
|
|
'email' => "Too many login attempts. Please try again in {$seconds} seconds.",
|
|
]);
|
|
}
|
|
|
|
$credentials = [
|
|
'email' => $request->email,
|
|
'password' => $request->password,
|
|
];
|
|
|
|
if (!Auth::attempt($credentials, $request->boolean('remember'))) {
|
|
RateLimiter::hit($key, 300);
|
|
return back()->withErrors(['email' => 'Invalid credentials.']);
|
|
}
|
|
|
|
RateLimiter::clear($key);
|
|
|
|
$user = Auth::user();
|
|
if (!$user->is_active) {
|
|
Auth::logout();
|
|
return back()->withErrors(['email' => 'Your account has been disabled.']);
|
|
}
|
|
|
|
$user->update([
|
|
'last_login_at' => now(),
|
|
'last_login_ip' => $request->ip(),
|
|
]);
|
|
|
|
activity()
|
|
->causedBy($user)
|
|
->log('User logged in from ' . $request->ip());
|
|
|
|
$request->session()->regenerate();
|
|
|
|
return redirect()->intended('/');
|
|
}
|
|
|
|
public function logout(Request $request)
|
|
{
|
|
activity()
|
|
->causedBy(Auth::user())
|
|
->log('User logged out');
|
|
|
|
Auth::logout();
|
|
$request->session()->invalidate();
|
|
$request->session()->regenerateToken();
|
|
|
|
return redirect()->route('login');
|
|
}
|
|
}
|