Compare commits
No commits in common. "f27d92c5447e2882f3b7582905a50e0a6f85554f" and "2d133598e8892deb81bfc8e25abeaf935e80a1d3" have entirely different histories.
f27d92c544
...
2d133598e8
@ -2,31 +2,28 @@
|
|||||||
|
|
||||||
namespace ppa\Controller;
|
namespace ppa\Controller;
|
||||||
|
|
||||||
use ppa\Model\UserModel;
|
use ppa\Model\NotesModel;
|
||||||
use ppa\Library\View;
|
use ppa\Library\View;
|
||||||
|
|
||||||
class UserController
|
class NotesController
|
||||||
{
|
{
|
||||||
private $userModel;
|
private $notesModel;
|
||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
public function __construct($view)
|
public function __construct($view)
|
||||||
{
|
{
|
||||||
$this->userModel = new UserModel();
|
$this->notesModel = new NotesModel();
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function showNotes()
|
||||||
public function loginUser()
|
|
||||||
{
|
{
|
||||||
echo "test";
|
$sortBy = $_GET['sort_by'] ?? 'updated_at';
|
||||||
//verifyLogin($_POST['username'] ?? '', $_POST['password'] ?? '')
|
$sortOrder = strtoupper($_GET['sort_order'] ?? 'DESC');
|
||||||
}
|
|
||||||
|
|
||||||
|
$this->view->setVars([
|
||||||
|
"notes" => $this->notesModel->selectNotesForUser(2, $sortBy, $sortOrder) //$_SESSION['user_id']
|
||||||
public function showUserLoginForm()
|
]);
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,31 +0,0 @@
|
|||||||
<?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' => 'index.php?page=dashboard'];
|
|
||||||
}
|
|
||||||
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.'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
<?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