Exemplo n.º 1
0
  /**
   * Resets forgotten password.
   *
   * <p>Renders the response with a json object, for example,
   *
   * <pre>
   * {
   *     "isLoggedIn": boolean,
   *     "msg": "" // optional, exists if isLoggedIn equals to false
   * }
   * </pre>
   *
   * @param context the specified context
   */
  @RequestProcessing(value = "/reset", method = HTTPRequestMethod.POST)
  public void reset(final HTTPRequestContext context) {
    final HttpServletRequest request = context.getRequest();
    final JSONRenderer renderer = new JSONRenderer();

    context.setRenderer(renderer);
    final JSONObject jsonObject = new JSONObject();

    renderer.setJSONObject(jsonObject);

    try {
      final JSONObject requestJSONObject;

      requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
      final String userEmail = requestJSONObject.getString(User.USER_EMAIL);
      final String newPwd = requestJSONObject.getString("newPwd");
      final JSONObject user = userQueryService.getUserByEmail(userEmail);

      user.put(User.USER_PASSWORD, newPwd);
      userMgmtService.updateUser(user);
      LOGGER.log(Level.DEBUG, "[{0}]'s password updated successfully.", new Object[] {userEmail});

      jsonObject.put("succeed", true);
      jsonObject.put("to", Latkes.getServePath() + "/login?from=reset");
      jsonObject.put(Keys.MSG, langPropsService.get("resetPwdSuccessMsg"));
    } catch (final Exception e) {
      LOGGER.log(Level.ERROR, e.getMessage(), e);
    }
  }
Exemplo n.º 2
0
  /**
   * Shows login page.
   *
   * @param context the specified context
   * @throws Exception exception
   */
  @RequestProcessing(value = "/login", method = HTTPRequestMethod.GET)
  public void showLogin(final HTTPRequestContext context) throws Exception {
    final HttpServletRequest request = context.getRequest();

    String destinationURL = request.getParameter(Common.GOTO);

    if (Strings.isEmptyOrNull(destinationURL)) {
      destinationURL = Latkes.getServePath() + Common.ADMIN_INDEX_URI;
    }

    final HttpServletResponse response = context.getResponse();

    userMgmtService.tryLogInWithCookie(request, response);

    if (null != userService.getCurrentUser(request)) { // User has already logged in
      response.sendRedirect(destinationURL);

      return;
    }

    renderPage(context, "login.ftl", destinationURL, request);
  }