Merge branch 'master' into lars

This commit is contained in:
Lars van Hijfte
2017-01-25 16:19:07 +01:00
7 changed files with 28 additions and 23 deletions

View File

@@ -8,4 +8,8 @@ function checkLoggedIn() {
function bannedAlert(){ function bannedAlert(){
alert("Your account is banned"); alert("Your account is banned");
}
function emailNotConfirmed(){
alert("Your account has not been verified yet!\nAnother email has been sent to you")
} }

View File

@@ -5,6 +5,7 @@
require_once("../queries/connect.php"); require_once("../queries/connect.php");
include_once("../queries/login.php"); include_once("../queries/login.php");
include_once("../queries/checkInput.php"); include_once("../queries/checkInput.php");
include_once("../queries/emailconfirm.php");
?> ?>
<body> <body>
<?php <?php
@@ -23,7 +24,7 @@
// Trying to login // Trying to login
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
try{ try{
$uname = strtolower(test_input($_POST["uname"])); $uname = ($_POST["uname"]);
validateLogin($_POST["uname"], $_POST["psw"]); validateLogin($_POST["uname"], $_POST["psw"]);
} catch(loginException $e) { } catch(loginException $e) {
$loginErr = $e->getMessage(); $loginErr = $e->getMessage();

View File

@@ -1,15 +1,4 @@
<!DOCTYPE html>
<html>
<?php <?php
include("../views/login_head.php"); session_start();
require_once("../queries/connect.php"); session_destroy();
include_once("../queries/login.php"); header("Location: login.php");
?>
<body>
<?php
session_start();
unset($_SESSION["userID"]);
header("Location: login.php");
?>
</body>
</html>

View File

@@ -5,6 +5,7 @@
require_once("../queries/connect.php"); require_once("../queries/connect.php");
include_once("../queries/register.php"); include_once("../queries/register.php");
include_once("../queries/checkInput.php"); include_once("../queries/checkInput.php");
include_once("../queries/emailconfirm.php");
?> ?>
<body> <body>
<?php <?php
@@ -91,6 +92,7 @@
try { try {
getIp(); getIp();
registerCheck($correct); registerCheck($correct);
sendConfirmEmailUsername($username);
} catch(registerException $e){ } catch(registerException $e){
$genericErr = $e->getMessage(); $genericErr = $e->getMessage();
} }

View File

@@ -25,7 +25,9 @@ function sendConfirmEmail(int $userID) {
WHERE WHERE
`userID` = :userID `userID` = :userID
"); ");
$stmt->bindParam(":userID", $userID); $stmt->bindParam(":userID", $userID);
$stmt->execute();
$user = $stmt->fetch(); $user = $stmt->fetch();
$email = $user["email"]; $email = $user["email"];
@@ -34,10 +36,7 @@ function sendConfirmEmail(int $userID) {
$confirmLink = "https://myhyvesbookplus.nl/emailconfirm.php?u=$userID&h=$hash"; $confirmLink = "https://myhyvesbookplus.nl/emailconfirm.php?u=$userID&h=$hash";
$subject = "Bevestig uw emailadres"; $subject = "Bevestig uw emailadres";
$body = "Hallo $fname,\r\n\r\n $body = "Hallo $fname,\r\n\r\nKlik op de onderstaande link om uw emailadres te bevestigen.\r\n\r\n$confirmLink\r\n\r\nGroeten MyHyvesbook+";
Klik op de onderstaande link om uw emailadres te bevestigen.\r\n\r\n
$confirmLink\r\n\r\n
Groeten MyHyvesbook+";
$header = "From: MyHyvesbook+ <noreply@myhyvesbookplus.nl>"; $header = "From: MyHyvesbook+ <noreply@myhyvesbookplus.nl>";
mail($email, $subject, $body, $header); mail($email, $subject, $body, $header);
} }

View File

@@ -34,6 +34,11 @@ function validateLogin($username, $password){
echo "<script> echo "<script>
window.onload=bannedAlert(); window.onload=bannedAlert();
</script>"; </script>";
} else if ($role == "unconfirmed"){
sendConfirmEmail(getUser()["userID"]);
echo "<script>
window.onload=emailNotConfirmed();
</script>";
} else { } else {
$_SESSION["userID"] = $userID; $_SESSION["userID"] = $userID;
header("location: profile.php"); header("location: profile.php");
@@ -52,4 +57,5 @@ class loginException extends Exception
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
} }
?> ?>

View File

@@ -1,4 +1,6 @@
<?php <?php
include_once "../queries/emailconfirm.php";
abstract class AlertMessage extends Exception { abstract class AlertMessage extends Exception {
public function __construct($message = "", $code = 0, Exception $previous = null) public function __construct($message = "", $code = 0, Exception $previous = null)
{ {
@@ -152,7 +154,7 @@ function emailIsAvailableInDatabase($email) {
`email` `email`
FROM FROM
`user` `user`
WHERE WHERE
`email` = :email `email` = :email
"); ");
@@ -168,16 +170,18 @@ function doChangeEmail($email) {
UPDATE UPDATE
`user` `user`
SET SET
`email` = :email `email` = :email,
`role` = 'unconfirmed'
WHERE WHERE
`userID` = :userID `userID` = :userID
"); ");
$stmt->bindParam(":email", $email); $stmt->bindParam(":email", $email);
$stmt->bindParam(":userID", $_SESSION["userID"]); $stmt->bindParam(":userID", $_SESSION["userID"]);
$stmt->execute(); $stmt->execute();
// return $stmt->rowCount();
if ($stmt->rowCount()) { if ($stmt->rowCount()) {
sendConfirmEmail($_SESSION["userID"]);
session_destroy();
throw new HappyAlert("Emailadres is veranderd."); throw new HappyAlert("Emailadres is veranderd.");
} else { } else {
throw new AngryAlert(); throw new AngryAlert();