Merge branch 'main' of http://git.pb.bib.de/PBBFA23CIV/EIANotesApp
This commit is contained in:
commit
c0bd9b7e8a
@ -2,28 +2,31 @@
|
|||||||
|
|
||||||
namespace ppa\Controller;
|
namespace ppa\Controller;
|
||||||
|
|
||||||
use ppa\Model\NotesModel;
|
use ppa\Model\UserModel;
|
||||||
use ppa\Library\View;
|
use ppa\Library\View;
|
||||||
|
|
||||||
class NotesController
|
class UserController
|
||||||
{
|
{
|
||||||
private $notesModel;
|
private $userModel;
|
||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
public function __construct($view)
|
public function __construct($view)
|
||||||
{
|
{
|
||||||
$this->notesModel = new NotesModel();
|
$this->userModel = new UserModel();
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showNotes()
|
|
||||||
|
public function loginUser()
|
||||||
|
{
|
||||||
|
echo "test";
|
||||||
|
//verifyLogin($_POST['username'] ?? '', $_POST['password'] ?? '')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function showUserLoginForm()
|
||||||
{
|
{
|
||||||
$sortBy = $_GET['sort_by'] ?? 'updated_at';
|
|
||||||
$sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC');
|
|
||||||
|
|
||||||
$this->view->setVars([
|
|
||||||
"notes" => $this->notesModel->selectNotesForUser(2, $sortBy, $sortOrder) //$_SESSION['user_id']
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
31
Model/UserModel.php
Normal file
31
Model/UserModel.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ppa\Model;
|
||||||
|
use ppa\Model\ParticipantModel;
|
||||||
|
use ppb\Library\Msg;
|
||||||
|
use PDOException;
|
||||||
|
|
||||||
|
class UserModel extends Database
|
||||||
|
{
|
||||||
|
function verifyLogin($pdo, $username, $password)
|
||||||
|
{
|
||||||
|
$pdo = $this->linkDB();
|
||||||
|
if (!$pdo) return ['success' => false, 'message' => 'Database connection error.'];
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->prepare("SELECT id, username, password, role FROM users WHERE username = ?");
|
||||||
|
$stmt->execute([$username]);
|
||||||
|
$user = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($user && password_verify($password, $user['password'])) {
|
||||||
|
$_SESSION['user_id'] = $user['id'];
|
||||||
|
$_SESSION['username'] = $user['username'];
|
||||||
|
$_SESSION['role'] = $user['role']; // Store role
|
||||||
|
return ['success' => true, 'message' => 'Login successful!', 'redirect' => showNotes()];
|
||||||
|
}
|
||||||
|
return ['success' => false, 'message' => 'Invalid username or password.'];
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
error_log("Login Error: " . $e->getMessage());
|
||||||
|
return ['success' => false, 'message' => 'An error occurred during login.'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
Views/User/showUserLoginForm.phtml
Normal file
22
Views/User/showUserLoginForm.phtml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php include dirname(__DIR__).'/header.phtml'; ?>
|
||||||
|
<script src="JavaScript/script.js"></script>
|
||||||
|
<div class="form-container">
|
||||||
|
<h2>Login</h2>
|
||||||
|
<form id="login-form" method="POST">
|
||||||
|
<input type="hidden" name="action" value="login">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username">Username:</label>
|
||||||
|
<input type="text" id="username" name="username" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password:</label>
|
||||||
|
<input type="password" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
|
||||||
|
<button type="submit" href="?controller=User&do=loginUser">Login</button>
|
||||||
|
<p style="margin-top:15px; text-align:center;">Don't have an account? <a href="index.php?page=register">Register here</a></p>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
Loading…
x
Reference in New Issue
Block a user