[74af394] | 1 | package com.example.salonbella.startup;
|
---|
| 2 |
|
---|
| 3 | import com.example.salonbella.entity.UserEntity;
|
---|
| 4 | import com.example.salonbella.service.UserService;
|
---|
| 5 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 6 | import org.springframework.boot.CommandLineRunner;
|
---|
| 7 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
---|
| 8 | import org.springframework.security.crypto.password.PasswordEncoder;
|
---|
| 9 | import org.springframework.stereotype.Component;
|
---|
| 10 |
|
---|
| 11 | @Component
|
---|
| 12 | public class CommandLineAppStartupRunner implements CommandLineRunner {
|
---|
| 13 |
|
---|
| 14 | private final UserService userService;
|
---|
| 15 |
|
---|
| 16 | @Autowired
|
---|
| 17 | public CommandLineAppStartupRunner(UserService userService) {
|
---|
| 18 | this.userService = userService;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | @Override
|
---|
| 22 | public void run(String... args) throws Exception {
|
---|
| 23 | PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(10);
|
---|
| 24 | UserEntity userEntity = new UserEntity();
|
---|
| 25 | userEntity.setName("Mladen");
|
---|
| 26 | userEntity.setSurname("Jovanovski");
|
---|
| 27 | userEntity.setEmail("mjovanovski04@gmail.com");
|
---|
| 28 | userEntity.setPassword(passwordEncoder.encode("admin"));
|
---|
| 29 | userEntity.setUsername("admin");
|
---|
| 30 | userEntity.setRole("ADMIN");
|
---|
| 31 | userEntity.setValid(true);
|
---|
| 32 | userEntity.setNumber("072312134");
|
---|
| 33 | userService.registerAdmin(userEntity);
|
---|
| 34 |
|
---|
| 35 | UserEntity userEntity2 = new UserEntity();
|
---|
| 36 | userEntity2.setName("Mladen");
|
---|
| 37 | userEntity2.setSurname("Jovanovski");
|
---|
| 38 | userEntity2.setEmail("m@gmail.com");
|
---|
| 39 | userEntity2.setPassword(passwordEncoder.encode("maky"));
|
---|
| 40 | userEntity2.setUsername("maky");
|
---|
| 41 | userEntity2.setRole("USER");
|
---|
| 42 | userEntity2.setValid(true);
|
---|
| 43 | userEntity2.setNumber("072312134");
|
---|
| 44 | userService.registerAdmin(userEntity2);
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 | }
|
---|