Compare commits
	
		
			6 Commits
		
	
	
		
			wal/front/
			...
			Leo/Backen
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c0890ac76a | |||
| 49b99e14c9 | |||
| 9328601d2d | |||
| 79f4b84b70 | |||
| 0c73f6f44d | |||
| a1bdae9e83 | 
@ -15,7 +15,7 @@ import java.util.Date;
 | 
			
		||||
 | 
			
		||||
public class MockController {
 | 
			
		||||
    private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
 | 
			
		||||
 | 
			
		||||
    public final UserService userService;
 | 
			
		||||
    public final UserRepository userRepo;
 | 
			
		||||
    public final TokenRepository tokenRepo;
 | 
			
		||||
    public final TokenService tokenService;
 | 
			
		||||
@ -27,7 +27,8 @@ public class MockController {
 | 
			
		||||
    ArrayList<User> mockUsers;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService){
 | 
			
		||||
    public MockController(UserService userService, UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService){
 | 
			
		||||
        this.userService = userService;
 | 
			
		||||
        this.tokenRepo = tokenRepo;
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
        this.tokenService = tokenService;
 | 
			
		||||
@ -45,19 +46,19 @@ public class MockController {
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/mock")
 | 
			
		||||
    public void postMock(){
 | 
			
		||||
 | 
			
		||||
        // user part
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        User herobrine = new User("brine","hero","admin@admin.com","behind","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
 | 
			
		||||
        User joe = new User("Mama","Joe","student@student.com","roundabout","England",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
 | 
			
		||||
        User meh = new User("Polo","Marco","secretary@secretary.com","a Box","Monaco",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary"));
 | 
			
		||||
        User joke = new User("Gaillard","Corentin","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
 | 
			
		||||
        User jojo = new User("Bridoux","Justin","teacher2@teacher2.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
 | 
			
		||||
        User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.InscriptionService,passwordEncoder.encode("inscriptionService"));
 | 
			
		||||
        mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena,jojo));
 | 
			
		||||
 | 
			
		||||
        userRepo.saveAll(mockUsers);
 | 
			
		||||
        mockUsers = new ArrayList<>(Arrays.asList(joke, herobrine, joe, meh, jojo));
 | 
			
		||||
        userService.saveAll(mockUsers);
 | 
			
		||||
        userService.save(lena);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //Course / Curriculum part
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								backend/src/main/java/ovh/herisson/Clyde/RegNoGenerator.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								backend/src/main/java/ovh/herisson/Clyde/RegNoGenerator.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
package ovh.herisson.Clyde;
 | 
			
		||||
 | 
			
		||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
 | 
			
		||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
 | 
			
		||||
import org.hibernate.id.IdentifierGenerator;
 | 
			
		||||
 | 
			
		||||
import java.sql.*;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.GregorianCalendar;
 | 
			
		||||
 | 
			
		||||
public class RegNoGenerator implements IdentifierGenerator {
 | 
			
		||||
    private static int count = 0;
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object generate(SharedSessionContractImplementor session, Object object) {
 | 
			
		||||
        try{
 | 
			
		||||
            JdbcConnectionAccess jdbccon = session.getJdbcConnectionAccess();
 | 
			
		||||
            Connection conn = jdbccon.obtainConnection();
 | 
			
		||||
 | 
			
		||||
            Statement statement = conn.createStatement();
 | 
			
		||||
 | 
			
		||||
            Calendar c = new GregorianCalendar();
 | 
			
		||||
            int y = c.get(Calendar.YEAR);
 | 
			
		||||
            String query = "select count(reg_no) + "+count+" from Users where reg_no/10000 = " + y%1000;
 | 
			
		||||
 | 
			
		||||
            ResultSet set = statement.executeQuery(query);
 | 
			
		||||
            long resp = 0;
 | 
			
		||||
            if(set.next()){
 | 
			
		||||
                resp = set.getLong(1)+((y%1000)*10000);
 | 
			
		||||
                count += 1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            conn.close();
 | 
			
		||||
            statement.close();
 | 
			
		||||
 | 
			
		||||
            return resp;
 | 
			
		||||
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void resetCount(){
 | 
			
		||||
        count = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -5,13 +5,10 @@ import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
public interface UserRepository extends CrudRepository<User, Long> {
 | 
			
		||||
 | 
			
		||||
    User findById(long id);
 | 
			
		||||
 | 
			
		||||
    User findByEmail(String email);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher")
 | 
			
		||||
    Iterable<User> findAllTeachers();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,16 +2,17 @@ package ovh.herisson.Clyde.Services;
 | 
			
		||||
 | 
			
		||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import ovh.herisson.Clyde.RegNoGenerator;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
import java.util.*;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class UserService {
 | 
			
		||||
    private final UserRepository userRepo;
 | 
			
		||||
    private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
 | 
			
		||||
 | 
			
		||||
    public UserService(UserRepository userRepo){
 | 
			
		||||
        this.userRepo = userRepo;
 | 
			
		||||
    }
 | 
			
		||||
@ -106,10 +107,19 @@ public class UserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public User save(User  user){
 | 
			
		||||
        RegNoGenerator.resetCount();
 | 
			
		||||
        user.setPassword(passwordEncoder.encode(user.getPassword()));
 | 
			
		||||
        return userRepo.save(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void saveAll(ArrayList<User> list){
 | 
			
		||||
        //S'assure que le compteur est bien a 0
 | 
			
		||||
        RegNoGenerator.resetCount();
 | 
			
		||||
        userRepo.saveAll(list);
 | 
			
		||||
        //Reset le compteur a zero pour les futurs ajouts
 | 
			
		||||
        RegNoGenerator.resetCount();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<User> getAll(){
 | 
			
		||||
        return userRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
@ -131,4 +141,5 @@ public class UserService {
 | 
			
		||||
    public void delete(User user) {
 | 
			
		||||
        userRepo.delete(user);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,8 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import org.hibernate.annotations.GenericGenerator;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,7 +10,8 @@ import java.util.Date;
 | 
			
		||||
@Table(name = "Users")
 | 
			
		||||
public class User {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    @GenericGenerator(name = "userGen", type = ovh.herisson.Clyde.RegNoGenerator.class)
 | 
			
		||||
    @GeneratedValue(generator = "userGen")
 | 
			
		||||
    private Long regNo;
 | 
			
		||||
    private String lastName;
 | 
			
		||||
    private String firstName;
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,2 @@
 | 
			
		||||
spring.jpa.hibernate.ddl-auto=create-drop
 | 
			
		||||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
 | 
			
		||||
spring.sql.init.mode=always
 | 
			
		||||
@ -23,6 +23,7 @@ import ovh.herisson.Clyde.Repositories.TokenRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Repositories.UserRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
 | 
			
		||||
import ovh.herisson.Clyde.Services.TokenService;
 | 
			
		||||
import ovh.herisson.Clyde.Services.UserService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Token;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
@ -47,6 +48,8 @@ public class UserControllerTest {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private TokenService tokenService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private UserService userService;
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private UserRepository userRepository;
 | 
			
		||||
    @Autowired
 | 
			
		||||
@ -79,12 +82,13 @@ public class UserControllerTest {
 | 
			
		||||
        tokenRepository.deleteAll();
 | 
			
		||||
        userRepository.deleteAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    //Verifie qu'un user qui n'a pas les permissions admin ou secretaire ne peut pas post
 | 
			
		||||
    public void userPostTest(){
 | 
			
		||||
        User god = new User("god","god","admin@admin.com","everywhere","every",new Date(0), null, Role.Admin,"goddoesntneedpassword");
 | 
			
		||||
        Token godToken = new Token(god, tokenService.generateNewToken(), new Date());
 | 
			
		||||
        userRepository.save(god);
 | 
			
		||||
        userService.save(god);
 | 
			
		||||
        tokenService.saveToken(godToken);
 | 
			
		||||
 | 
			
		||||
        //Can god post herobrine himself ?
 | 
			
		||||
@ -97,7 +101,7 @@ public class UserControllerTest {
 | 
			
		||||
        //Can noob post herobrine without authorizations (no)
 | 
			
		||||
        User noob = new User("boon","noob","noob@student.com","everywhere","every",new Date(0), null, Role.Student,"noob");
 | 
			
		||||
        Token noobToken = new Token(noob, tokenService.generateNewToken(), new Date());
 | 
			
		||||
        userRepository.save(noob);
 | 
			
		||||
        userService.save(noob);
 | 
			
		||||
        tokenService.saveToken(noobToken);
 | 
			
		||||
 | 
			
		||||
        with().body(herobrine).contentType(ContentType.JSON).header("Authorization", noobToken.getToken()).when().request("POST", "/user").then().statusCode(401);
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
 | 
			
		||||
import org.springframework.test.context.TestPropertySource;
 | 
			
		||||
import ovh.herisson.Clyde.Services.UserService;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Role;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@ -24,6 +25,7 @@ public class UserRepoTest {
 | 
			
		||||
 | 
			
		||||
    @BeforeEach
 | 
			
		||||
    public void setup(){
 | 
			
		||||
        userRepo.deleteAll();
 | 
			
		||||
        User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand", new GregorianCalendar(2005, 4, 3).getTime(), null, Role.Admin,"admin");
 | 
			
		||||
        userRepo.save(herobrine);
 | 
			
		||||
    }
 | 
			
		||||
@ -34,8 +36,8 @@ public class UserRepoTest {
 | 
			
		||||
    }
 | 
			
		||||
    @Test
 | 
			
		||||
    public void usertest(){
 | 
			
		||||
        Assert.assertEquals("brine", userRepo.findById(1).getLastName());
 | 
			
		||||
        Assert.assertTrue(new GregorianCalendar(2005, 4, 3).getTime().equals(userRepo.findById(1).getBirthDate()));
 | 
			
		||||
        Assert.assertEquals("brine", userRepo.findByEmail("admin@admin.com").getLastName());
 | 
			
		||||
        Assert.assertTrue(new GregorianCalendar(2005, 4, 3).getTime().equals(userRepo.findByEmail("admin@admin.com").getBirthDate()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -86,12 +86,14 @@ window.addEventListener('hashchange', () => {
 | 
			
		||||
    </ul>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="page">
 | 
			
		||||
      <div style=" margin:50px;">
 | 
			
		||||
        <Suspense>
 | 
			
		||||
        
 | 
			
		||||
		<component :is="currentView" />
 | 
			
		||||
        </Suspense>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
 | 
			
		||||
@ -55,7 +55,7 @@
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<template style="background-color:rgba(255,255,255,0.05); border-radius:50px" >
 | 
			
		||||
<template>
 | 
			
		||||
      <div class='loginBox'>
 | 
			
		||||
 | 
			
		||||
        <div v-if="loginPage">
 | 
			
		||||
@ -157,14 +157,31 @@
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
.Home{
 | 
			
		||||
  position:absolute;
 | 
			
		||||
 	display: flex;
 | 
			
		||||
  z-index: 100;
 | 
			
		||||
	padding: 8px 16px;
 | 
			
		||||
	color:rgb(255, 255, 255);
 | 
			
		||||
	text-decoration: none;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.Home:hover{
 | 
			
		||||
  width:40px;
 | 
			
		||||
  background-color: black;
 | 
			
		||||
	border-radius:6px;
 | 
			
		||||
	color:white;
 | 
			
		||||
  transform: translate(0px ,1px);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
.loginBox {
 | 
			
		||||
  background-color: rgb(24,24,24);
 | 
			
		||||
  width: 100%;
 | 
			
		||||
  height:100%;
 | 
			
		||||
  width: 400px;
 | 
			
		||||
  display:flex;
 | 
			
		||||
  justify-content: center;
 | 
			
		||||
  padding: 10%;
 | 
			
		||||
  border-radius: 5%;
 | 
			
		||||
  padding: 40px;
 | 
			
		||||
  border-radius: 20px;
 | 
			
		||||
  box-shadow:0 5px 25px #000000;
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
@ -173,8 +190,9 @@
 | 
			
		||||
  width:100%;
 | 
			
		||||
  display: flex;
 | 
			
		||||
  flex-direction: column;
 | 
			
		||||
  justify-content: center;
 | 
			
		||||
  align-items:center;
 | 
			
		||||
  gap: 3%;
 | 
			
		||||
  gap: 15px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -182,12 +200,12 @@
 | 
			
		||||
  
 | 
			
		||||
  width:100%;
 | 
			
		||||
  border: none;
 | 
			
		||||
  margin-right: 12.5%;
 | 
			
		||||
  padding-left: 2.5%;
 | 
			
		||||
  padding-top:2.5%;
 | 
			
		||||
  padding-bottom:2.5%;
 | 
			
		||||
  margin-right: 50px;
 | 
			
		||||
  padding-left: 10px;
 | 
			
		||||
  padding-top:10px;
 | 
			
		||||
  padding-bottom:10px;
 | 
			
		||||
  outline:none;
 | 
			
		||||
  border-radius: 10px;
 | 
			
		||||
  border-radius: 4px;
 | 
			
		||||
  font-size:1.35em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user