mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 05:25:42 +07:00
Initial Release v1.0.0: Full feature set with Docker automation, Nginx/Alpine stack
This commit is contained in:
43
app/Controllers/AuthController.php
Normal file
43
app/Controllers/AuthController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use App\Models\User;
|
||||
|
||||
class AuthController extends Controller {
|
||||
|
||||
public function showLogin() {
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
return $this->view('login');
|
||||
}
|
||||
|
||||
public function login() {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
$userModel = new User();
|
||||
$user = $userModel->attempt($username, $password);
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
\App\Helpers\FlashHelper::set('success', 'Welcome Back', 'Login successful.');
|
||||
header('Location: /');
|
||||
exit;
|
||||
} else {
|
||||
\App\Helpers\FlashHelper::set('error', 'Login Failed', 'Invalid credentials');
|
||||
header('Location: /login');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
session_destroy();
|
||||
header('Location: /login');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user