Changeset cc88ec2 for src


Ignore:
Timestamp:
02/09/23 14:57:39 (21 months ago)
Author:
milamihajlovska <mila.mihajlovska01@…>
Branches:
master
Children:
17a2fda
Parents:
ff75720
Message:

updates to login

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

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/config/CustomUsernamePasswordAuthenticationProvider.java

    rff75720 rcc88ec2  
    3535
    3636        UserDetails userDetails = this.userService.findByUsername(username);
    37         String realPassword = userDetails.getPassword();
    38         if (!Objects.equals(password,realPassword)) {
     37//        String realPassword = userDetails.getPassword();
     38        if (!Objects.equals(password,userDetails.getPassword())) {
    3939            throw new BadCredentialsException("Password is incorrect!");
    4040        }
  • src/main/java/com/example/moviezone/web/HomeController.java

    rff75720 rcc88ec2  
    55import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException;
    66
     7import com.example.moviezone.model.exceptions.UserNotFoundException;
    78import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
    89
     
    1516import org.springframework.web.bind.annotation.*;
    1617
     18import javax.servlet.http.HttpServletRequest;
    1719import javax.servlet.http.HttpSession;
    1820import javax.transaction.Transactional;
     
    135137    @PostMapping("/login")
    136138    public String login(@RequestParam String username,
    137                         @RequestParam String password,Model model, HttpSession session)
     139                        @RequestParam String password, Model model, HttpServletRequest request)
    138140    {
    139141//        User user = null;
    140 //        try {
     142        try {
    141143           User user=userService.login(username,password);
    142144        System.out.println(user.getFirst_name());
    143 //            session.setAttribute("sessionUser",user);
    144 //            model.addAttribute("user",user);
     145        request.getSession().setAttribute("user", user);
     146        //            model.addAttribute("user",user);
    145147            return "redirect:/home";
    146 //
    147 //        }catch (UserNotFoundException e)
    148 //        {
    149 //            model.addAttribute("hasError", true);
    150 //            model.addAttribute("error", e.getMessage());
    151 //            return "login";
    152 //        }
     148
     149        }catch (UserNotFoundException e)
     150        {
     151            model.addAttribute("hasError", true);
     152            model.addAttribute("error", e.getMessage());
     153            return "/login";
     154        }
    153155
    154156    }
Note: See TracChangeset for help on using the changeset viewer.