Changeset 6489bb9
- Timestamp:
- 01/05/23 01:40:08 (2 years ago)
- Branches:
- main
- Children:
- e440971
- Parents:
- f11774e
- Location:
- FullyStocked
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/pom.xml
rf11774e r6489bb9 34 34 <artifactId>postgresql</artifactId> 35 35 </dependency> 36 36 <dependency> 37 <groupId>org.springframework.boot</groupId> 38 <artifactId>spring-boot-starter-security</artifactId> 39 </dependency> 40 <dependency> 41 <groupId>org.thymeleaf.extras</groupId> 42 <artifactId>thymeleaf-extras-springsecurity5</artifactId> 43 </dependency> 37 44 <dependency> 38 45 <groupId>org.projectlombok</groupId> -
FullyStocked/src/main/java/com/bazi/fullystocked/Models/User.java
rf11774e r6489bb9 5 5 import lombok.Data; 6 6 import lombok.NoArgsConstructor; 7 import org.springframework.security.core.GrantedAuthority; 8 import org.springframework.security.core.userdetails.UserDetails; 7 9 10 import java.util.Collection; 8 11 9 12 … … 13 16 @NoArgsConstructor 14 17 @Table(name="users") 15 public class User {18 public class User implements UserDetails { 16 19 @Id 17 20 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 46 49 } 47 50 51 @Override 52 public Collection<? extends GrantedAuthority> getAuthorities() { 53 return null; 54 } 55 56 @Override 57 public String getPassword() { 58 return userpassword; 59 } 60 61 @Override 62 public boolean isAccountNonExpired() { 63 return true; 64 } 65 66 @Override 67 public boolean isAccountNonLocked() { 68 return true; 69 } 70 71 @Override 72 public boolean isCredentialsNonExpired() { 73 return true; 74 } 75 76 @Override 77 public boolean isEnabled() { 78 return true; 79 } 48 80 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/WorkersRepository.java
rf11774e r6489bb9 3 3 import com.bazi.fullystocked.Models.Invoices; 4 4 import com.bazi.fullystocked.Models.Locations; 5 import com.bazi.fullystocked.Models.User; 5 6 import com.bazi.fullystocked.Models.Workers; 6 7 import org.springframework.data.jpa.repository.JpaRepository; … … 13 14 List<Workers> findAllByLocation(Locations location); 14 15 List<Workers> findAllByLocationIsNull(); 16 15 17 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/AuthService.java
rf11774e r6489bb9 5 5 import com.bazi.fullystocked.Models.User; 6 6 import com.bazi.fullystocked.Models.Workers; 7 import org.springframework.security.core.userdetails.UserDetailsService; 7 8 8 public interface AuthService {9 public interface AuthService extends UserDetailsService { 9 10 User login(String username, String password); 10 11 Workers registerWorker(String firstname, String lastname, String username, String email, String password); -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/AuthServiceImpl.java
rf11774e r6489bb9 14 14 import com.bazi.fullystocked.Repositories.WorkersRepository; 15 15 import com.bazi.fullystocked.Services.AuthService; 16 import org.springframework.security.core.userdetails.UserDetails; 16 17 import org.springframework.security.crypto.password.PasswordEncoder; 17 18 import org.springframework.stereotype.Service; … … 25 26 private final PasswordEncoder passwordEncoder; 26 27 27 public AuthServiceImpl( UsersRepository usersRepository, WorkersRepository workersRepository, SuppliersRepository suppliersRepository, ManagersRepository managersRepository, PasswordEncoder passwordEncoder) {28 public AuthServiceImpl( UsersRepository usersRepository, WorkersRepository workersRepository, SuppliersRepository suppliersRepository, ManagersRepository managersRepository, PasswordEncoder passwordEncoder) { 28 29 this.usersRepository = usersRepository; 29 30 this.workersRepository = workersRepository; … … 35 36 @Override 36 37 public User login(String username, String password) { 37 if (username ==null || username.isEmpty() || password==null || password.isEmpty()) {38 if (username == null || username.isEmpty() || password == null || password.isEmpty()) { 38 39 throw new InvalidArgumentsException(); 39 40 } 40 User user=usersRepository.findByUsername(username).orElseThrow(()->new UserNotFoundException(username)); 41 if(passwordEncoder.matches(password, user.getUserpassword())) 42 { 41 User user = usersRepository.findByUsername(username).orElseThrow(() -> new UserNotFoundException(username)); 42 if (passwordEncoder.matches(password, user.getUserpassword())) { 43 43 return user; 44 } 45 else 46 { 44 } else { 47 45 throw new InvalidUserCredentialsException(); 48 46 } … … 62 60 63 61 private void RegParamsCheck(String firstname, String lastname, String username, String email, String password) { 64 if(firstname==null || firstname.isEmpty() || lastname==null || lastname.isEmpty() || username==null || username.isEmpty() || email==null || email.isEmpty() || password==null || password.isEmpty()) 65 { 62 if (firstname == null || firstname.isEmpty() || lastname == null || lastname.isEmpty() || username == null || username.isEmpty() || email == null || email.isEmpty() || password == null || password.isEmpty()) { 66 63 throw new InvalidArgumentsException(); 67 64 } 68 if(usersRepository.findByUsername(username).isPresent()) 69 { 65 if (usersRepository.findByUsername(username).isPresent()) { 70 66 throw new UsernameAlreadyExistsException(username); 71 67 } … … 74 70 @Override 75 71 public Suppliers registerSupplier(String firstname, String lastname, String username, String email, String password, String supplierInfo, String phone, String street, int streetNumber, String city) { 76 if(firstname==null || firstname.isEmpty() || lastname==null || lastname.isEmpty() || username==null || username.isEmpty() || email==null || email.isEmpty() || password==null || password.isEmpty()) 77 { 72 if (firstname == null || firstname.isEmpty() || lastname == null || lastname.isEmpty() || username == null || username.isEmpty() || email == null || email.isEmpty() || password == null || password.isEmpty()) { 78 73 throw new InvalidArgumentsException(); 79 74 } 80 if(supplierInfo==null || supplierInfo.isEmpty() || phone==null || phone.isEmpty() || street==null || street.isEmpty() || city==null || city.isEmpty()) 81 { 75 if (supplierInfo == null || supplierInfo.isEmpty() || phone == null || phone.isEmpty() || street == null || street.isEmpty() || city == null || city.isEmpty()) { 82 76 throw new InvalidArgumentsException(); 83 77 } 84 if(usersRepository.findByUsername(username).isPresent()) 85 { 78 if (usersRepository.findByUsername(username).isPresent()) { 86 79 throw new UsernameAlreadyExistsException(username); 87 80 } 88 81 return suppliersRepository.save(new Suppliers(firstname, lastname, username, email, passwordEncoder.encode(password), supplierInfo, phone, street, streetNumber, city)); 89 82 } 83 84 @Override 85 public UserDetails loadUserByUsername(String username) throws UserNotFoundException { 86 return usersRepository.findByUsername(username).orElseThrow(() -> new UserNotFoundException(username)); 87 88 } 90 89 } -
FullyStocked/src/main/resources/templates/login.html
rf11774e r6489bb9 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 1 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous"> 2 <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script> 3 <meta charset="UTF-8"> 4 <th:block xmlns="http://www.w3.org/1999/xhtml"> 5 <section class="vh-100"> 6 <div class="container py-5 h-100"> 7 <div class="row d-flex align-items-center justify-content-center h-100"> 8 <div class="col-md-8 col-lg-7 col-xl-6"> 9 <img src="https://img.freepik.com/free-vector/warehouse-isometric-template_1284-15709.jpg?w=2000" 10 class="img-fluid" alt="Phone image"> 11 </div> 12 <div class="col-md-7 col-lg-5 col-xl-5 offset-xl-1"> 13 <h2>Најави се</h2> 14 <form method="POST" action="/login"> 15 <div class="form-outline mb-4"> 16 <input name="username" type="text" id="username" class="form-control form-control-lg" /> 17 <label class="form-label" for="username">Username</label> 18 </div> 8 19 9 </body> 10 </html> 20 <div class="form-outline mb-4"> 21 <input name="password" type="password" id="password" class="form-control form-control-lg" /> 22 <label class="form-label" for="password">Password</label> 23 </div> 24 25 <button type="submit" class="btn btn-primary btn-lg btn-block">Најави се</button> 26 27 </form> 28 </div> 29 </div> 30 </div> 31 </section> 32 </th:block> -
FullyStocked/src/main/resources/templates/register.html
rf11774e r6489bb9 3 3 <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script> 4 4 <meta charset="UTF-8"> 5 <th:block xmlns="http://www.thymeleaf.org"> 5 6 <section class="vh-230" style="background-color: #eee;"> 6 7 <div class="container h-150"> … … 14 15 <p class="text-center h1 fw-bold mb-5 mx-1 mx-md-4 mt-4">Регистрација</p> 15 16 16 <form class="mx-1 mx-md-4" >17 <form class="mx-1 mx-md-4" method="POST" action="/register"> 17 18 18 19 <div class="d-flex flex-row align-items-center mb-4"> 19 20 <i class="fas fa-user fa-lg me-3 fa-fw"></i> 20 21 <div class="form-outline flex-fill mb-0"> 21 <input type="text" id="ime" class="form-control" />22 <input name="ime" for="ime" type="text" id="ime" class="form-control" /> 22 23 <label class="form-label" for="ime">Име</label> 23 24 </div> … … 26 27 <i class="fas fa-user fa-lg me-3 fa-fw"></i> 27 28 <div class="form-outline flex-fill mb-0"> 28 <input type="text" id="prezime" class="form-control" />29 <input name="prezime" for="prezime" type="text" id="prezime" class="form-control" /> 29 30 <label class="form-label" for="prezime">Презиме</label> 30 31 </div> … … 33 34 <i class="fas fa-user fa-lg me-3 fa-fw"></i> 34 35 <div class="form-outline flex-fill mb-0"> 35 <input type="text" id="username" class="form-control" />36 <input name="username" for="username" type="text" id="username" class="form-control" /> 36 37 <label class="form-label" for="username">Username</label> 37 38 </div> … … 41 42 <i class="fas fa-envelope fa-lg me-3 fa-fw"></i> 42 43 <div class="form-outline flex-fill mb-0"> 43 <input type="email" id="email" class="form-control" />44 <input name="email" for="email" type="email" id="email" class="form-control" /> 44 45 <label class="form-label" for="email">Email</label> 45 46 </div> … … 49 50 <i class="fas fa-lock fa-lg me-3 fa-fw"></i> 50 51 <div class="form-outline flex-fill mb-0"> 51 <input type="password" id="password" class="form-control"/>52 <input name="password" for="password" type="password" id="password" class="form-control"/> 52 53 <label class="form-label" for="password">Password</label> 53 54 </div> … … 56 57 <i class="fas fa-lock fa-lg me-3 fa-fw"></i> 57 58 <div class="form-outline flex-fill mb-0"> 58 <select class="form-select" id="tip">59 <select name="role" for="role" class="form-select" id="tip"> 59 60 <option value="1" disabled>Избери тип на профил</option> 60 <option value=" 2">Магационер</option>61 <option value=" 3">Добавувач</option>62 <option value=" 4">Магационер</option>61 <option value="magacioner">Магационер</option> 62 <option value="dobavuvac">Добавувач</option> 63 <option value="menadzer">Менаџер</option> 63 64 </select> 64 65 <label class="form-label" for="tip">Тип</label> … … 66 67 </div> 67 68 <div class="d-flex justify-content-center mx-4 mb-3 mb-lg-4"> 68 <button type=" button" class="btn btn-primary btn-lg">Регистрирај се</button>69 <button type="submit" class="btn btn-primary btn-lg">Регистрирај се</button> 69 70 </div> 70 71 … … 85 86 </div> 86 87 </section> 88 </th:block>
Note:
See TracChangeset
for help on using the changeset viewer.