From b796f6bf471531952ee59017b2197c4e59169334 Mon Sep 17 00:00:00 2001 From: coolneng Date: Thu, 18 Jun 2020 14:48:12 +0200 Subject: [PATCH] Add log in functionality --- database/db.sql | 2 +- src/appointment.php | 14 ++++++--- src/calendar.js | 18 +++++++++++ src/database.php | 8 +++++ src/forms/appointment_create_form.php | 7 ++++- src/forms/holiday_create_form.php | 5 +++ src/forms/holiday_edit_form.php | 5 +++ src/forms/patient_create_form.php | 5 +++ src/forms/patient_edit_form.php | 6 ++++ src/forms/report_create_form.php | 5 +++ src/forms/report_edit_form.php | 5 +++ src/forms/user_create_form.html | 5 +++ src/forms/user_edit_form.php | 5 +++ src/holiday.php | 6 +++- src/index.php | 5 +++ src/login.php | 44 +++++++++++++++++++++++++++ src/patient.php | 6 +++- src/report.php | 30 ++++++++++-------- src/user.php | 32 ++++++++++--------- src/user_management.php | 19 ++++++++++++ src/validate_user.js | 16 ++++++++++ static/style.css | 11 ++++--- 22 files changed, 219 insertions(+), 40 deletions(-) create mode 100644 src/login.php diff --git a/database/db.sql b/database/db.sql index cd51555..4be9b36 100644 --- a/database/db.sql +++ b/database/db.sql @@ -107,5 +107,5 @@ CREATE TABLE IF NOT EXISTS informe( INSERT INTO rol (codigo, nombre) VALUES (1, "administrativo"); INSERT INTO rol (codigo, nombre) VALUES (2, "medico"); -INSERT INTO usuario (nombre, usuario, contraseña, correo, rol) VALUES ("Sysadmin", "Admin", "chimba", "admin@example.com", 1); +INSERT INTO usuario (nombre, usuario, contraseña, correo, rol) VALUES ("Sysadmin", "admin", "chimba", "admin@example.com", 1); INSERT INTO usuario (nombre, usuario, contraseña, correo, rol) VALUES ("Nabil", "nabil", "menisco","doctor@example.com", 2); diff --git a/src/appointment.php b/src/appointment.php index fe28847..d005434 100644 --- a/src/appointment.php +++ b/src/appointment.php @@ -1,4 +1,4 @@ - + @@ -14,19 +14,23 @@ -
- +
diff --git a/src/calendar.js b/src/calendar.js index 489b4ac..00d9445 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -7,3 +7,21 @@ document.addEventListener('DOMContentLoaded', function() { calendar.render(); }); + + $(document).ready(function() { + $('#calendar').fullCalendar({ + header: { + left: 'prev,next today', + center: 'title', + right: 'month,basicWeek,basicDay' + }, + defaultDate: new Date(), + navLinks: true, // can click day/week names to navigate views + editable: true, + eventLimit: true, // allow "more" link when too many events + dayClick: function(date, jsEvent, view) { + $("#successModal").modal("show"); + $("#eventDate").val(date.format()); + }, + events: + }); diff --git a/src/database.php b/src/database.php index 96444c6..92c106b 100644 --- a/src/database.php +++ b/src/database.php @@ -243,4 +243,12 @@ function fetchReportData($pdo, string $id) { return $data; } +function fetchLoginData($pdo, $data){ + $query = "SELECT usuario, contraseña, rol FROM usuario WHERE usuario=? AND fecha_baja IS NULL"; + $result = $pdo->prepare($query); + $result->execute([$data["usuario"]]); + $data = $result->fetch(); + return $data; +} + ?> diff --git a/src/forms/appointment_create_form.php b/src/forms/appointment_create_form.php index ab7ff3a..d296fa6 100644 --- a/src/forms/appointment_create_form.php +++ b/src/forms/appointment_create_form.php @@ -1,4 +1,4 @@ - + @@ -18,10 +18,15 @@ diff --git a/src/forms/holiday_create_form.php b/src/forms/holiday_create_form.php index 488a5b7..58a3b18 100644 --- a/src/forms/holiday_create_form.php +++ b/src/forms/holiday_create_form.php @@ -1,3 +1,4 @@ + @@ -12,11 +13,15 @@ diff --git a/src/forms/holiday_edit_form.php b/src/forms/holiday_edit_form.php index 06843ce..488f0cf 100644 --- a/src/forms/holiday_edit_form.php +++ b/src/forms/holiday_edit_form.php @@ -1,3 +1,4 @@ + @@ -11,11 +12,15 @@ diff --git a/src/forms/patient_create_form.php b/src/forms/patient_create_form.php index 6c50467..ff38589 100644 --- a/src/forms/patient_create_form.php +++ b/src/forms/patient_create_form.php @@ -1,3 +1,4 @@ + @@ -14,11 +15,15 @@ diff --git a/src/forms/patient_edit_form.php b/src/forms/patient_edit_form.php index 85b6431..a7fb324 100644 --- a/src/forms/patient_edit_form.php +++ b/src/forms/patient_edit_form.php @@ -1,3 +1,4 @@ + @@ -11,10 +12,15 @@ diff --git a/src/forms/report_create_form.php b/src/forms/report_create_form.php index 653c333..fd80def 100644 --- a/src/forms/report_create_form.php +++ b/src/forms/report_create_form.php @@ -1,3 +1,4 @@ + @@ -12,11 +13,15 @@ diff --git a/src/forms/report_edit_form.php b/src/forms/report_edit_form.php index 48833de..bbf7e58 100644 --- a/src/forms/report_edit_form.php +++ b/src/forms/report_edit_form.php @@ -1,3 +1,4 @@ + @@ -11,11 +12,15 @@ diff --git a/src/forms/user_create_form.html b/src/forms/user_create_form.html index 1592100..201ad7c 100644 --- a/src/forms/user_create_form.html +++ b/src/forms/user_create_form.html @@ -1,3 +1,4 @@ + @@ -12,11 +13,15 @@ diff --git a/src/forms/user_edit_form.php b/src/forms/user_edit_form.php index 04c5f84..061fd17 100644 --- a/src/forms/user_edit_form.php +++ b/src/forms/user_edit_form.php @@ -1,3 +1,4 @@ + @@ -11,11 +12,15 @@ diff --git a/src/holiday.php b/src/holiday.php index 231de51..63bdcc4 100644 --- a/src/holiday.php +++ b/src/holiday.php @@ -1,4 +1,4 @@ - + @@ -13,11 +13,15 @@ diff --git a/src/index.php b/src/index.php index 331cc65..8032963 100644 --- a/src/index.php +++ b/src/index.php @@ -1,3 +1,4 @@ + @@ -11,11 +12,15 @@ diff --git a/src/login.php b/src/login.php new file mode 100644 index 0000000..70d0e9f --- /dev/null +++ b/src/login.php @@ -0,0 +1,44 @@ + + + + + + Gestión de usuarios + + + + + + +
+ +
+ +
+
+ + +
+
+ + +
+
+ +
+
+ diff --git a/src/patient.php b/src/patient.php index 76aada7..4d3c109 100644 --- a/src/patient.php +++ b/src/patient.php @@ -1,4 +1,4 @@ - + @@ -13,11 +13,15 @@ diff --git a/src/report.php b/src/report.php index e48311c..858d244 100644 --- a/src/report.php +++ b/src/report.php @@ -1,4 +1,4 @@ - + @@ -9,19 +9,23 @@ -
- +
Crear
diff --git a/src/user.php b/src/user.php index e680c07..c4f32fd 100644 --- a/src/user.php +++ b/src/user.php @@ -1,4 +1,4 @@ - + @@ -9,19 +9,23 @@ -
- -
+
+ +
Crear
diff --git a/src/user_management.php b/src/user_management.php index f478f76..6127d31 100644 --- a/src/user_management.php +++ b/src/user_management.php @@ -35,6 +35,21 @@ function userFind(){ header("location: user.php?search=$search"); } +function userLogin(){ + $location = 'login.php'; + $data = $_POST; + $pdo = connectDatabase(); + $db_data = fetchLoginData($pdo, $data); + closeDatabase($pdo); + if($data["usuario"] == $db_data["usuario"] && $data["contraseña"] == $db_data["contraseña"]){ + session_start(); + $_SESSION["user"] = $db_data["usuario"]; + $_SESSION["user_type"] = $db_data["rol"]; + $location = 'index.php'; + } + header("location: $location"); +} + if (isset($_POST["create"])) { userCreation(); } @@ -51,3 +66,7 @@ if (isset($_GET["delete"])) { if (isset($_POST["search"])) { userFind(); } + +if (isset($_POST["login"])) { + userLogin(); +} diff --git a/src/validate_user.js b/src/validate_user.js index 0ec3afd..b98c64b 100644 --- a/src/validate_user.js +++ b/src/validate_user.js @@ -45,3 +45,19 @@ function validateUser(){ return true; } + +function validateLogin(){ + var user = document.forms["login_form"]["usuario"]; + var password = document.forms["login_form"]["contraseña"]; + + if(!validateString(user.value)){ + alert("Introduce el usuario"); + return false; + } + + if(!validateString(password.value)){ + alert("Introduce la contraseña"); + return false; + } + return true; +} diff --git a/static/style.css b/static/style.css index 80b88c9..6f041d9 100644 --- a/static/style.css +++ b/static/style.css @@ -123,21 +123,18 @@ header li a { main { background: white; } + .hero { - /* Sizing */ width: 100vw; height: 100vh; - /* Flexbox stuff */ display: flex; justify-content: center; align-items: center; - /* Text styles */ text-align: center; color: white; - /* Background styles */ background-image: linear-gradient(rgba(0, 0, 0, 0.5),rgba(0, 0, 0, 0.5)), url('https://www.pepperconstruction.com/sites/default/files/images/pmc1.jpg'); background-size: cover; background-position: center center; @@ -145,3 +142,9 @@ main { background-attachment: fixed; } +.hero h1 { + font-size: 5em; + + margin-top: 0; + margin-bottom: 0.5em; +}