Changeset 5444409
- Timestamp:
- 02/09/23 16:05:47 (23 months ago)
- Branches:
- master
- Children:
- 01a1ca6
- Parents:
- 17a2fda
- Location:
- src/main
- Files:
-
- 1 added
- 9 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") -
src/main/resources/templates/login.html
r17a2fda r5444409 1 1 <div class="container"> 2 <h1 th:if="${hasError}" th:text="${error}"></h1> 3 </div> 2 4 <div> 3 5 <form th:method="POST" th:action="@{/login}"> -
src/main/resources/templates/register.html
r17a2fda r5444409 4 4 <div class="container"> 5 5 <form class="form-signin mt-xl-5" method="post" action="/register"> 6 <h2 class="form-signin-heading" >Register</h2>6 <h2 class="form-signin-heading" style="color: white">Регистрација</h2> 7 7 <p> 8 <label for="username" class="sr-only" >Корисничко име</label>8 <label for="username" class="sr-only" style="color: white">Корисничко име</label> 9 9 <input type="text" id="username" name="username" class="form-control" placeholder="Корисничко име" required="" 10 10 autofocus=""> 11 11 </p> 12 12 <p> 13 <label for="password" class="sr-only" >Лозинка</label>13 <label for="password" class="sr-only" style="color: white">Лозинка</label> 14 14 <input type="password" id="password" name="password" class="form-control" placeholder="Лозинка" 15 15 required=""> 16 16 </p> 17 17 <p> 18 <label for="repeatedPassword" class="sr-only" >Повтори лозинка</label>18 <label for="repeatedPassword" class="sr-only" style="color: white">Повтори лозинка</label> 19 19 <input type="password" id="repeatedPassword" name="repeatedPassword" class="form-control" 20 20 placeholder="Повтори лозинка" required=""> 21 21 </p> 22 22 <p> 23 <label for="first_name" class="sr-only" >Име</label>23 <label for="first_name" class="sr-only" style="color: white">Име</label> 24 24 <input type="text" id="first_name" name="first_name" class="form-control" placeholder="Име" required="" autofocus=""> 25 25 </p> 26 26 <p> 27 <label for="last_name" class="sr-only" >Презиме</label>27 <label for="last_name" class="sr-only" style="color: white">Презиме</label> 28 28 <input type="text" id="last_name" name="last_name" class="form-control" placeholder="Презиме" required="" 29 29 autofocus=""> 30 30 </p> 31 31 <p> 32 <label for="number" class="sr-only">Телефонски број</label> 32 <label for="last_name" class="sr-only" style="color: white">Е-пошта</label> 33 <input type="text" id="email" name="email" class="form-control" placeholder="Е-пошта" required="" 34 autofocus=""> 35 </p> 36 <p> 37 <label for="number" class="sr-only" style="color: white">Телефонски број</label> 33 38 <input type="text" id="number" name="number" class="form-control" placeholder="Телефонски број" required="" 34 39 autofocus=""> … … 37 42 <div class="form-check form-check-inline"> 38 43 <input class="form-check-input" name="role" type="radio" id="ROLE_ADMIN" value="ROLE_ADMIN"> 39 <label class="form-check-label" for="ROLE_ADMIN" >ROLE_ADMIN</label>44 <label class="form-check-label" for="ROLE_ADMIN" style="color: white">ROLE_ADMIN</label> 40 45 </div> 41 46 <div class="form-check form-check-inline"> 42 47 <input class="form-check-input" name="role" type="radio" id="ROLE_USER" value="ROLE_USER"> 43 <label class="form-check-label" for="ROLE_USER" >ROLE_USER</label>48 <label class="form-check-label" for="ROLE_USER" style="color: white">ROLE_USER</label> 44 49 </div> 45 50 </p>
Note:
See TracChangeset
for help on using the changeset viewer.