source: Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/RegisterController.java@ aced08c

main
Last change on this file since aced08c was aced08c, checked in by trajchevaM <118018439+trajchevaM@…>, 17 months ago

Updated RegisterController and Adopter

Changed primitive types of Adopter

  • Property mode set to 100644
File size: 3.4 KB
Line 
1package finki.paw5.web.controllers;
2import finki.paw5.model.entities.Adopter;
3import finki.paw5.model.entities.Employee;
4import finki.paw5.model.enumerations.FreeTime;
5import finki.paw5.model.enumerations.Funds;
6import finki.paw5.model.enumerations.Housing;
7import finki.paw5.model.enumerations.PhysicalActivity;
8import finki.paw5.service.AuthService;
9import finki.paw5.service.OrganisationService;
10import finki.paw5.service.ShelterService;
11import jakarta.servlet.http.HttpServletRequest;
12import org.springframework.stereotype.Controller;
13import org.springframework.web.bind.annotation.PostMapping;
14import org.springframework.web.bind.annotation.RequestMapping;
15import org.springframework.web.bind.annotation.GetMapping;
16import org.springframework.ui.Model;
17import org.springframework.web.bind.annotation.RequestParam;
18
19@Controller
20@RequestMapping("/register")
21public class RegisterController {
22
23 private final OrganisationService organisationService;
24 private final ShelterService shelterService;
25 private final AuthService authService;
26
27 public RegisterController(OrganisationService organisationService, ShelterService shelterService, AuthService authService) {
28 this.organisationService = organisationService;
29 this.shelterService = shelterService;
30 this.authService = authService;
31 }
32
33 @GetMapping
34 public String getRegisterPage(Model model) {
35 model.addAttribute("shelters", this.shelterService.listShelters());
36 model.addAttribute("organisations", this.organisationService.findAll());
37 return "register";
38 }
39
40 @PostMapping
41 public String registerUser(@RequestParam String name, @RequestParam String email,
42 @RequestParam String password, @RequestParam String repeatPassword,
43 @RequestParam String telephone,@RequestParam String role,
44 @RequestParam (required = false) String freeTime, @RequestParam (required = false) String funds,
45 @RequestParam (required = false) boolean hasOtherPets, @RequestParam (required = false) boolean hasKids,
46 @RequestParam (required = false) String housing, @RequestParam (required = false) String physicalActivity,
47 @RequestParam (required = false) boolean willFoster, @RequestParam (required = false) Integer shelter,
48 @RequestParam (required = false) String position, HttpServletRequest request) {
49
50 if(role.equals("adopter") & password.equals(repeatPassword)){
51
52 FreeTime ft = FreeTime.valueOf(freeTime);
53 Funds f = Funds.valueOf(funds);
54 Housing h = Housing.valueOf(housing);
55 PhysicalActivity pa = PhysicalActivity.valueOf(physicalActivity);
56
57 Adopter adopterUser = authService.registerAdopter(name, email, password, telephone,ft,f,hasOtherPets,hasKids,h,pa,willFoster);
58
59 request.getSession().setAttribute("user",adopterUser);
60 return "redirect:/home";
61 }
62 else if(role.equals("employee") & password.equals(repeatPassword)){
63
64 Employee employeeUser = authService.registerEmployee(name, email, password, telephone,position,shelter);
65
66 request.getSession().setAttribute("user",employeeUser);
67 return "redirect:/home";
68 }
69
70 return "redirect:/register";
71 }
72
73}
Note: See TracBrowser for help on using the repository browser.