From d8a826588d012c106a70d5ea88bf9b6891bc1485 Mon Sep 17 00:00:00 2001 From: SLeighton Date: Wed, 23 Mar 2016 22:03:54 -0400 Subject: [PATCH 1/6] Added a login controller with the pre-given views --- controller/login.php | 47 ++++++++++++++++++++++++++++++++++++++ system/database.php | 2 +- views/assignment_form.html | 23 +++++++++++++++++++ views/class_form.html | 27 ++++++++++++++++++++++ views/content_form.html | 26 +++++++++++++++++++++ views/course_form.html | 27 ++++++++++++++++++++++ views/criteria_form.html | 26 +++++++++++++++++++++ views/evaluation_form.html | 23 +++++++++++++++++++ views/form.css | 16 +++++++++++++ views/login.html | 25 ++++++++++++++++++++ views/part_form.html | 26 +++++++++++++++++++++ views/project_form.html | 24 +++++++++++++++++++ views/user_form.html | 31 +++++++++++++++++++++++++ 13 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 controller/login.php create mode 100644 views/assignment_form.html create mode 100644 views/class_form.html create mode 100644 views/content_form.html create mode 100644 views/course_form.html create mode 100644 views/criteria_form.html create mode 100644 views/evaluation_form.html create mode 100644 views/form.css create mode 100644 views/login.html create mode 100644 views/part_form.html create mode 100644 views/project_form.html create mode 100644 views/user_form.html diff --git a/controller/login.php b/controller/login.php new file mode 100644 index 0000000..73183fc --- /dev/null +++ b/controller/login.php @@ -0,0 +1,47 @@ +query($query); + //if found, set SESSION variables and go to correct home page + if($result->num_rows != 0){ + $user = $result->fetch_array(MYSQLI_BOTH); + $_SESSION['user'] = new User($user['userID']); + $_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/system/database.php b/system/database.php index 7f91f2c..37bba61 100755 --- a/system/database.php +++ b/system/database.php @@ -1,7 +1,7 @@ connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); diff --git a/views/assignment_form.html b/views/assignment_form.html new file mode 100644 index 0000000..16cd4bd --- /dev/null +++ b/views/assignment_form.html @@ -0,0 +1,23 @@ + + + + + + New Assignment + + + + +

New Assignment

+
+ Title + + Description + + +
+ + + + + \ No newline at end of file diff --git a/views/class_form.html b/views/class_form.html new file mode 100644 index 0000000..4d74ebb --- /dev/null +++ b/views/class_form.html @@ -0,0 +1,27 @@ + + + + Class + + + +

Make a Class

+
+
+ Class Name

+ Course ID

+ Description

+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/views/content_form.html b/views/content_form.html new file mode 100644 index 0000000..83642cc --- /dev/null +++ b/views/content_form.html @@ -0,0 +1,26 @@ + + + + + + New Content + + + + +

New Content

+
+ Format + + Size + + Location + + + +
+ + + + + \ No newline at end of file diff --git a/views/course_form.html b/views/course_form.html new file mode 100644 index 0000000..d70c409 --- /dev/null +++ b/views/course_form.html @@ -0,0 +1,27 @@ + + + + Course + + + +

Course

+
+
+ Title

+ Coursecode

+ Description

+ + +

+
+ + + + + + + + + + \ No newline at end of file diff --git a/views/criteria_form.html b/views/criteria_form.html new file mode 100644 index 0000000..692effa --- /dev/null +++ b/views/criteria_form.html @@ -0,0 +1,26 @@ + + + + Criteria + + + +

Criteria

+
+
+ Title

+ Description

+ Rating

+ +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/views/evaluation_form.html b/views/evaluation_form.html new file mode 100644 index 0000000..01931f3 --- /dev/null +++ b/views/evaluation_form.html @@ -0,0 +1,23 @@ + + + + + + New Evaluation + + + + +

New Evaluation

+
+ Rating + + Description + + +
+ + + + + \ No newline at end of file diff --git a/views/form.css b/views/form.css new file mode 100644 index 0000000..89ba9f2 --- /dev/null +++ b/views/form.css @@ -0,0 +1,16 @@ + +form{ + + height: 1000px; + width: 100px; + +} + +input{ + + + float: left; + margin-bottom: 10px; + + +} \ No newline at end of file diff --git a/views/login.html b/views/login.html new file mode 100644 index 0000000..9c74d1d --- /dev/null +++ b/views/login.html @@ -0,0 +1,25 @@ + + + + Sign In + + + +

Login

+
+
+ Username

+ Password

+ +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/views/part_form.html b/views/part_form.html new file mode 100644 index 0000000..10ac5cf --- /dev/null +++ b/views/part_form.html @@ -0,0 +1,26 @@ + + + + Part Assignment + + + +

Part Assignment

+
+
+ Title

+ Description

+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/views/project_form.html b/views/project_form.html new file mode 100644 index 0000000..4ba9cf8 --- /dev/null +++ b/views/project_form.html @@ -0,0 +1,24 @@ + + + + + + New Project + + + + +

New Project

+
+ Title + + Description + + + +
+ + + + + \ No newline at end of file diff --git a/views/user_form.html b/views/user_form.html new file mode 100644 index 0000000..03150bc --- /dev/null +++ b/views/user_form.html @@ -0,0 +1,31 @@ + + + + + + New User + + + + +

New User

+
+ First Name + + Last Name + + Middle Initial + + Email + + Password + + + + +
+ + + + + \ No newline at end of file From e64799318fcdcf779e41b9dfc8c825c0c535cdea Mon Sep 17 00:00:00 2001 From: Dylan Landry Date: Thu, 24 Mar 2016 17:56:23 -0400 Subject: [PATCH 2/6] Removed unnecessary Views --- views/assignment_form.html | 23 ----------------------- views/class_form.html | 27 --------------------------- views/content_form.html | 26 -------------------------- views/course_form.html | 27 --------------------------- views/criteria_form.html | 26 -------------------------- views/evaluation_form.html | 23 ----------------------- views/form.css | 16 ---------------- views/login.html | 2 +- views/part_form.html | 26 -------------------------- views/project_form.html | 24 ------------------------ views/user_form.html | 31 ------------------------------- 11 files changed, 1 insertion(+), 250 deletions(-) delete mode 100644 views/assignment_form.html delete mode 100644 views/class_form.html delete mode 100644 views/content_form.html delete mode 100644 views/course_form.html delete mode 100644 views/criteria_form.html delete mode 100644 views/evaluation_form.html delete mode 100644 views/form.css delete mode 100644 views/part_form.html delete mode 100644 views/project_form.html delete mode 100644 views/user_form.html diff --git a/views/assignment_form.html b/views/assignment_form.html deleted file mode 100644 index 16cd4bd..0000000 --- a/views/assignment_form.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - New Assignment - - - - -

New Assignment

-
- Title - - Description - - -
- - - - - \ No newline at end of file diff --git a/views/class_form.html b/views/class_form.html deleted file mode 100644 index 4d74ebb..0000000 --- a/views/class_form.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - Class - - - -

Make a Class

-
-
- Class Name

- Course ID

- Description

- - -
-
- - - - - - - - - - \ No newline at end of file diff --git a/views/content_form.html b/views/content_form.html deleted file mode 100644 index 83642cc..0000000 --- a/views/content_form.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - New Content - - - - -

New Content

-
- Format - - Size - - Location - - - -
- - - - - \ No newline at end of file diff --git a/views/course_form.html b/views/course_form.html deleted file mode 100644 index d70c409..0000000 --- a/views/course_form.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - Course - - - -

Course

-
-
- Title

- Coursecode

- Description

- - -

-
- - - - - - - - - - \ No newline at end of file diff --git a/views/criteria_form.html b/views/criteria_form.html deleted file mode 100644 index 692effa..0000000 --- a/views/criteria_form.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - Criteria - - - -

Criteria

-
-
- Title

- Description

- Rating

- -
-
- - - - - - - - - - \ No newline at end of file diff --git a/views/evaluation_form.html b/views/evaluation_form.html deleted file mode 100644 index 01931f3..0000000 --- a/views/evaluation_form.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - New Evaluation - - - - -

New Evaluation

-
- Rating - - Description - - -
- - - - - \ No newline at end of file diff --git a/views/form.css b/views/form.css deleted file mode 100644 index 89ba9f2..0000000 --- a/views/form.css +++ /dev/null @@ -1,16 +0,0 @@ - -form{ - - height: 1000px; - width: 100px; - -} - -input{ - - - float: left; - margin-bottom: 10px; - - -} \ No newline at end of file diff --git a/views/login.html b/views/login.html index 9c74d1d..df282b4 100644 --- a/views/login.html +++ b/views/login.html @@ -2,7 +2,7 @@ Sign In - +

Login

diff --git a/views/part_form.html b/views/part_form.html deleted file mode 100644 index 10ac5cf..0000000 --- a/views/part_form.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - Part Assignment - - - -

Part Assignment

-
-
- Title

- Description

- - -
-
- - - - - - - - - - \ No newline at end of file diff --git a/views/project_form.html b/views/project_form.html deleted file mode 100644 index 4ba9cf8..0000000 --- a/views/project_form.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - New Project - - - - -

New Project

-
- Title - - Description - - - -
- - - - - \ No newline at end of file diff --git a/views/user_form.html b/views/user_form.html deleted file mode 100644 index 03150bc..0000000 --- a/views/user_form.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - New User - - - - -

New User

-
- First Name - - Last Name - - Middle Initial - - Email - - Password - - - - -
- - - - - \ No newline at end of file From ebdc6357e02a24d1a5cd1ae0c42c8dedf7a08697 Mon Sep 17 00:00:00 2001 From: matthew-loewen Date: Fri, 25 Mar 2016 14:38:06 -0400 Subject: [PATCH 3/6] added layout code works --- views/login.html | 32 ++++++++++++++++++++++---------- views/passwordreset.php | 3 +++ views/stylesheet.css | 10 ++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 views/passwordreset.php create mode 100644 views/stylesheet.css diff --git a/views/login.html b/views/login.html index df282b4..80cb5f1 100644 --- a/views/login.html +++ b/views/login.html @@ -1,18 +1,30 @@ - Sign In - + Haggis - Sign In + -

Login

-
-
- Username

- Password

- -
-
+
+
+ +
+ +
+

Login

+
+ +

+ +
+

forgot your password?

+
+ + +
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 From 4946401949c9f7c42677ccc01d83b3f9be94d421 Mon Sep 17 00:00:00 2001 From: SLeighton Date: Thu, 24 Mar 2016 20:44:25 -0400 Subject: [PATCH 4/6] Moved query used in controller to User model The process of checking a user for the right login credentials was added as a class function to the User class. Had to add a way to create an empty User, thus the initial check for UserID = -1 at the start of the User() function. --- controller/login.php | 46 +++++++++++++++----------------------------- models/user.php | 26 +++++++++++++++++++++++++ system/database.php | 2 +- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/controller/login.php b/controller/login.php index 73183fc..028627b 100644 --- a/controller/login.php +++ b/controller/login.php @@ -8,40 +8,24 @@ //get the html page ready to be displayed $page = file_get_contents(dirname(__FILE__) . '/../views/login.html'); echo $page; - //if the user is not already logged in - //display the login form - //if($_SESSION['sessionCheck'] != 'true'){ - // echo $page; - //} - //else if they are logged in, check user type and redirect to appropriate home page - //else{ - if(isset($_POST['submitLogin'])){ //change submitLogin to the equivalent login.html file + if(isset($_POST['submitLogin'])){ //change submitLogin to the equivalent login.html file - //get actual DB - require_once dirname(__FILE__) . "/../system/database.php"; - $db = GetDB(); + $user = new User(-1); //User with no user id to give + $user->User_Login($_POST['postName'], $_POST['postPassword']); //check for right credentials - //query for the user in the database - $query = "SELECT * FROM `user` WHERE `email` = '" . $_POST['postName'] . "' AND `password` = '" . $_POST['postPassword'] . "';"; - $result = $db->query($query); - //if found, set SESSION variables and go to correct home page - if($result->num_rows != 0){ - $user = $result->fetch_array(MYSQLI_BOTH); - $_SESSION['user'] = new User($user['userID']); - $_SESSION['sessionCheck'] = 'true'; - if ($_SESSION['user']->userType == 'Student'){ - header("location:student_home.php"); - } - else{ - header("location:instructor_home.php"); - } + //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 { - echo "Wrong Username/Password
Please try again.
"; + 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/system/database.php b/system/database.php index 37bba61..7f91f2c 100755 --- a/system/database.php +++ b/system/database.php @@ -1,7 +1,7 @@ connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); From 19fc276124b1cbd8fd70195fc814e86dda937a1d Mon Sep 17 00:00:00 2001 From: SLeighton Date: Thu, 24 Mar 2016 21:33:43 -0400 Subject: [PATCH 5/6] User Model Commit Not sure if this was updated in the previous commit --- models/user.php | 1 + 1 file changed, 1 insertion(+) diff --git a/models/user.php b/models/user.php index f47d989..cfad3d4 100755 --- a/models/user.php +++ b/models/user.php @@ -56,6 +56,7 @@ 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 . "';"; From c29a873aa489235114c763d99f1715ddfdba9d51 Mon Sep 17 00:00:00 2001 From: SLeighton Date: Thu, 24 Mar 2016 21:35:54 -0400 Subject: [PATCH 6/6] Revert "User Model Commit" This reverts commit a6d963adefa63512c88d654ef5e5d6dc86118dfc. --- models/user.php | 1 - 1 file changed, 1 deletion(-) diff --git a/models/user.php b/models/user.php index cfad3d4..f47d989 100755 --- a/models/user.php +++ b/models/user.php @@ -56,7 +56,6 @@ 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 . "';";