예제 #1
0
  @POST
  @Path("/changepassword")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public JSONObject changePassword(JSONObject jsonObject) throws JSONException {

    UserDetailsModel userDetailsModel = new UserDetailsModel();

    String currentpassword = jsonObject.getString("currentpassword");

    String newpassword = jsonObject.getString("newpassword");

    JSONObject jsonobject = new JSONObject();

    HttpSession session = request.getSession(true);

    if (session.getAttribute("userId") == null) {
      return null;
    }
    Object userId = session.getAttribute("userId");

    userDetailsModel = accountDetailsService.getAccountDetails(userId);

    String encryptedCurrentPassword = JavaMD5Hash.md5(currentpassword);
    String encryptedNewPassword = JavaMD5Hash.md5(newpassword);

    if (!encryptedCurrentPassword.equals(userDetailsModel.getPassword())) {

      jsonobject.put("msg", "error_currentpassword");

      return jsonobject;

    } else {

      userDetailsModel.setPassword(encryptedNewPassword);
      System.out.println(userDetailsModel);

      boolean updatepassword = accountDetailsService.updateNewPassword(userDetailsModel);

      if (updatepassword) {

        jsonobject.put("msg", "updated");
      }

      return jsonobject;
    }
  }
예제 #2
0
  @POST
  @Path("/editdetails")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public JSONObject editUserDetails(JSONObject jsonObject) throws JSONException {

    UserDetailsModel userDetailsModel = new UserDetailsModel();

    JSONObject jsonobject = new JSONObject();

    boolean updated;

    HttpSession session = request.getSession(true);

    if (session.getAttribute("userId") == null) {
      return null;
    }
    Object userId = session.getAttribute("userId");

    userDetailsModel = accountDetailsService.getAccountDetails(userId);

    userDetailsModel.setName(jsonObject.getString("name"));

    userDetailsModel.seteMail(jsonObject.getString("email"));

    /*userDetailsModel.setUserName(jsonObject.getString("username"));*/

    updated = accountDetailsService.updateDetails(userDetailsModel);

    if (updated) {

      jsonobject.put("msg", "updated");
      return jsonobject;

    } else {

      jsonobject.put("msg", "updationerror");
      return jsonobject;
    }
  }