changes to updateuser, added logout button

This commit is contained in:
LilleBRG 2025-03-25 16:11:14 +01:00
parent f42dcd743a
commit a3f3d8f861
16 changed files with 119 additions and 67 deletions

View File

@ -75,12 +75,6 @@ namespace Api.BusinessLogic
public async Task<IActionResult> EditProfile(EditUserRequest userRequest, int userId) public async Task<IActionResult> EditProfile(EditUserRequest userRequest, int userId)
{ {
if (!new Regex(@".+@.+\..+").IsMatch(userRequest.Email))
{
return new ConflictObjectResult(new { message = "Invalid email address" });
}
return await _dbAccess.UpdateUser(userRequest, userId); return await _dbAccess.UpdateUser(userRequest, userId);
} }

View File

@ -91,9 +91,13 @@ namespace Api.DBAccess
} }
} }
profile.UserName = user.UserName; if(user.Email != "" && user.Email != null)
profile.Email = user.Email;
if (user.UserName != "" && user.UserName != null)
profile.UserName = user.UserName;
profile.Email = user.Email;
bool saved = await _context.SaveChangesAsync() == 1; bool saved = await _context.SaveChangesAsync() == 1;

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Temperature-Alarm-Web</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<link rel="stylesheet" href="/styles/auth.css">
<link rel="stylesheet" href="/styles/devices.css" />
<script defer type="module" src="/scripts/devices.js"></script>
<script defer type="module" src="/shared/utils.js"></script>
</head>
<body>
<div id="container">
<div class="topnav">
<a href="/home/index.html">Home</a>
<a class="active" href="/devices/index.html">Devices</a>
<div style="display: flex; justify-content: flex-end;">
<a href="/profile/index.html">Profile</a>
<span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div>
</div>
<table>
<tr>
<th>Id</th>
<th>Placement</th>
<th>Latest Meassurement</th>
</tr>
<tbody id="deviceTable"></tbody>
</table>
</div>
</body>
</html>

View File

@ -8,15 +8,19 @@
<link rel="stylesheet" href="/styles/auth.css"> <link rel="stylesheet" href="/styles/auth.css">
<link rel="stylesheet" href="/styles/home.css" /> <link rel="stylesheet" href="/styles/home.css" />
<script type="module" src="/scripts/home.js"></script> <script type="module" src="/scripts/home.js"></script>
<script defer type="module" src="/shared/utils.js"></script>
</head> </head>
<body> <body>
<div id="container"> <div id="container">
<div class="topnav"> <div class="topnav">
<a class="active" href="/home/index.html">Home</a> <a class="active" href="/home/index.html">Home</a>
<a href="/devices/index.html">Devices</a>
<div style="display: flex; justify-content: flex-end;"> <div style="display: flex; justify-content: flex-end;">
<a class="" href="/home/index.html">Devices</a> <a href="/profile/index.html">Profile</a>
<a class="" href="/profile/index.html">Profile</a> <span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div> </div>
</div> </div>
<div class="chartContainer"> <div class="chartContainer">

BIN
frontend/img/logout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@ -20,9 +20,6 @@
<button type="submit">Login</button> <button type="submit">Login</button>
<div class="details"> <div class="details">
<label>
<input type="checkbox" name="remember" id="rememberId"> Remember me
</label>
<span> <span>
Dont have an account? <a href="/register">Register</a> Dont have an account? <a href="/register">Register</a>
</span> </span>

View File

@ -7,14 +7,18 @@
<link rel="stylesheet" href="/styles/auth.css"> <link rel="stylesheet" href="/styles/auth.css">
<link rel="stylesheet" href="/styles/profile.css"> <link rel="stylesheet" href="/styles/profile.css">
<script defer type="module" src="/scripts/profile.js"></script> <script defer type="module" src="/scripts/profile.js"></script>
<script defer type="module" src="/shared/utils.js"></script>
</head> </head>
<body> <body>
<div id="container"> <div id="container">
<div class="topnav"> <div class="topnav">
<a class="active" href="/home/index.html">Home</a> <a href="/home/index.html">Home</a>
<a href="/devices/index.html">Devices</a>
<div style="display: flex; justify-content: flex-end;"> <div style="display: flex; justify-content: flex-end;">
<a class="" href="/home/index.html">Devices</a> <a class="active" href="/profile/index.html">Profile</a>
<a class="" href="/profile/index.html">Profile</a> <span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div> </div>
</div> </div>
<div id="profileCard"></div> <div id="profileCard"></div>
@ -32,10 +36,10 @@
<form id="editForm"> <form id="editForm">
<div class="form-container"> <div class="form-container">
<label for="email"><b>Email</b></label> <label for="email"><b>Email</b></label>
<input type="email" placeholder="Enter email "id="email" required> <input type="email" placeholder="Enter email "id="email">
<label for="uname"><b>Username</b></label> <label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter username" id="uname" required> <input type="text" placeholder="Enter username" id="uname">
<button type="submit">Save Changes</button> <button type="submit">Save Changes</button>

View File

@ -10,7 +10,7 @@
<body> <body>
<form id="registerForm"> <form id="registerForm">
<div class="form-container"> <div class="form-container">
<h1>Create Account</h1> <h1>Sign Up</h1>
<label for="email"><b>Email</b></label> <label for="email"><b>Email</b></label>
<input type="email" placeholder="Enter email "id="email" required> <input type="email" placeholder="Enter email "id="email" required>

View File

@ -0,0 +1,26 @@
import { getDevicesOnUserId } from "./services/devices.service.js";
let idlocation = localStorage.getItem("rememberLogin")
let id;
if(idlocation){
id = localStorage.getItem("id");
}
else{
id = localStorage.getItem("id");
}
getDevicesOnUserId(id).then(res => {
buildTable(res)
})
function buildTable(data) {
var table = document.getElementById(`deviceTable`);
data.forEach((device) => {
var row = ` <tr>
<td>Name</td>
<td class="${color}">${device.id}</td>
<td>${device.name}</td>
</tr>`;
table.innerHTML += row;
});
}

View File

@ -61,24 +61,4 @@ function buildTable(data) {
</tr>`; </tr>`;
table.innerHTML += row; table.innerHTML += row;
}); });
} }
// Get the modal
var modal = document.getElementById("chartModal");
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function () {
modal.style.display = "block";
};
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
};
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
};

View File

@ -17,15 +17,7 @@ document.getElementById("loginForm").addEventListener("submit", function(event)
} }
else{ else{
if (typeof(Storage) !== "undefined") { if (typeof(Storage) !== "undefined") {
if(document.getElementById("rememberId").checked == true){ localStorage.setItem("id", response.id);
localStorage.setItem("id", response.id);
localStorage.setItem("rememberLogin", true);
}
else{
localStorage.setItem("rememberLogin", false);
sessionStorage.setItem("id", response.id);
}
} }
} }

View File

@ -3,14 +3,8 @@ import { get } from "./services/users.service.js";
import { update } from "./services/users.service.js"; import { update } from "./services/users.service.js";
import { updatePassword } from "./services/users.service.js"; import { updatePassword } from "./services/users.service.js";
let idlocation = localStorage.getItem("rememberLogin") let id = localStorage.getItem("id");
let id;
if(idlocation){
id = localStorage.getItem("id");
}
else{
id = localStorage.getItem("id");
}
get(id).then(res => { get(id).then(res => {
var table = document.getElementById(`profileCard`); var table = document.getElementById(`profileCard`);
table.innerHTML += ` table.innerHTML += `
@ -40,6 +34,8 @@ document.querySelectorAll(".close").forEach(closeBtn => {
closeBtn.onclick = () => { closeBtn.onclick = () => {
pswModal.style.display = "none"; pswModal.style.display = "none";
editModal.style.display = "none"; editModal.style.display = "none";
document.getElementById("form-error").innerText = "";
document.getElementById("form-error").style.display = "none";
}; };
}); });

View File

@ -1,12 +1,11 @@
import { address } from "../../shared/constants"; import { address } from "../../shared/constants.js";
export function getDevicesOnUserId(id) { export function getDevicesOnUserId(userId) {
fetch(`${address}/get-on-user-id`, { fetch(`${address}/device/${userId}`, {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
body: JSON.stringify({ id: id })
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => console.log("Success:", data)) .then(data => console.log("Success:", data))

View File

@ -10,3 +10,9 @@ export async function handleResponse(response) {
return { error: "Request failed with HTTP code " + response.status }; return { error: "Request failed with HTTP code " + response.status };
} }
document.querySelectorAll(".logoutContainer").forEach(closeBtn => {
closeBtn.onclick = () => {
localStorage.clear();
window.location.href = "/index.html";
};
});

View File

@ -9,6 +9,7 @@ body {
} }
.topnav a { .topnav a {
height: 20px;
float: left; float: left;
color: #f2f2f2; color: #f2f2f2;
text-align: center; text-align: center;
@ -17,15 +18,16 @@ body {
font-size: 17px; font-size: 17px;
} }
.topnav a:hover { .topnav a:hover, .topnav span:hover {
background-color: #ddd; background-color: #ddd;
color: black; color: black;
} cursor: pointer;
}
.topnav a.active {
.topnav a.active {
background-color: #04aa6d; background-color: #04aa6d;
color: white; color: white;
} }
/* Full-width input fields */ /* Full-width input fields */
input[type=text], input[type=password], input[type=email] { input[type=text], input[type=password], input[type=email] {
@ -60,7 +62,7 @@ button:hover {
.details { .details {
display: flex; display: flex;
justify-content: space-between; justify-content: flex-end;
margin-top: 0.5rem; margin-top: 0.5rem;
} }
@ -74,3 +76,15 @@ button:hover {
margin-top: 1rem; margin-top: 1rem;
} }
.logoutContainer{
display: flex;
justify-content: center;
align-items: center;
width: 50px;
}
.logout{
width: 20px;
height: 24px;
}

View File