mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-13 17:11:49 +00:00
feat: dev-web - manage account creation
This commit is contained in:
@@ -342,4 +342,11 @@ public class User implements Serializable {
|
||||
* Enumération des genres possibles
|
||||
*/
|
||||
public enum Gender {MALE, FEMALE, OTHER}
|
||||
|
||||
public static Gender getGender(String value) throws IllegalArgumentException{
|
||||
if (value.equals("MALE")) return Gender.MALE;
|
||||
if (value.equals("FEMALE")) return Gender.FEMALE;
|
||||
if (value.equals("OTHER")) return Gender.OTHER;
|
||||
throw new IllegalArgumentException("Le genre selectionné n'existe pas");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,13 @@ import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import uppa.project.dao.DAOException;
|
||||
import uppa.project.dao.jpa.DAO_JPA_User;
|
||||
import uppa.project.pojo.User;
|
||||
|
||||
@WebServlet(name = "registerServlet", value = "/register")
|
||||
public class RegisterServlet extends HttpServlet {
|
||||
@@ -29,9 +36,38 @@ public class RegisterServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
// TODO : Implement the registration process
|
||||
String username = request.getParameter("username");
|
||||
String email = request.getParameter("email");
|
||||
String birthdate = request.getParameter("birthdate");
|
||||
System.out.println(birthdate);
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date birth;
|
||||
try {
|
||||
birth = formatter.parse(birthdate);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.out.println("birth: " + birth);
|
||||
String gender = request.getParameter("gender");
|
||||
String password = request.getParameter("password");
|
||||
String confirmPassword = request.getParameter("confirmPassword");
|
||||
if (!password.equals(confirmPassword)) {
|
||||
response.sendRedirect(request.getContextPath() + "/register?error=matching-password");
|
||||
return;
|
||||
}
|
||||
createAccount(username, email, password, birth, gender);
|
||||
response.sendRedirect(request.getContextPath() + "/login?success=account-created");
|
||||
}
|
||||
|
||||
public static void createAccount(String username, String email, String password, Date birth, String gender){
|
||||
try{
|
||||
DAO_JPA_User daoJpaUser = new DAO_JPA_User();
|
||||
User user = new User(username, email, password, birth, User.getGender(gender));
|
||||
daoJpaUser.create(user);
|
||||
} catch (DAOException | IllegalArgumentException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<body>
|
||||
|
||||
<main>
|
||||
<section id="title">Titre du jeu</section>
|
||||
<section id="title">Cards Rush - Inscription</section>
|
||||
<section id="form">
|
||||
<div class="border-left"></div>
|
||||
<div class="flex-column register-gap">
|
||||
@@ -16,27 +16,27 @@
|
||||
<h1>Register</h1>
|
||||
<form id="register-form" action="${pageContext.request.contextPath}/register" method="post">
|
||||
|
||||
<label for="email">Email:</label>
|
||||
<label for="email">Email :</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
|
||||
<label for="username">Username:</label>
|
||||
<label for="username">Nom d'utilisateur :</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
|
||||
<label for="password">Password:</label>
|
||||
<label for="password">Mot de passe :</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
|
||||
<label for="repassword">RePassword:</label>
|
||||
<input type="password" id="repassword" name="password" required>
|
||||
<label for="confirmPassword">Confirmez le mot de pass :</label>
|
||||
<input type="password" id="confirmPassword" name="confirmPassword" required>
|
||||
|
||||
<label for="birthdate">Birthdate:</label>
|
||||
<label for="birthdate">Date de naissance :</label>
|
||||
<input type="date" id="birthdate" name="birthdate" required>
|
||||
|
||||
<label for="gender">Gender:</label>
|
||||
<select name="gender" id="gender">
|
||||
<option value="">--Please choose an option--</option>
|
||||
<option value="MALE">Mâle</option>
|
||||
<option value="FEMALE">Female</option>
|
||||
<option value="OTHER">Other</option>
|
||||
<label for="gender">Genre :</label>
|
||||
<select name="gender" id="gender" required>
|
||||
<option value="">--Choisissez une option--</option>
|
||||
<option value="MALE">Homme</option>
|
||||
<option value="FEMALE">Femme</option>
|
||||
<option value="OTHER">Autre</option>
|
||||
</select>
|
||||
|
||||
<input id="register-submit" type="submit" value="Register">
|
||||
@@ -44,7 +44,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<hr>
|
||||
<p>Already have an account? <a href="${pageContext.request.contextPath}/login">Login</a></p>
|
||||
<p>Déjà un compte ? <a href="${pageContext.request.contextPath}/login">Se connecter</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user