Changeset 5444409 for src/main/java/com
- Timestamp:
- 02/09/23 16:05:47 (23 months ago)
- Branches:
- master
- Children:
- 01a1ca6
- Parents:
- 17a2fda
- Location:
- src/main/java/com/example/moviezone
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/moviezone/config/CustomUsernamePasswordAuthenticationProvider.java
r17a2fda r5444409 2 2 3 3 4 import com.example.moviezone.model.exceptions.UserNotFoundException; 4 5 import com.example.moviezone.service.UserService; 5 6 import org.springframework.security.authentication.AuthenticationProvider; … … 35 36 36 37 UserDetails userDetails = this.userService.findByUsername(username); 38 37 39 // String realPassword = userDetails.getPassword(); 38 40 if (!Objects.equals(password,userDetails.getPassword())) { -
src/main/java/com/example/moviezone/model/Worker.java
r17a2fda r5444409 32 32 super(password, first_name, last_name, address, contact_number, username); 33 33 } 34 public Worker(String password, String first_name, String last_name, String address, String contact_number, String username,String position,String work_hours_from,String work_hours_to,Cinema cinema) { 35 super(password, first_name, last_name, address, contact_number, username); 36 this.position=position; 37 this.work_hours_from=work_hours_from; 38 this.work_hours_to=work_hours_to; 39 this.cinema=cinema; 40 } 34 41 35 42 @Override -
src/main/java/com/example/moviezone/service/CinemaService.java
r17a2fda r5444409 7 7 public interface CinemaService { 8 8 List<Cinema> findAllCinemas(); 9 Cinema findCinemaById(Integer id_cinema); 9 10 } -
src/main/java/com/example/moviezone/service/Impl/CinemaServiceImpl.java
r17a2fda r5444409 20 20 return cinemaRepository.findAll(); 21 21 } 22 23 @Override 24 public Cinema findCinemaById(Integer id_cinema) { 25 return cinemaRepository.findById(id_cinema).orElseThrow(RuntimeException::new); 26 } 22 27 } -
src/main/java/com/example/moviezone/service/Impl/UserServiceImpl.java
r17a2fda r5444409 1 1 package com.example.moviezone.service.Impl; 2 2 3 import com.example.moviezone.model.Customer; 4 import com.example.moviezone.model.Role; 5 import com.example.moviezone.model.User; 6 import com.example.moviezone.model.Worker; 3 import com.example.moviezone.model.*; 7 4 import com.example.moviezone.model.exceptions.InvalidUsernameOrPasswordException; 8 5 import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException; … … 75 72 } 76 73 74 @Override 75 public void registerWorker(String first_name, String last_name, String username, String email, String number, String password, String position, String work_hours_from, String work_hours_to, Cinema cinema) { 76 userRepository.save(new Worker(password,first_name,last_name,email,number,username,position,work_hours_from,work_hours_to,cinema)); 77 78 } 79 77 80 78 81 } -
src/main/java/com/example/moviezone/service/UserService.java
r17a2fda r5444409 1 1 package com.example.moviezone.service; 2 2 3 import com.example.moviezone.model.Cinema; 3 4 import com.example.moviezone.model.Role; 4 5 import com.example.moviezone.model.User; … … 13 14 void register(String first_name, String last_name,String username, String email, String number, String password, Role role); 14 15 User login(String username,String password); 16 void registerWorker(String first_name, String last_name, String username, String email, String number, String password, String position, String work_hours_from, String work_hours_to, Cinema cinema); 15 17 } -
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.