Max/Backend/loginApi Ajout mock Users et Tokens #62
@ -2,6 +2,7 @@ package ovh.herisson.Clyde.EndPoints;
|
|||||||
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
||||||
@ -23,6 +24,8 @@ public class MockController {
|
|||||||
public final UserRepository userRepo;
|
public final UserRepository userRepo;
|
||||||
public final TokenRepository tokenRepo;
|
public final TokenRepository tokenRepo;
|
||||||
|
|
||||||
|
ArrayList<User> mockUsers;
|
||||||
|
|
||||||
|
|
||||||
public MockController(UserRepository userRepo, TokenRepository tokenRepo){
|
public MockController(UserRepository userRepo, TokenRepository tokenRepo){
|
||||||
this.tokenRepo = tokenRepo;
|
this.tokenRepo = tokenRepo;
|
||||||
@ -35,7 +38,7 @@ public class MockController {
|
|||||||
* They all have silly names
|
* They all have silly names
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@PostMapping("/generateMock")
|
@PostMapping("/mock")
|
||||||
public void postMock(){
|
public void postMock(){
|
||||||
|
|
||||||
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), Role.Admin,passwordEncoder.encode("admin"));
|
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), Role.Admin,passwordEncoder.encode("admin"));
|
||||||
@ -43,13 +46,20 @@ public class MockController {
|
|||||||
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), Role.Teacher,passwordEncoder.encode("secretary"));
|
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), Role.Teacher,passwordEncoder.encode("secretary"));
|
||||||
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), Role.Teacher,passwordEncoder.encode("teacher"));
|
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), Role.Teacher,passwordEncoder.encode("teacher"));
|
||||||
|
|
||||||
|
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
||||||
|
|
||||||
ArrayList<User> users = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
userRepo.saveAll(mockUsers);
|
||||||
|
|
||||||
userRepo.saveAll(users);
|
for (User user: mockUsers){
|
||||||
|
|
||||||
for (User user: users){
|
|
||||||
tokenRepo.save(new Token(user,user.getPassword()));
|
tokenRepo.save(new Token(user,user.getPassword()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/mock")
|
||||||
|
public void deleteMock(){
|
||||||
|
for (User user:mockUsers){
|
||||||
|
tokenRepo.deleteAll(tokenRepo.getByUser(user));
|
||||||
|
}
|
||||||
|
userRepo.deleteAll(mockUsers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,6 @@ import ovh.herisson.Clyde.Tables.User;
|
|||||||
public interface TokenRepository extends CrudRepository<Token,Long> {
|
public interface TokenRepository extends CrudRepository<Token,Long> {
|
||||||
|
|
||||||
Token getByToken(String token);
|
Token getByToken(String token);
|
||||||
|
|
||||||
|
Iterable<Token> getByUser(User user);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user