Connexion page
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.User;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserRepository {
|
||||
List<User> findAll();
|
||||
User findById(int id);
|
||||
void save(User utilisateur);
|
||||
List<UserProfil> findAll();
|
||||
UserProfil findById(int id);
|
||||
UserProfil findByUsername(String username);
|
||||
void save(UserProfil utilisateur);
|
||||
void delete(int id);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.User;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -10,7 +10,9 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
@Primary
|
||||
@@ -26,17 +28,41 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> findAll() {
|
||||
public List<UserProfil> findAll() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findById(int id) {
|
||||
public UserProfil findById(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(User utilisateur) {
|
||||
public UserProfil findByUsername(String username) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("username", username);
|
||||
UserProfil user = namedParameterJdbcTemplate.queryForObject(sql, params, (rs, rowNum) -> {
|
||||
UserProfil userProfile = new UserProfil();
|
||||
userProfile.setId(rs.getInt("no_utilisateur"));
|
||||
userProfile.setPrenom(rs.getString("prenom"));
|
||||
userProfile.setNom(rs.getString("nom"));
|
||||
userProfile.setPseudo(rs.getString("pseudo"));
|
||||
userProfile.setEmail(rs.getString("email"));
|
||||
userProfile.setTelephone(rs.getString("telephone"));
|
||||
userProfile.setRue(rs.getString("rue"));
|
||||
userProfile.setCode_postal(rs.getString("code_postal"));
|
||||
userProfile.setVille(rs.getString("ville"));
|
||||
userProfile.setPassword(rs.getString("mot_de_passe"));
|
||||
userProfile.setCredit(rs.getFloat("credit"));
|
||||
userProfile.setAdmin(rs.getBoolean("administrateur"));
|
||||
return userProfile;
|
||||
});
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(UserProfil 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)";
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
|
||||
Reference in New Issue
Block a user