|
10 | 10 | import java.io.IOException;
|
11 | 11 | import java.util.HashMap;
|
12 | 12 | import java.util.Map;
|
| 13 | + |
| 14 | +import org.jetbrains.annotations.NotNull; |
13 | 15 | import org.json.JSONObject;
|
14 | 16 |
|
15 | 17 | public class RegisterServlet extends HttpServlet {
|
| 18 | + public static final String PAGE_URL = "/register"; |
| 19 | + |
| 20 | + @NotNull |
16 | 21 | private AccountService accountService;
|
17 | 22 |
|
18 |
| - public RegisterServlet(AccountService accountService) { |
| 23 | + public RegisterServlet(@NotNull AccountService accountService) { |
19 | 24 | this.accountService = accountService;
|
20 | 25 | }
|
21 | 26 |
|
22 |
| - public void doGet(HttpServletRequest request, |
23 |
| - HttpServletResponse response) throws ServletException, IOException { |
24 |
| - |
25 |
| - } |
26 |
| - |
| 27 | + @Override |
27 | 28 | public void doPost(HttpServletRequest request,
|
28 | 29 | HttpServletResponse response) throws ServletException, IOException {
|
29 | 30 |
|
30 | 31 | String name = request.getParameter("login");
|
31 | 32 | String email = request.getParameter("email");
|
32 | 33 | String password = request.getParameter("password");
|
33 | 34 |
|
| 35 | + |
34 | 36 | Map<String, Object> objResponse = new HashMap<>();
|
35 |
| - objResponse.put("signup", false); |
36 |
| - objResponse.put("name", name); |
| 37 | + objResponse.put("signup", false); ///// что возвращать???? true -&????? false - ????? |
| 38 | + objResponse.put("login", "notexists"); /////!!!!!!!!!!!!!! |
| 39 | + objResponse.put("email", true); |
| 40 | + objResponse.put("password", true); |
| 41 | + |
| 42 | + boolean isOk = true; |
37 | 43 |
|
38 |
| - if (accountService.addUser(name, new UserProfile(name, password, email))) { |
39 |
| - objResponse.replace("signup", true); |
| 44 | + if (!accountService.validationName(name)) { |
| 45 | + //objResponse.put("login", "exists"); |
| 46 | + isOk = false; |
| 47 | + } if (!accountService.validationEmail(email)) { |
| 48 | + objResponse.put("email", false); |
| 49 | + isOk = false; |
| 50 | + } if (!accountService.validationPassword(password)) { |
| 51 | + objResponse.put("password", false); |
| 52 | + isOk = false; |
40 | 53 | }
|
| 54 | + |
| 55 | + if (isOk) { |
| 56 | + if (accountService.singUp(new UserProfile(name, password, email))) { |
| 57 | + objResponse.put("signup", true); |
| 58 | + } else { |
| 59 | + objResponse.put("login", "exists"); |
| 60 | + } |
| 61 | + } |
| 62 | + |
41 | 63 | JSONObject jsonResponse = new JSONObject(objResponse);
|
42 | 64 | response.setContentType("application/json");
|
43 | 65 | response.setCharacterEncoding("UTF-8");
|
|
0 commit comments