diff --git a/controller/login.php b/controller/login.php new file mode 100644 index 0000000..028627b --- /dev/null +++ b/controller/login.php @@ -0,0 +1,31 @@ +User_Login($_POST['postName'], $_POST['postPassword']); //check for right credentials + + //if correct credentials, set SESSION variables and go to correct home page + if($user->userID != -1){ + $_SESSION['user'] = $user; + $_SESSION['sessionCheck'] = 'true'; + if ($_SESSION['user']->userType == 'Student'){ + header("location:student_home.php"); + } + else{ + header("location:instructor_home.php"); + } + } + else { + echo "Wrong Username/Password
Please try again.
"; + } + } +?> \ No newline at end of file diff --git a/models/user.php b/models/user.php index 7545ab8..f47d989 100755 --- a/models/user.php +++ b/models/user.php @@ -13,6 +13,11 @@ class User { public $password; public function User($user_id){ + //check to see if valid user_id + if($user_id <= -1){ + return; + } + $this->userID = $user_id; $db = GetDB(); @@ -49,6 +54,27 @@ public function User($user_id){ } } + public function User_Login($email, $password){ + $db = GetDB(); + + //query for the user in the database using credentials + $query = "SELECT * FROM `user` WHERE `email` = '" . $email . "' AND `password` = '" . $password . "';"; + $result = $db->query($query); + + //if the result isn't empty + if($result->num_rows != 0){ + $user = $result->fetch_array(MYSQLI_BOTH); + + $this->userID = $user['userID']; + $this->firstName = $user['firstName']; + $this->lastName = $user['lastName']; + $this->middleInitial = $user['middleInitial']; + $this->userType = $user['userType']; + $this->email = $user['email']; + $this->password = $user['password']; + } + } + public function Save(){ if($this->userID != -1){ $query = "UPDATE `user` SET "; diff --git a/views/login.html b/views/login.html new file mode 100644 index 0000000..80cb5f1 --- /dev/null +++ b/views/login.html @@ -0,0 +1,37 @@ + + + + Haggis - Sign In + + + +
+
+ +
+ +
+

Login

+
+ +

+ +
+

forgot your password?

+
+ + +
+ + + + + + + + + + \ No newline at end of file diff --git a/views/passwordreset.php b/views/passwordreset.php new file mode 100644 index 0000000..b6fa64c --- /dev/null +++ b/views/passwordreset.php @@ -0,0 +1,3 @@ +#login{ + background:red; +} \ No newline at end of file diff --git a/views/stylesheet.css b/views/stylesheet.css new file mode 100644 index 0000000..5892800 --- /dev/null +++ b/views/stylesheet.css @@ -0,0 +1,10 @@ +/*haggis stylesheet*/ +body{ + border-style:solid; + border-width:1px; + border-color:black; +} + +#login{ + align:center; +} \ No newline at end of file