Changeset d7f5da9 for src/main/java/com


Ignore:
Timestamp:
02/07/23 13:48:25 (23 months ago)
Author:
milamihajlovska <mila.mihajlovska01@…>
Branches:
master
Children:
fc448f5
Parents:
f7b0906
Message:

changes for login (not working)

Location:
src/main/java/com/example/moviezone
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/model/Customer.java

    rf7b0906 rd7f5da9  
    3434
    3535    @Override
     36    public boolean equals(Object o) {
     37        if (this == o) return true;
     38        if (o == null || getClass() != o.getClass()) return false;
     39        Customer customer = (Customer) o;
     40        return id_user!=null && Objects.equals(id_user,customer.id_user);
     41    }
     42
     43    @Override
     44    public int hashCode() {
     45        return Objects.hash();
     46    }
     47
     48    @Override
    3649    public Collection<? extends GrantedAuthority> getAuthorities() {
    3750        return Collections.singletonList(Role.ROLE_USER);
  • src/main/java/com/example/moviezone/model/Worker.java

    rf7b0906 rd7f5da9  
    1010import java.util.Collection;
    1111import java.util.Collections;
     12import java.util.Objects;
    1213
    1314@Entity
     
    3233    }
    3334
     35    @Override
     36    public boolean equals(Object o) {
     37        if (this == o) return true;
     38        if (o == null || getClass() != o.getClass()) return false;
     39        Worker worker = (Worker) o;
     40        return id_user!=null && Objects.equals(id_user, worker.id_user);
     41    }
     42
     43    @Override
     44    public int hashCode() {
     45        return Objects.hash();
     46    }
     47
    3448    public Worker() {
    3549
  • src/main/java/com/example/moviezone/service/Impl/UserServiceImpl.java

    rf7b0906 rd7f5da9  
    4848
    4949    @Override
    50     public User register(String first_name, String last_name, String username, String email, String number, String password,String repeatedPassword, Role role) {
    51        if(!password.equals(repeatedPassword))
    52            throw new PasswordsDoNotMatchException();
    53        if (username==null || username.isEmpty()  || password==null || password.isEmpty())
    54             throw new InvalidUsernameOrPasswordException();
     50    public void register(String first_name, String last_name, String username, String email, String number, String password, Role role) {
     51//       if(!password.equals(repeatedPassword))
     52//           throw new PasswordsDoNotMatchException();
     53//       if (username==null || username.isEmpty()  || password==null || password.isEmpty())
     54//            throw new InvalidUsernameOrPasswordException();
    5555
    5656       if(role.equals(Role.ROLE_ADMIN))
    5757        {
    58             User user= new User(passwordEncoder.encode(password),first_name,last_name,username,email,number);
    59             workerRepository.save((Worker) user);
    60             return userRepository.save(user);
     58//            User user= new User(passwordEncoder.encode(password),first_name,last_name,username,email,number);
     59//            workerRepository.save((Worker) user);
     60            userRepository.save(new Worker(password,first_name,last_name,email,number,username));
    6161        }
    6262        else
    6363       {
    64            Customer customer=new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number);
    65           customerRepository.save(customer);
    66            return userRepository.save(customer);
     64//           Customer customer=new Customer(passwordEncoder.encode(password),first_name,last_name,username,email,number);
     65//           customerRepository.save(customer);
     66           userRepository.save(new Customer(password,first_name,last_name,email,number,username));
    6767
    6868       }
  • src/main/java/com/example/moviezone/service/UserService.java

    rf7b0906 rd7f5da9  
    1111    User findByUsername(String username);
    1212
    13   User register(String first_name, String last_name,String username, String email, String number, String password,String repeatedPassword, Role role);
     13    void register(String first_name, String last_name,String username, String email, String number, String password, Role role);
    1414    User login(String username,String password);
    1515}
  • src/main/java/com/example/moviezone/web/HomeController.java

    rf7b0906 rd7f5da9  
    7777
    7878    @PostMapping("/login")
    79     public String login(@RequestParam String username,@RequestParam String password,Model model, HttpSession session)
    80     {
    81         User user = null;
    82         try {
    83             user=userService.login(username,password);
    84             session.setAttribute("sessionUser",user);
    85             model.addAttribute("user",user);
     79    public String login(@RequestParam String username,
     80                        @RequestParam String password,Model model, HttpSession session)
     81    {
     82//        User user = null;
     83//        try {
     84           User user=userService.login(username,password);
     85        System.out.println(user.getFirst_name());
     86//            session.setAttribute("sessionUser",user);
     87//            model.addAttribute("user",user);
    8688            return "redirect:/home";
    87 
    88         }catch (UserNotFoundException e)
    89         {
    90             model.addAttribute("hasError", true);
    91             model.addAttribute("error", e.getMessage());
    92             return "login";
    93         }
     89//
     90//        }catch (UserNotFoundException e)
     91//        {
     92//            model.addAttribute("hasError", true);
     93//            model.addAttribute("error", e.getMessage());
     94//            return "login";
     95//        }
    9496
    9597    }
     
    106108    {
    107109        try {
    108            User user=userService.register(first_name,last_name,username,email,number,password,repeatedPassword,role);
     110           userService.register(first_name,last_name,username,email,number,password,role);
    109111            return "redirect:/login";
    110112        }catch (PasswordsDoNotMatchException exception)
Note: See TracChangeset for help on using the changeset viewer.