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

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

register functionality

  1. Changed css of login.html
  2. Changed css and html of register
  3. Foreign keys in Adopter and Employee changed from int to Integer
  4. AuthorisationService updated with methods for employee and adopter registration
  5. RegisterController works only for employee and adopter
  6. Added services for Organisation and Shelter for dropdown list on registration form
  • 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 HttpServletRequest request) {
45
46 if(role.equals("adopter") & password.equals(repeatPassword)){
47 String freeTime = request.getParameter("freeTime");
48 String funds = request.getParameter("funds");
49 boolean hasOtherPets = Boolean.parseBoolean(request.getParameter("hasOtherPets"));
50 boolean hasKids = Boolean.parseBoolean(request.getParameter("hasKids"));
51 String housing = request.getParameter("housing");
52 String physicalActivity = request.getParameter("physicalActivity");
53 boolean willFoster = Boolean.parseBoolean(request.getParameter("willFoster"));
54
55 FreeTime ft = FreeTime.valueOf(freeTime);
56 Funds f = Funds.valueOf(funds);
57 Housing h = Housing.valueOf(housing);
58 PhysicalActivity pa = PhysicalActivity.valueOf(physicalActivity);
59
60 Adopter adopterUser = authService.registerAdopter(name, email, password, telephone,ft,f,hasOtherPets,hasKids,h,pa,willFoster);
61
62 request.getSession().setAttribute("user",adopterUser);
63 return "redirect:/home";
64 }
65 else if(role.equals("employee") & password.equals(repeatPassword)){
66 Integer shelter = Integer.valueOf(request.getParameter("shelter"));
67 String position = request.getParameter("position");
68
69 Employee employeeUser = authService.registerEmployee(name, email, password, telephone,position,shelter);
70
71 request.getSession().setAttribute("user",employeeUser);
72 return "redirect:/home";
73 }
74
75 return "redirect:/register";
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.