Changeset e440971


Ignore:
Timestamp:
01/05/23 17:07:31 (23 months ago)
Author:
Bojan <bojantrpeski123@…>
Branches:
main
Children:
f08836b
Parents:
6489bb9
Message:

Home screens added

Location:
FullyStocked
Files:
7 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • FullyStocked/pom.xml

    r6489bb9 re440971  
    3333            <groupId>org.postgresql</groupId>
    3434            <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>
    4335        </dependency>
    4436        <dependency>
  • FullyStocked/src/main/java/com/bazi/fullystocked/Controller/LoginController.java

    r6489bb9 re440971  
    22
    33import com.bazi.fullystocked.Models.Exceptions.InvalidUserCredentialsException;
     4import com.bazi.fullystocked.Models.Managers;
    45import com.bazi.fullystocked.Models.User;
     6import com.bazi.fullystocked.Models.Workers;
    57import com.bazi.fullystocked.Services.AuthService;
    68import org.springframework.stereotype.Controller;
     
    3335    public String login(HttpServletRequest request, Model model) {
    3436        User user = null;
    35         try{
     37        try {
    3638            user = this.authService.login(request.getParameter("username"),
    3739                    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            }
    3950            return "redirect:/home";
    4051        }
  • FullyStocked/src/main/java/com/bazi/fullystocked/Models/User.java

    r6489bb9 re440971  
    55import lombok.Data;
    66import lombok.NoArgsConstructor;
    7 import org.springframework.security.core.GrantedAuthority;
    8 import org.springframework.security.core.userdetails.UserDetails;
    97
    108import java.util.Collection;
     
    1614@NoArgsConstructor
    1715@Table(name="users")
    18 public class User implements UserDetails {
     16public class User {
    1917    @Id
    2018    @GeneratedValue(strategy = GenerationType.IDENTITY)
     
    4846        this.userpassword = password;
    4947    }
    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     }
    8048}
  • FullyStocked/src/main/java/com/bazi/fullystocked/Services/AuthService.java

    r6489bb9 re440971  
    55import com.bazi.fullystocked.Models.User;
    66import com.bazi.fullystocked.Models.Workers;
    7 import org.springframework.security.core.userdetails.UserDetailsService;
    87
    9 public interface AuthService extends UserDetailsService {
     8public interface AuthService {
    109    User login(String username, String password);
    1110    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  
    1414import com.bazi.fullystocked.Repositories.WorkersRepository;
    1515import com.bazi.fullystocked.Services.AuthService;
    16 import org.springframework.security.core.userdetails.UserDetails;
    1716import org.springframework.security.crypto.password.PasswordEncoder;
    1817import org.springframework.stereotype.Service;
     
    8281    }
    8382
    84     @Override
    85     public UserDetails loadUserByUsername(String username) throws UserNotFoundException {
    86         return usersRepository.findByUsername(username).orElseThrow(() -> new UserNotFoundException(username));
    87 
    88     }
    8983}
Note: See TracChangeset for help on using the changeset viewer.