Formulaire incription utilisateur
This commit is contained in:
@@ -21,6 +21,8 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
|
||||
implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.4'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
|
||||
@@ -5,6 +5,8 @@ import fr.eni.enchere.bo.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@@ -22,4 +24,12 @@ public class InscriptionController {
|
||||
model.addAttribute("user", new User());
|
||||
return "inscription";
|
||||
}
|
||||
|
||||
@PostMapping("/newUser")
|
||||
public String setUser(@ModelAttribute User user) {
|
||||
System.out.println(user.getId());
|
||||
//userService.setUtilisateur(user);
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
public interface UserRepository {
|
||||
List<User> findAll();
|
||||
User findById(int id);
|
||||
User save(User utilisateur);
|
||||
void save(User utilisateur);
|
||||
void edit(int id);
|
||||
void delete(int id);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package fr.eni.enchere.dall;
|
||||
|
||||
import fr.eni.enchere.bo.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
@@ -8,6 +13,13 @@ import java.util.List;
|
||||
@Repository
|
||||
public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public UserRepositoryImpl(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findAll() {
|
||||
return List.of();
|
||||
@@ -19,8 +31,30 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public User save(User utilisateur) {
|
||||
return null;
|
||||
public void save(User utilisateur) {
|
||||
if (utilisateur.getId() == 0) {
|
||||
String sql = "insert into UTILISATEURS (pseudo, nom, prenom, email, telephone," +
|
||||
" rue, code_postal, ville, mot_de_passe, credit, administrateur)" +
|
||||
" values (:pseudo, :nom, :prenom, :email, :telephone," +
|
||||
" :rue, :code_postal, :ville, :mot_de_passe, 0, false)";
|
||||
|
||||
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
parameters.addValue("pseudo", utilisateur.getPseudo());
|
||||
parameters.addValue("nom", utilisateur.getNom());
|
||||
parameters.addValue("prenom", utilisateur.getPrenom());
|
||||
parameters.addValue("email", utilisateur.getEmail());
|
||||
parameters.addValue("telephone", utilisateur.getTelephone());
|
||||
parameters.addValue("rue", utilisateur.getRue());
|
||||
parameters.addValue("code_postal", utilisateur.getCode_postal());
|
||||
parameters.addValue("ville", utilisateur.getVille());
|
||||
parameters.addValue("mot_de_passe", utilisateur.getPassword());
|
||||
|
||||
jdbcTemplate.update(sql, parameters, keyHolder ,new String[] {"id"} );
|
||||
utilisateur.setId(keyHolder.getKey().intValue());
|
||||
}else {
|
||||
//Mettre à jour
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
|
||||
spring.datasource.url=jdbc:mariadb://91.121.54.36:3306/eni_enchere
|
||||
spring.datasource.username=eni
|
||||
spring.datasource.password=Pa$$w0rd
|
||||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||
@@ -1,8 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<html lang="fr" th:replace="~{modele-page :: layout('Inscription',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Inscription</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Ajouter la page de nav bar -->
|
||||
@@ -125,11 +124,9 @@
|
||||
<input type="password" id="password" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button>Créer</button>
|
||||
<button>Annuler</button>
|
||||
<input type="submit" value="Créer"/>
|
||||
</form>
|
||||
|
||||
<a href="/">Annuler</a>
|
||||
</div>
|
||||
<!-- Ajouter le footer -->
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user