x
This commit is contained in:
parent
97137da6b9
commit
9a4626e854
@ -19,19 +19,27 @@ class UserController
|
|||||||
|
|
||||||
public function loginUser()
|
public function loginUser()
|
||||||
{
|
{
|
||||||
var_dump($_POST);
|
$erg = array();
|
||||||
echo $_POST["username"];
|
$erg = $this->userModel->verifyLogin($_POST["username"], $_POST["password"]);
|
||||||
|
if ($erg["success"] == true) {
|
||||||
|
echo "success";
|
||||||
// on fail
|
}
|
||||||
|
else {
|
||||||
$this->view->setDoMethodName("showUserLoginForm");
|
$this->view->setDoMethodName("showUserLoginForm");
|
||||||
|
$this->view->setVars([
|
||||||
|
"errmsg" => $erg["message"]
|
||||||
|
]);
|
||||||
$this->showUserLoginForm();
|
$this->showUserLoginForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function showUserLoginForm()
|
public function showUserLoginForm()
|
||||||
{
|
{
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace ppa\Model;
|
namespace ppa\Model;
|
||||||
use ppa\Model\ParticipantModel;
|
use ppa\Model\ParticipantModel;
|
||||||
use ppb\Library\Msg;
|
//use ppb\Library\Msg;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
|
||||||
class UserModel extends Database
|
class UserModel extends Database
|
||||||
{
|
{
|
||||||
function verifyLogin($pdo, $username, $password)
|
public function verifyLogin($username, $password)
|
||||||
{
|
{
|
||||||
$pdo = $this->linkDB();
|
$pdo = $this->linkDB();
|
||||||
if (!$pdo) return ['success' => false, 'message' => 'Database connection error.'];
|
if (!$pdo) return ['success' => false, 'message' => 'Database connection error.'];
|
||||||
@ -20,7 +20,7 @@ class UserModel extends Database
|
|||||||
$_SESSION['user_id'] = $user['id'];
|
$_SESSION['user_id'] = $user['id'];
|
||||||
$_SESSION['username'] = $user['username'];
|
$_SESSION['username'] = $user['username'];
|
||||||
$_SESSION['role'] = $user['role']; // Store role
|
$_SESSION['role'] = $user['role']; // Store role
|
||||||
return ['success' => true, 'message' => 'Login successful!', 'redirect' => showNotes()];
|
return ['success' => true, 'message' => 'Login successful!', 'redirect' => "xx"];
|
||||||
}
|
}
|
||||||
return ['success' => false, 'message' => 'Invalid username or password.'];
|
return ['success' => false, 'message' => 'Invalid username or password.'];
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
|
@ -13,10 +13,15 @@
|
|||||||
<input type="password" id="password" name="password" required>
|
<input type="password" id="password" name="password" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
<button type="submit">Login</button>
|
||||||
<button type="submit" href="?controller=User&do=loginUser">Login</button>
|
<label><?php if (isset($errmsg)):?>
|
||||||
|
<?php echo $errmsg;?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</label>
|
||||||
<p style="margin-top:15px; text-align:center;">Don't have an account? <a href="index.php?page=register">Register here</a></p>
|
<p style="margin-top:15px; text-align:center;">Don't have an account? <a href="index.php?page=register">Register here</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" name="controller" value="User">
|
||||||
|
<input type="hidden" name="do" value="loginUser">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
Loading…
x
Reference in New Issue
Block a user