Changeset 5444409 for src/main/java/com/example/moviezone/web
- Timestamp:
- 02/09/23 16:05:47 (21 months ago)
- Branches:
- master
- Children:
- 01a1ca6
- Parents:
- 17a2fda
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/web/HomeController.java
r17a2fda r5444409 17 17 18 18 import javax.servlet.http.HttpServletRequest; 19 import javax.servlet.http.HttpServletResponse; 19 20 import javax.servlet.http.HttpSession; 20 21 import javax.transaction.Transactional; 22 import java.io.IOException; 21 23 import java.time.LocalDate; 22 24 import java.util.LinkedList; 23 25 import java.util.List; 26 import java.util.Objects; 24 27 import java.util.stream.Collectors; 25 28 … … 151 154 model.addAttribute("hasError", true); 152 155 model.addAttribute("error", e.getMessage()); 153 return " /login";154 } 155 156 } 157 158 @PostMapping( )159 public Stringregister(@RequestParam String username,156 return "login"; 157 } 158 159 } 160 161 @PostMapping("/register") 162 public void register(@RequestParam String username, 160 163 @RequestParam String first_name, 161 164 @RequestParam String last_name, … … 164 167 @RequestParam String email, 165 168 @RequestParam String number, 166 @RequestParam Role role) 167 { 169 @RequestParam Role role,HttpServletResponse response, HttpSession session) throws IOException { 170 171 System.out.println(username + first_name+ last_name + password + repeatedPassword + email + number + role); 172 if(role.equals(Role.ROLE_ADMIN)){ 173 session.setAttribute("username", username); 174 session.setAttribute("first_name", first_name); 175 session.setAttribute("last_name", last_name); 176 session.setAttribute("password", password); 177 session.setAttribute("repeatedPassword", repeatedPassword); 178 session.setAttribute("email", email); 179 session.setAttribute("number", number); 180 response.sendRedirect("/registerWorker"); 181 } 182 else { 183 try { 184 userService.register(first_name,last_name,username,email,number,password,role); 185 response.sendRedirect( "redirect:/login"); 186 }catch (PasswordsDoNotMatchException exception) 187 { 188 // return "redirect:/register?error=" + exception.getMessage(); 189 } 190 } 191 192 } 193 @GetMapping("/registerWorker") 194 public String getRegisterWorkerPage(Model model){ 195 model.addAttribute("cinemas",cinemaService.findAllCinemas()); 196 model.addAttribute("bodyContent","registerWorker"); 197 return "master-template"; 198 } 199 @PostMapping("/finishRegister") 200 public void handleWorkerRegister(Model model, HttpServletResponse response, HttpSession session, 201 @RequestParam String position, @RequestParam String work_hours_from, 202 @RequestParam String work_hours_to,@RequestParam Integer id_cinema){ 203 System.out.println("here?"); 204 String username = (String) session.getAttribute("username"); 205 String first_name = (String) session.getAttribute("first_name"); 206 String last_name = (String) session.getAttribute("last_name"); 207 String password = (String) session.getAttribute("password"); 208 String email = (String) session.getAttribute("email"); 209 String number = (String) session.getAttribute("number"); 210 Cinema cinema=cinemaService.findCinemaById(id_cinema); 211 userService.registerWorker(first_name,last_name,username,email,number,password,position,work_hours_from,work_hours_to,cinema); 168 212 try { 169 userService.register(first_name,last_name,username,email,number,password,role); 170 return "redirect:/login"; 171 }catch (PasswordsDoNotMatchException exception) 172 { 173 return "redirect:/register?error=" + exception.getMessage(); 174 } 175 176 } 177 213 response.sendRedirect("/login"); 214 } catch (IOException e) { 215 throw new RuntimeException(e); 216 } 217 } 178 218 179 219 @GetMapping("/films")
Note:
See TracChangeset
for help on using the changeset viewer.