mirror of
https://github.com/michaelstaake/mainty.git
synced 2026-04-16 19:40:13 +00:00
Initial version upload
This commit is contained in:
41
controllers/AuthController.php
Normal file
41
controllers/AuthController.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
class AuthController extends Controller {
|
||||
public function login(): void {
|
||||
$this->requireSetup();
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
$this->redirect('/home');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->view('login');
|
||||
}
|
||||
|
||||
public function authenticate(): void {
|
||||
$this->requireSetup();
|
||||
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($password)) {
|
||||
$_SESSION['error'] = 'Password is required';
|
||||
$this->redirect('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
|
||||
if ($user->verifyPassword($password)) {
|
||||
$_SESSION['user_id'] = $user->getId();
|
||||
$this->redirect('/home');
|
||||
} else {
|
||||
$_SESSION['error'] = 'Invalid password';
|
||||
$this->redirect('/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function logout(): void {
|
||||
session_destroy();
|
||||
$this->redirect('/login');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user