mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-17 09:05:30 +00:00
feat(DevWeb): Projet - Login page, Login Api
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
|
||||
version="5.0">
|
||||
</web-app>
|
||||
@@ -0,0 +1,13 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +1,11 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JSP - Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= "Hello World!" %></h1>
|
||||
<br/>
|
||||
<a href="hello-servlet">Hello Servlet</a>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
const loginForm = document.getElementById("loginForm");
|
||||
|
||||
loginForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(loginForm);
|
||||
const data = {};
|
||||
formData.forEach((value, key) => data[key] = value);
|
||||
|
||||
const action = loginForm.getAttribute("action")
|
||||
const endpoint = loginForm.getAttribute("data-login-endpoint");
|
||||
const method = loginForm.getAttribute("method")
|
||||
|
||||
fetch(endpoint, {
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(data),
|
||||
method,
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data)
|
||||
window.location.href = action;
|
||||
})
|
||||
.catch(error => console.error("Error:", error))
|
||||
;
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Login</title>
|
||||
<script defer type="text/javascript" src="js/login.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<main>
|
||||
<h1>Login</h1>
|
||||
<form id="loginForm" data-login-endpoint="api/login" action="dashboard.jsp" method="POST">
|
||||
<div class="field">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Login">
|
||||
|
||||
<p>Don't have an account? <a href="register.jsp">Register</a></p>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,34 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Register</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<main>
|
||||
<h1>Login</h1>
|
||||
<form action="register" method="post">
|
||||
<div class="field">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="password">RePassword:</label>
|
||||
<input type="password" id="repassword" name="password" required>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Login">
|
||||
|
||||
<p>Already have an account? <a href="login.jsp">Login</a></p>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user