diff --git a/api/login.php b/api/login.php index 5dab8498f40e183713ebc2118dfcda59c1c7fd54..7f34260eccb4d5b51dddbc7ffb1266794cc7852d 100644 --- a/api/login.php +++ b/api/login.php @@ -20,6 +20,7 @@ if(isset($decoded['email']) && isset($decoded['password'])){ $_SESSION['name'] = $dataUser['user_name']; $_SESSION['password'] = $dataUser['password']; $_SESSION['role'] = $dataUser['isAdmin']; + $_SESSION['profile_photo'] = $dataUser['profile_img']; echo "<script type='text/javascript'> alert('Login Successful'); </script>"; if($dataUser['isAdmin'] == 0){ diff --git a/api/updateProfile.php b/api/updateProfile.php new file mode 100644 index 0000000000000000000000000000000000000000..8d63c837975db5d429cbe73dc2e1dbf1b5c8d1ec --- /dev/null +++ b/api/updateProfile.php @@ -0,0 +1,63 @@ +<?php +require_once '../app/core/db.php'; +require_once '../app/models/user.php'; +session_start(); + +$user = new User; + +// echo $_SESSION['email']; +// echo $_SESSION['name']; +// echo $_SESSION['password']; +// echo $_SESSION['profile_photo']; +// echo " hhhhhhhh "; + +// $name = $_POST['name']; +// $email = $_POST['email']; +// $password = $_POST['password']; +// echo $email; +// echo $password; +// echo $name; +// echo " hhhhhhhh "; + +// $_SESSION['name'] = $name; +// $_SESSION['email'] = $email; +// $_SESSION['password'] = $password; + +// echo $_SESSION['email']; +// echo $_SESSION['name']; +// echo $_SESSION['password']; +// echo $profile_img; + +if(isset($_SESSION['email'])) { + if ($_SERVER["REQUEST_METHOD"] == "POST") { + $name = $_POST['name']; + $email = $_POST['email']; + $password = $_POST['password']; + + $profile_img = $_SESSION['profile_photo']; + if (isset($_FILES['profile_photo'])) { + $profile_img_tmp = $_FILES['profile_photo']['tmp_name']; + + if ($profile_img_tmp != "") { + $profile_img = $_FILES['profile_photo']['name']; + $_SESSION['profile_photo'] = $profile_img; + move_uploaded_file($profile_img_tmp, "../public/assets/img/$profile_img"); + } + } + $user->updateUser($_SESSION['email'], $name, $email, $password, $profile_img); + $_SESSION['name'] = $name; + $_SESSION['email'] = $email; + $_SESSION['password'] = $password; + + echo $_SESSION['email']; + echo $_SESSION['name']; + echo $_SESSION['password']; + + echo "<script type='text/javascript'> alert('Update Successful'); </script>"; + echo "<script>location.href='../app/views/profile/index.php'</script>"; + } else { + echo "<script type='text/javascript'> alert('Update Failed'); </script>"; + echo "<script>location.href='../app/views/profile/index.php'</script>"; + } +} +?> \ No newline at end of file diff --git a/app/models/user.php b/app/models/user.php index e0c932da248d55c25e06e3780d23f797a45fc532..f1030851b2c1d8e3e680ada195bdc6da8e15ec02 100644 --- a/app/models/user.php +++ b/app/models/user.php @@ -16,5 +16,10 @@ class User{ $query = "SELECT * FROM $this->table WHERE email = '$email'"; return $this->database->execute($query); } + + public function updateUser($previousemail, $name, $email, $password, $profile_img) { + $query = "UPDATE $this->table SET user_name = '$name', email = '$email', password = '$password', profile_img = '$profile_img' WHERE email = '$previousemail'"; + $this->database->execute($query); + } } ?> \ No newline at end of file diff --git a/app/views/profile/index.php b/app/views/profile/index.php index 611684bc8978946c6600ff613b4ce0bb0bbe32dd..7d0b7ea9e0b88e8bf96048793a830d47bb4aa02b 100644 --- a/app/views/profile/index.php +++ b/app/views/profile/index.php @@ -35,32 +35,35 @@ $page = "Profile"; </section> <section class="container"> <div class="profile"> + <form class="form" action="/api/updateProfile.php" method="POST" enctype="multipart/form-data"> <div class="image"> <div class="profile-container"> - <img id="profileImage" src="../../../public/assets/img/profile-img.png"/> + <div id="profileImage"> + <img src="../../../public/assets/img/<?php echo $_SESSION['profile_photo']; ?>" alt="Profile Photo" id="profile-preview"> + </div> + </div> + <input class="imageUpload" type="file" id="profile-img" + name="profile_photo" accept=".jpg,.jpeg,.png" capture> </div> - <input class="imageUpload" type="file" - name="profile_photo" placeholder="Photo" required="" capture> - </div> - <div class="form"> <label for="name">Name</label><br> - <input type="text" class="input-form" name="name" required><br> + <input type="text" class="input-form" name="name" value="<?php echo $_SESSION['name']?>" required><br> <label for="email">Email</label><br> - <input type="email" class="input-form" name="email" required><br> + <input type="email" class="input-form" name="email" value=<?php echo $_SESSION['email']?> required><br> <label for="pw">Change Password</label><br> - <input type="password" class="input-form" name="pw" required><br> - </div> - </div> - <div class="update-btn"> - <a href="#" class="update">Update</a> + <input type="password" class="input-form" name="password" value="<?php echo $_SESSION['password']?>" required><br> + <div class="update-btn"> + <!-- <a href="#" type="submit" class="update">Update</a> --> + <input class="update" type="submit" name="update" value="Update" href=""> + </div> + </form> </div> </section> <script> - document.addEventListener("DOMContentLoaded", function() { - setupImageUpload('#profileImage', '.imageUpload'); - }); +document.addEventListener("DOMContentLoaded", function() { + setupImageUpload('#profileImage', '.imageUpload'); +}); </script> <script src="../../../public/js/navbar.js"></script> -<script src="../../../public/js/preview-img.js"></script> +<script src="../../../public/js/preview.js"></script> </body> </html> \ No newline at end of file diff --git a/db/db.sql b/db/db.sql index 6c839218b0f72a4e26a0400e2f6ba22c112a30aa..7c6b6294170e8aa06d2392b35ef64c3fdac6f324 100644 --- a/db/db.sql +++ b/db/db.sql @@ -35,7 +35,8 @@ CREATE TABLE user ( email VARCHAR(255) PRIMARY KEY, user_name VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, - isAdmin BOOLEAN DEFAULT 0 + isAdmin BOOLEAN DEFAULT 0, + profile_img VARCHAR(255) DEFAULT 'profile-img.png' ); -- Insert sample data to the Restaurant table @@ -83,4 +84,3 @@ INSERT INTO schedule VALUES (2, 'Tuesday', '10:00:00', '20:00:00'); INSERT INTO schedule VALUES (2, 'Wednesday', '09:00:00', '19:00:00'); INSERT INTO schedule VALUES (2, 'Thursday', '11:00:00', '18:00:00'); INSERT INTO schedule VALUES (2, 'Friday', '08:00:00', '12:00:00'); - \ No newline at end of file diff --git a/public/css/profile.css b/public/css/profile.css index 2f0197630b3d3197a84a248d4f56beea3787a9b9..5bc998cf2aec56680e31936b5d5ff10efe9c867c 100644 --- a/public/css/profile.css +++ b/public/css/profile.css @@ -18,7 +18,6 @@ body{ align-items: center; justify-content: center; background-color: #F5F5F5; - height: 100vh; } .container{ display: flex; @@ -26,7 +25,7 @@ body{ position: relative; align-items: center; justify-content: center; - margin-top: 20px; + margin: 50px 0px; height: 75vh; } .profile{