コード例 #1
0
  @SuppressWarnings("unchecked")
  @ResponseBody
  @RequestMapping(
      value = "/signup",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  public String signup(@RequestBody Login login, HttpSession session) {
    log.info("signup: " + login.getEmail());

    Login entityLogin = loginService.get(login.getEmail());
    if (entityLogin == null) {
      entityLogin = loginService.signup(login);
      Account entityAccount = accountService.findLoginAccount(entityLogin);
      session.setAttribute(ConstantsOfSystem.USER_SESSION_KEY, entityLogin);
      session.setAttribute(ConstantsOfSystem.USER_ACCOUNT_SESSION_KEY, entityAccount);

      JSONObject json = new JSONObject();
      json.put("message", "success");
      return json.toJSONString();
    } else {
      JSONObject json = new JSONObject();
      json.put(
          "message",
          "This email: " + login.getEmail() + ". is already registered \nPlease try another email");
      return json.toJSONString();
    }
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  @ResponseBody
  @RequestMapping(
      value = "/signin",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  public String signin(@RequestBody Login login, HttpSession session) {
    log.info("signin: " + login.getEmail());
    Login entityLogin = loginService.get(login.getEmail());
    Account entityAccount = accountService.findLoginAccount(entityLogin);

    session.setAttribute(ConstantsOfSystem.USER_SESSION_KEY, entityLogin);
    session.setAttribute(ConstantsOfSystem.USER_ACCOUNT_SESSION_KEY, entityAccount);
    if (entityLogin != null && login.getPassword().equals(entityLogin.getPassword())) {
      JSONObject json = new JSONObject();
      json.put("message", "success");
      return json.toJSONString();
    } else {
      JSONObject json = new JSONObject();
      json.put("message", "Incorrect password. \nPlease try again");
      return json.toJSONString();
    }
  }