mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-07-09 13:27:45 +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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -29,6 +29,11 @@
|
|||||||
<artifactId>org.eclipse.persistence.jpa</artifactId>
|
<artifactId>org.eclipse.persistence.jpa</artifactId>
|
||||||
<version>3.0.4</version>
|
<version>3.0.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.6</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package uppa.project;
|
package uppa.project;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import uppa.project.dao.DAO;
|
import uppa.project.dao.DAO;
|
||||||
|
import uppa.project.dao.DAOException;
|
||||||
import uppa.project.dao.jpa.Game_JPA_DAO_Factory;
|
import uppa.project.dao.jpa.Game_JPA_DAO_Factory;
|
||||||
import uppa.project.pojo.Game;
|
|
||||||
import uppa.project.pojo.Player;
|
|
||||||
import uppa.project.pojo.User;
|
import uppa.project.pojo.User;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
@@ -17,34 +15,43 @@ public class Main {
|
|||||||
// DAO<Player> daoJpaPlayer = jpaDaoFactory.getDAOPlayer();
|
// DAO<Player> daoJpaPlayer = jpaDaoFactory.getDAOPlayer();
|
||||||
|
|
||||||
// Contenu de la BD au début
|
// Contenu de la BD au début
|
||||||
User[] users = daoJpaUser.findAll();
|
// User[] users = daoJpaUser.findAll();
|
||||||
for (User u : users) {
|
// for (User u : users) {
|
||||||
System.out.println(u.toString());
|
// System.out.println(u.toString());
|
||||||
|
// }
|
||||||
|
// System.out.println();
|
||||||
|
|
||||||
|
// // Ajout d'User :
|
||||||
|
// Calendar cal1 = Calendar.getInstance();
|
||||||
|
// cal1.set(1996, Calendar.FEBRUARY, 20);
|
||||||
|
// User user1 = new User("Kevin", "Mitresse", cal1.getTime(), User.Gender.MALE);
|
||||||
|
//
|
||||||
|
// Calendar cal2 = Calendar.getInstance();
|
||||||
|
// cal2.set(2002, Calendar.JUNE, 28);
|
||||||
|
// User user2 = new User("Lucàs", "Vabre", cal2.getTime(), User.Gender.MALE);
|
||||||
|
//
|
||||||
|
// daoJpaUser.create(user1);
|
||||||
|
// daoJpaUser.create(user2);
|
||||||
|
|
||||||
|
System.out.println("test récupération user");
|
||||||
|
User[] users2 = daoJpaUser.findByField("username", "Kevin");
|
||||||
|
for (User user : users2) {
|
||||||
|
System.out.println(user.toString());
|
||||||
}
|
}
|
||||||
System.out.println();
|
System.out.println("fin test");
|
||||||
|
} catch (DAOException e) {
|
||||||
// Ajout d'User :
|
throw new RuntimeException(e);
|
||||||
Calendar cal1 = Calendar.getInstance();
|
|
||||||
cal1.set(1996, Calendar.FEBRUARY, 20);
|
|
||||||
User user1 = new User("Kevin", "Mitresse", cal1.getTime(), User.Gender.MALE);
|
|
||||||
|
|
||||||
Calendar cal2 = Calendar.getInstance();
|
|
||||||
cal2.set(2002, Calendar.JUNE, 28);
|
|
||||||
User user2 = new User("Lucàs", "Vabre", cal2.getTime(), User.Gender.MALE);
|
|
||||||
|
|
||||||
daoJpaUser.create(user1);
|
|
||||||
daoJpaUser.create(user2);
|
|
||||||
|
|
||||||
// Contenu de la BD après ajout
|
|
||||||
users = daoJpaUser.findAll();
|
|
||||||
for (User u : users) {
|
|
||||||
System.out.println(u.toString());
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
EntityManagerProvider.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
// Contenu de la BD après ajout
|
||||||
|
// users = daoJpaUser.findAll();
|
||||||
|
// for (User u : users) {
|
||||||
|
// System.out.println(u.toString());
|
||||||
|
// }
|
||||||
|
// System.out.println();
|
||||||
|
//
|
||||||
|
// EntityManagerProvider.close();
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
package uppa.project.dao;
|
package uppa.project.dao;
|
||||||
|
|
||||||
|
import jakarta.persistence.TypedQuery;
|
||||||
|
import java.util.List;
|
||||||
|
import uppa.project.pojo.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DAO abstrait et générique pour tout type de données
|
* DAO abstrait et générique pour tout type de données
|
||||||
*
|
*
|
||||||
@@ -52,4 +56,6 @@ public abstract class DAO<D> {
|
|||||||
* @throws DAOException en cas de problème
|
* @throws DAOException en cas de problème
|
||||||
*/
|
*/
|
||||||
public abstract void delete(D data) throws DAOException;
|
public abstract void delete(D data) throws DAOException;
|
||||||
|
|
||||||
|
public abstract D[] findByField(String field, String value) throws DAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import uppa.project.EntityManagerProvider;
|
|||||||
import uppa.project.dao.DAO;
|
import uppa.project.dao.DAO;
|
||||||
import uppa.project.dao.DAOException;
|
import uppa.project.dao.DAOException;
|
||||||
import uppa.project.pojo.Game;
|
import uppa.project.pojo.Game;
|
||||||
|
import uppa.project.pojo.User;
|
||||||
|
|
||||||
public class DAO_JPA_Game extends DAO<Game> {
|
public class DAO_JPA_Game extends DAO<Game> {
|
||||||
|
|
||||||
@@ -24,6 +25,14 @@ public class DAO_JPA_Game extends DAO<Game> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Game[] findByField(String field, String value) throws DAOException {
|
||||||
|
TypedQuery<Game> query = entityManager.createQuery("SELECT u FROM Game u WHERE ?1=?2", Game.class);
|
||||||
|
query.setParameter(1, field);
|
||||||
|
query.setParameter(2, value);
|
||||||
|
List<Game> results = query.getResultList();
|
||||||
|
return results.toArray(new Game[0]);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Game[] findAll() throws DAOException {
|
public Game[] findAll() throws DAOException {
|
||||||
TypedQuery<Game> query = entityManager.createQuery("SELECT g FROM Game g", Game.class);
|
TypedQuery<Game> query = entityManager.createQuery("SELECT g FROM Game g", Game.class);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import uppa.project.EntityManagerProvider;
|
|||||||
import uppa.project.dao.DAO;
|
import uppa.project.dao.DAO;
|
||||||
import uppa.project.dao.DAOException;
|
import uppa.project.dao.DAOException;
|
||||||
import uppa.project.pojo.Player;
|
import uppa.project.pojo.Player;
|
||||||
|
import uppa.project.pojo.User;
|
||||||
|
|
||||||
public class DAO_JPA_Player extends DAO<Player> {
|
public class DAO_JPA_Player extends DAO<Player> {
|
||||||
|
|
||||||
@@ -24,6 +25,14 @@ public class DAO_JPA_Player extends DAO<Player> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player[] findByField(String field, String value) throws DAOException {
|
||||||
|
TypedQuery<Player> query = entityManager.createQuery("SELECT p FROM Player p WHERE ?1=?2", Player.class);
|
||||||
|
query.setParameter(1, field);
|
||||||
|
query.setParameter(2, value);
|
||||||
|
List<Player> results = query.getResultList();
|
||||||
|
return results.toArray(new Player[0]);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player[] findAll() throws DAOException {
|
public Player[] findAll() throws DAOException {
|
||||||
TypedQuery<Player> query = entityManager.createQuery("SELECT p FROM Player p", Player.class);
|
TypedQuery<Player> query = entityManager.createQuery("SELECT p FROM Player p", Player.class);
|
||||||
|
|||||||
@@ -24,6 +24,15 @@ public class DAO_JPA_User extends DAO<User> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User[] findByField(String field, String value) throws DAOException {
|
||||||
|
String sqlQuery = String.format("SELECT u FROM User u WHERE u.%s = (:val)", field);
|
||||||
|
|
||||||
|
TypedQuery<User> query = entityManager.createQuery(sqlQuery, User.class);
|
||||||
|
query.setParameter("val", value);
|
||||||
|
List<User> results = query.getResultList();
|
||||||
|
return results.toArray(new User[0]);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User[] findAll() throws DAOException {
|
public User[] findAll() throws DAOException {
|
||||||
TypedQuery<User> query = entityManager.createQuery("SELECT u FROM User u", User.class);
|
TypedQuery<User> query = entityManager.createQuery("SELECT u FROM User u", User.class);
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
package uppa.project.pojo;
|
package uppa.project.pojo;
|
||||||
|
|
||||||
public class Card {
|
public class Card {
|
||||||
|
/**
|
||||||
|
* The color of the card:
|
||||||
|
* Heart -> Coeur
|
||||||
|
* Clubs -> Trèfle
|
||||||
|
* Spades -> Pique
|
||||||
|
* Diamonds -> Carreau
|
||||||
|
*/
|
||||||
|
public enum Color{HEART, CLUBS, SPADES, DIAMONDS}
|
||||||
|
|
||||||
public enum Color{coeur, carreau, pique, trefle}
|
public enum Value{ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING}
|
||||||
|
|
||||||
public enum Value{un, deux, trois, quatre, cinq, six, sept, huit, neuf, dix, valet, dame, roi}
|
|
||||||
private final Color color;
|
private final Color color;
|
||||||
|
|
||||||
private final Value value;
|
private final Value value;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class User implements Serializable {
|
|||||||
return (int) (diffDays / 365);
|
return (int) (diffDays / 365);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String hashPassword(String password) {
|
public static String hashPassword(String password) {
|
||||||
try {
|
try {
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
|
||||||
@@ -118,7 +118,6 @@ public class User implements Serializable {
|
|||||||
if (hex.length() == 1) hexString.append('0');
|
if (hex.length() == 1) hexString.append('0');
|
||||||
hexString.append(hex);
|
hexString.append(hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hexString.toString();
|
return hexString.toString();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package uppa.project.servlet;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import jakarta.servlet.http.*;
|
|
||||||
import jakarta.servlet.annotation.*;
|
|
||||||
|
|
||||||
@WebServlet(name = "helloServlet", value = "/hello-servlet")
|
|
||||||
public class HelloServlet extends HttpServlet {
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
message = "Hello World!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
||||||
response.setContentType("text/html");
|
|
||||||
|
|
||||||
// Hello
|
|
||||||
PrintWriter out = response.getWriter();
|
|
||||||
out.println("<html><body>");
|
|
||||||
out.println("<h1>" + message + "</h1>");
|
|
||||||
out.println("</body></html>");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void destroy() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package uppa.project.servlet;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import uppa.project.dao.DAO;
|
||||||
|
import uppa.project.dao.DAOException;
|
||||||
|
import uppa.project.dao.jpa.Game_JPA_DAO_Factory;
|
||||||
|
import uppa.project.servlet.json.ErrorApi;
|
||||||
|
import uppa.project.pojo.User;
|
||||||
|
import uppa.project.servlet.utils.RequestUtils;
|
||||||
|
|
||||||
|
@WebServlet(name = "loginApiServlet", value = "/api/login")
|
||||||
|
public class LoginServlet extends HttpServlet {
|
||||||
|
|
||||||
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
response.setContentType("application/json");
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
PrintWriter out = response.getWriter();
|
||||||
|
|
||||||
|
// Convert the string to a JSON object
|
||||||
|
JsonObject jsonBody;
|
||||||
|
try {
|
||||||
|
String requestBody = RequestUtils.getRequestBody(request);
|
||||||
|
jsonBody = JsonParser.parseString(requestBody).getAsJsonObject();
|
||||||
|
} catch (Exception e) {
|
||||||
|
int STATUS = 400;
|
||||||
|
|
||||||
|
ErrorApi error = new ErrorApi(STATUS, "Bad Request", "Invalid JSON");
|
||||||
|
response.setStatus(STATUS);
|
||||||
|
out.println(error.toJson());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the username and password are present
|
||||||
|
JsonElement username = jsonBody.get("username");
|
||||||
|
JsonElement password = jsonBody.get("password");
|
||||||
|
if (username == null || password == null) {
|
||||||
|
int STATUS = 400;
|
||||||
|
|
||||||
|
ErrorApi error = new ErrorApi(STATUS, "Bad Request", "Username and password are required");
|
||||||
|
response.setStatus(STATUS);
|
||||||
|
out.println(error.toJson());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get User from database matching the username and password
|
||||||
|
User user = LoginServlet.loginUser(username.getAsString(), password.getAsString());
|
||||||
|
if (user == null) {
|
||||||
|
int STATUS = 401;
|
||||||
|
ErrorApi error = new ErrorApi(STATUS, "Unauthorized", "Invalid username or password");
|
||||||
|
|
||||||
|
response.setStatus(STATUS);
|
||||||
|
out.println(error.toJson());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the user as JSON
|
||||||
|
String json = gson.toJson(user);
|
||||||
|
out.println(json);
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static User loginUser(String username, String password) {
|
||||||
|
Game_JPA_DAO_Factory factory = new Game_JPA_DAO_Factory();
|
||||||
|
try {
|
||||||
|
DAO<User> userDao = factory.getDAOUser();
|
||||||
|
User[] users = userDao.findByField("username", username);
|
||||||
|
|
||||||
|
for (User user : users) {
|
||||||
|
if (user.verifyPassword(password)) return user;
|
||||||
|
}
|
||||||
|
} catch (DAOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package uppa.project.servlet.json;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
public class ErrorApi {
|
||||||
|
private final int status;
|
||||||
|
private final String error;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public ErrorApi(int status, String error, String message) {
|
||||||
|
this.status = status;
|
||||||
|
this.error = error;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
return gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package uppa.project.servlet.utils;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class RequestUtils {
|
||||||
|
public static String getRequestBody(HttpServletRequest request) throws IOException {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
BufferedReader reader = request.getReader();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
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"
|
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
|
||||||
version="5.0">
|
version="5.0">
|
||||||
</web-app>
|
</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" %>
|
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>JSP - Hello World</title>
|
<title>JSP - Hello World</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1><%= "Hello World!" %></h1>
|
|
||||||
<br/>
|
|
||||||
<a href="hello-servlet">Hello Servlet</a>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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