cleaning
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.Token;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "http://localhost:5173")
|
||||
|
||||
public class MockController {
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
public final UserRepository userRepo;
|
||||
public final TokenRepository tokenRepo;
|
||||
|
||||
|
||||
public MockController(UserRepository userRepo, TokenRepository tokenRepo){
|
||||
this.tokenRepo = tokenRepo;
|
||||
this.userRepo = userRepo;
|
||||
}
|
||||
|
||||
/** Saves an example of each user type by :
|
||||
* email : FooRole@FooRole.com, password : FooRole and token : FooRole
|
||||
* For example the admin as "admin@admin.com" as email and "admin" as both password and token
|
||||
* They all have silly names
|
||||
*/
|
||||
|
||||
@PostMapping("/generateMock")
|
||||
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 joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), Role.Student,passwordEncoder.encode("student"));
|
||||
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"));
|
||||
|
||||
|
||||
ArrayList<User> users = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
||||
|
||||
userRepo.saveAll(users);
|
||||
|
||||
for (User user: users){
|
||||
tokenRepo.save(new Token(user,user.getPassword()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user