Changeset e440971
- Timestamp:
- 01/05/23 17:07:31 (23 months ago)
- Branches:
- main
- Children:
- f08836b
- Parents:
- 6489bb9
- Location:
- FullyStocked
- Files:
-
- 7 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/pom.xml
r6489bb9 re440971 33 33 <groupId>org.postgresql</groupId> 34 34 <artifactId>postgresql</artifactId> 35 </dependency>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 35 </dependency> 44 36 <dependency> -
FullyStocked/src/main/java/com/bazi/fullystocked/Controller/LoginController.java
r6489bb9 re440971 2 2 3 3 import com.bazi.fullystocked.Models.Exceptions.InvalidUserCredentialsException; 4 import com.bazi.fullystocked.Models.Managers; 4 5 import com.bazi.fullystocked.Models.User; 6 import com.bazi.fullystocked.Models.Workers; 5 7 import com.bazi.fullystocked.Services.AuthService; 6 8 import org.springframework.stereotype.Controller; … … 33 35 public String login(HttpServletRequest request, Model model) { 34 36 User user = null; 35 try {37 try { 36 38 user = this.authService.login(request.getParameter("username"), 37 39 request.getParameter("password")); 38 request.getSession().setAttribute("user", user); 40 if (user instanceof Workers) { 41 Workers w= (Workers) user; 42 request.getSession().setAttribute("user", w); 43 request.getSession().setAttribute("location",w.getLocation().getLocationname()+" "+w.getLocation().getCity()); 44 return "redirect:/homeWorker"; 45 } else if (user instanceof Managers) { 46 Managers m= (Managers) user; 47 request.getSession().setAttribute("user", m); 48 return "redirect:/homeManager"; 49 } 39 50 return "redirect:/home"; 40 51 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Models/User.java
r6489bb9 re440971 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;9 7 10 8 import java.util.Collection; … … 16 14 @NoArgsConstructor 17 15 @Table(name="users") 18 public class User implements UserDetails{16 public class User { 19 17 @Id 20 18 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 48 46 this.userpassword = password; 49 47 } 50 51 @Override52 public Collection<? extends GrantedAuthority> getAuthorities() {53 return null;54 }55 56 @Override57 public String getPassword() {58 return userpassword;59 }60 61 @Override62 public boolean isAccountNonExpired() {63 return true;64 }65 66 @Override67 public boolean isAccountNonLocked() {68 return true;69 }70 71 @Override72 public boolean isCredentialsNonExpired() {73 return true;74 }75 76 @Override77 public boolean isEnabled() {78 return true;79 }80 48 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/AuthService.java
r6489bb9 re440971 5 5 import com.bazi.fullystocked.Models.User; 6 6 import com.bazi.fullystocked.Models.Workers; 7 import org.springframework.security.core.userdetails.UserDetailsService;8 7 9 public interface AuthService extends UserDetailsService{8 public interface AuthService { 10 9 User login(String username, String password); 11 10 Workers registerWorker(String firstname, String lastname, String username, String email, String password); -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/AuthServiceImpl.java
r6489bb9 re440971 14 14 import com.bazi.fullystocked.Repositories.WorkersRepository; 15 15 import com.bazi.fullystocked.Services.AuthService; 16 import org.springframework.security.core.userdetails.UserDetails;17 16 import org.springframework.security.crypto.password.PasswordEncoder; 18 17 import org.springframework.stereotype.Service; … … 82 81 } 83 82 84 @Override85 public UserDetails loadUserByUsername(String username) throws UserNotFoundException {86 return usersRepository.findByUsername(username).orElseThrow(() -> new UserNotFoundException(username));87 88 }89 83 }
Note:
See TracChangeset
for help on using the changeset viewer.