Changeset 5f69a70
- Timestamp:
- 01/06/23 16:43:55 (2 years ago)
- Branches:
- main
- Children:
- 154b74c
- Parents:
- f08836b
- Location:
- FullyStocked/src/main
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/src/main/java/com/bazi/fullystocked/Controller/LoginController.java
rf08836b r5f69a70 3 3 import com.bazi.fullystocked.Models.Exceptions.InvalidUserCredentialsException; 4 4 import com.bazi.fullystocked.Models.Managers; 5 import com.bazi.fullystocked.Models.Suppliers; 5 6 import com.bazi.fullystocked.Models.User; 6 7 import com.bazi.fullystocked.Models.Workers; … … 48 49 return "redirect:/homeManager"; 49 50 } 51 else if(user instanceof Suppliers) 52 { 53 Suppliers s= (Suppliers) user; 54 request.getSession().setAttribute("user", s); 55 request.getSession().setAttribute("info",s.getSupplierinfo()); 56 request.getSession().setAttribute("number",s.getPhone()); 57 request.getSession().setAttribute("location",s.getStreet()+" бр."+ s.getStreetnumber()+", "+s.getCity()); 58 return "redirect:/homeSupplier"; 59 } 50 60 return "redirect:/home"; 51 61 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Controller/RegisterController.java
rf08836b r5f69a70 1 1 package com.bazi.fullystocked.Controller; 2 2 3 import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException; 3 4 import com.bazi.fullystocked.Models.Exceptions.UsernameAlreadyExistsException; 5 import com.bazi.fullystocked.Models.User; 4 6 import com.bazi.fullystocked.Services.AuthService; 5 7 import org.springframework.stereotype.Controller; … … 9 11 import org.springframework.web.bind.annotation.RequestMapping; 10 12 import org.springframework.web.bind.annotation.RequestParam; 13 14 import javax.servlet.http.HttpServletRequest; 11 15 12 16 @Controller … … 28 32 @RequestParam String username, 29 33 @RequestParam String email 30 ,@RequestParam String password 31 ,@RequestParam String role) 32 { 33 if(role.equals("menadzer")) 34 { 35 authService.registerManager(ime,prezime,username,email,password); 36 } 37 else if(role.equals("magacioner")) 38 { 39 authService.registerWorker(ime,prezime,username,email,password); 34 , @RequestParam String password 35 , @RequestParam String role, HttpServletRequest request) { 36 try { 37 if (role.equals("menadzer")) { 38 authService.registerManager(ime, prezime, username, email, password); 39 } else if (role.equals("magacioner")) { 40 authService.registerWorker(ime, prezime, username, email, password); 41 } else if (role.equals("dobavuvac")) { 42 User u = new User(ime, prezime, username, email, password); 43 request.getSession().setAttribute("user", u); 44 return "redirect:/register/registerSupplier"; 40 45 } 41 46 return "redirect:/login"; 47 } 48 catch (UsernameAlreadyExistsException | InvalidArgumentsException exception) 49 { 50 return "redirect:/register?error="+exception.getMessage(); 51 } 52 } 53 @GetMapping("/registerSupplier") 54 public String getRegisterSupplier(@RequestParam(required = false) String error, Model model) 55 { 56 return "registerSupplier"; 57 } 58 @PostMapping("/registerSupplier") 59 public String registerSupplier(@RequestParam String sinfo, 60 @RequestParam String phone, 61 @RequestParam String street, 62 @RequestParam String broj, 63 @RequestParam String grad,HttpServletRequest request) 64 { 65 try { 66 User u = (User) request.getSession().getAttribute("user"); 67 authService.registerSupplier(u.getFirstname(), u.getLastname(), u.getUsername(), u.getEmail(), u.getUserpassword(), sinfo, phone, street, Integer.parseInt(broj), grad); 68 request.getSession().invalidate(); 69 return "redirect:/login"; 70 } 71 catch (UsernameAlreadyExistsException | InvalidArgumentsException exception) 72 { 73 return "redirect:/register?error="+exception.getMessage(); 74 } 42 75 } 43 76 } -
FullyStocked/src/main/resources/templates/register.html
rf08836b r5f69a70 57 57 <i class="fas fa-lock fa-lg me-3 fa-fw"></i> 58 58 <div class="form-outline flex-fill mb-0"> 59 <select name="role" for="role" class="form-select" id=" tip">59 <select name="role" for="role" class="form-select" id="role"> 60 60 <option value="1" disabled>Избери тип на профил</option> 61 61 <option value="magacioner">Магационер</option> … … 63 63 <option value="menadzer">Менаџер</option> 64 64 </select> 65 <label class="form-label" for=" tip">Тип</label>65 <label class="form-label" for="role">Тип</label> 66 66 </div> 67 67 </div>
Note:
See TracChangeset
for help on using the changeset viewer.