private void process(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   String login = request.getParameter("login");
   String password = request.getParameter("password");
   if (login != null && password != null) {
     UserService service = null;
     try {
       service = new UserService();
       User user = service.findByLoginAndPassword(login, password);
       if (user != null) {
         HttpSession session = request.getSession();
         session.setAttribute("currentUser", user);
         response.sendRedirect(request.getContextPath());
       } else {
         response.sendRedirect(
             request.getContextPath()
                 + "/login.html?message="
                 + URLEncoder.encode("Имя пользователя или пароль неопознанны", "UTF-8"));
       }
     } catch (SQLException e) {
       throw new ServletException(e);
     } finally {
       if (service != null) {
         service.close();
       }
     }
   } else {
     getServletContext().getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
   }
 }
Example #2
0
 @Override
 public void run() {
   System.out.println("notifications job running");
   List<User> users = userService.queryUsers(Filters.eq("notifications", true));
   for (User user : users) {
     String query = user.getNotificationQuery();
     query = query + "&createdOn[$gt]=" + user.getLastNotificationAt();
     List<Document> documents = adService.queryAds(query);
     if (!documents.isEmpty()) {
       List<BaseAd> adsList = adService.getListAs(BaseAd.class, documents);
       twilioService.sendSMS(user.getMobile(), "New ads for your query");
       user.setLastNotificationAt(ZonedDateTime.now().toEpochSecond());
       userService.updateUser(user);
     }
   }
 }
Example #3
0
  private Representation mono() throws Exception {
    String sessionHash = getQuery().getValues("session_hash");

    User user = mUserService.getCurrentUser(sessionHash);

    return new JacksonRepresentation<UserPrivateRepresentation>(
        new UserPrivateRepresentation(user));
  }
Example #4
0
 /**
  * 获取用户自己的信息
  *
  * @param param
  * @return
  */
 @RequestMapping(
     value = "/myInfo.ajax",
     method = RequestMethod.POST,
     consumes = "application/json")
 @ResponseBody
 public Map myInfo(@RequestBody Map param) {
   return initResult(true, userService.myInfo(param));
 }
Example #5
0
 public void sendPassword() {
   try {
     userService.sendPassword();
   } catch (PostException e) {
     FacesContext.getCurrentInstance()
         .addMessage(
             null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()));
   }
 }
Example #6
0
 private UserInfo FindUserInfo(String SQL, Integer userId) {
   // TODO Auto-generated method stub
   List<Object> list =
       userService
           .getRepository()
           .getImply()
           .searchList(SQL, new Object[] {userId}, new BeanPropertyRowMapper(UserInfo.class));
   if (list != null && list.size() > 0) return (UserInfo) list.get(0);
   return null;
 }
Example #7
0
 public void login() throws IOException {
   try {
     current = userService.find(username, password);
     FacesContext.getCurrentInstance().getExternalContext().redirect("pages/read.jsf");
   } catch (PostException e) {
     FacesContext.getCurrentInstance()
         .addMessage(
             null, new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()));
   }
 }
Example #8
0
 private Degree Find_Degree(Integer user) {
   // TODO Auto-generated method stub
   List<Object> list =
       userService
           .getRepository()
           .getImply()
           .searchList(
               sql.SEARCH_DEGREE, new Object[] {user}, new BeanPropertyRowMapper(Degree.class));
   if (list != null && list.size() > 0) return (Degree) list.get(0);
   return null;
 }
  @RequestMapping(value = "/UserLoginRequest", method = RequestMethod.POST)
  public @ResponseBody UserLoginResponse userLoginRequest(
      @RequestBody UserLoginRequest request, HttpServletRequest req) {
    UserLoginResponse response = userService.userLoginRequest(request);

    if (response.isIsAuthenicated()) {
      req.getSession().setAttribute("LOGGEDIN_USER", response.getUser());
    }

    return response;
  }
Example #10
0
  private Representation multi() throws Exception {
    String sessionHash = getQuery().getValues("session_hash");
    String search = getQuery().getValues("search");

    List<User> users = mUserService.getUsers(sessionHash, search);
    List<UserPublicRepresentation> usersResponse = new ArrayList<UserPublicRepresentation>();
    for (User each : users) {
      usersResponse.add(new UserPublicRepresentation(each));
    }

    return new JacksonRepresentation<List<UserPublicRepresentation>>(usersResponse);
  }
  @RequestMapping(value = "/login", method = RequestMethod.POST)
  public String login(
      @RequestParam(value = "username") String username,
      @RequestParam(value = "password") String password) {
    System.out.println("username:"******",password:"******"usernotexist";
    else if (user.getPassword().equals(password)) return "loginsuccess";
    else return "loginfail";
  }
  @RequestMapping(value = "/GetUserListByRoleRequest/{role}", method = RequestMethod.GET)
  public @ResponseBody List<User> getUserListByRoleRequest(@PathVariable("role") String role) {

    List<User> userList = null;
    try {
      userList = userService.getUserListByRoleRequest(role);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return userList;
  }
  @RequestMapping(value = "/GetUserListRequest", method = RequestMethod.GET)
  public @ResponseBody List<User> getUserListRequest() {

    List<User> userList = null;
    try {
      userList = userService.getUserListRequest();

    } catch (Exception e) {
      e.printStackTrace();
    }

    return userList;
  }
  @RequestMapping(value = "/GetUserByUsernameRequest/{username}", method = RequestMethod.GET)
  public @ResponseBody User getUserByUsernameRequest(@PathVariable("username") String username) {

    User user = null;
    try {
      user = userService.getUserByUsernameRequest(username);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return user;
  }
Example #15
0
 /**
  * 修改用户自己的资料
  *
  * @param param
  * @return
  */
 @RequestMapping(
     value = "/modifyInfo.ajax",
     method = RequestMethod.POST,
     consumes = "application/json")
 @ResponseBody
 public Map modifyInfo(@RequestBody Map param) {
   try {
     return initResult(true, userService.modifyInfo(param));
   } catch (Exception e) {
     e.printStackTrace();
     return initResult(false, e.getMessage(), "");
   }
 }
Example #16
0
 @ResponseBody
 @RequestMapping("SearchOtherMesg")
 public List searchOtherMesg(@RequestParam("type") Integer type, HttpSession session) {
   RowMapper<other_infos> mapper = new BeanPropertyRowMapper<>(other_infos.class);
   List list =
       userService
           .getRepository()
           .getImply()
           .searchList(
               sql.SEARCH_OTHER_INFOS,
               new Object[] {(Integer) session.getAttribute("userID"), type},
               mapper);
   return list;
 }
Example #17
0
 /**
  * 上传用户头像,一次共大中小三张
  *
  * @param param
  * @param request
  * @return
  */
 @RequestMapping(
     value = "/modifyUserhead.ajax",
     method = RequestMethod.POST,
     consumes = "application/json")
 @ResponseBody
 public Map modifyUserhead(@RequestBody Map param, HttpServletRequest request) {
   try {
     String realPath = request.getSession().getServletContext().getRealPath("/");
     param.put("realPath", realPath);
     return initResult(true, userService.modifyUserhead(param));
   } catch (Exception e) {
     e.printStackTrace();
     return initResult(false, e.getMessage(), "");
   }
 }
  @RequestMapping(
      value = "/GetVolunteerListByOrganizationRequest/{organizationName}",
      method = RequestMethod.GET)
  public @ResponseBody List<User> getVolunteerListByOrganizationRequest(
      @PathVariable("organizationName") String organizationName) {

    List<User> userList = null;
    try {
      userList = userService.getVolunteerListByOrganizationRequest(organizationName);

    } catch (Exception e) {
      e.printStackTrace();
    }

    return userList;
  }
Example #19
0
  private Representation editSimpleData(Form form) {
    String sessionHash = form.getFirstValue("session_hash");
    String fullName = form.getFirstValue("full_name");
    String email = form.getFirstValue("email");

    try {
      mUserService.editSimpleData(sessionHash, fullName, email);

      return new JacksonRepresentation<Status>(StatusFactory.ok());
    } catch (BadAuthenticationException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientUnauthorized(e.getMessage()));
    } catch (IllegalArgumentException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientBadRequest(e.getMessage()));
    } catch (Exception e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
    }
  }
Example #20
0
  private Representation editPasswordData(Form form) {
    String sessionHash = form.getFirstValue("session_hash");
    String oldPassword = form.getFirstValue("old_password");
    String newPassword = form.getFirstValue("new_password");

    try {
      mUserService.editPassword(sessionHash, oldPassword, newPassword);

      return new JacksonRepresentation<Status>(StatusFactory.ok());
    } catch (BadAuthenticationException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientUnauthorized(e.getMessage()));
    } catch (IllegalArgumentException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientBadRequest(e.getMessage()));
    } catch (Exception e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
    }
  }
Example #21
0
  @Post
  public Representation createUser(Representation entity) {
    Form form = new Form(entity);
    try {
      String fullName = form.getFirstValue("full_name");
      String password = form.getFirstValue("password");
      String hostIp = getClientInfo().getAddress();
      String hostAgent = getClientInfo().getAgent();

      Session session = mUserService.createUser(mLogin, fullName, password, hostIp, hostAgent);

      return new JacksonRepresentation<SessionRepresentation>(new SessionRepresentation(session));
    } catch (IllegalArgumentException e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.clientBadRequest(e.getMessage()));
    } catch (Exception e) {
      System.err.println(StatusFactory.getErrorMessage(e));
      return new JacksonRepresentation<Status>(StatusFactory.serverInternalError());
    }
  }
 @RequestMapping(value = "/SuspendUserRequest/{id}", method = RequestMethod.PUT)
 public @ResponseBody SuspendUserResponse suspendUserRequest(@PathVariable("id") String id) {
   return userService.suspendUserRequest(id);
 }
 @RequestMapping(value = "/ChangePasswordRequest", method = RequestMethod.PUT)
 public @ResponseBody ChangePasswordResponse changePasswordRequest(
     @RequestBody ChangePasswordRequest request) {
   return userService.changePasswordRequest(request);
 }
 @RequestMapping(value = "/ActivateUserRequest/{id}", method = RequestMethod.PUT)
 public @ResponseBody ActivateUserResponse activateUserRequest(@PathVariable("id") String id) {
   return userService.activateUserRequest(id);
 }
 @RequestMapping(value = "/UpdateUserRequest", method = RequestMethod.PUT)
 public @ResponseBody UpdateUserResponse userLoginRequest(@RequestBody User user) {
   return userService.updateUserRequest(user);
 }
Example #26
0
 public Role getMyRole() {
   return getRoleById(userService.getUserByLogin().getRoleId());
 }
 @RequestMapping(value = "/ResetPasswordRequest", method = RequestMethod.PUT)
 public @ResponseBody ResetPasswordResponse resetPasswordRequest(
     @RequestBody ResetPasswordRequest request) {
   return userService.resetPasswordRequest(request);
 }
 @RequestMapping(value = "/VerifyResetPasswordTokenRequest/{token}", method = RequestMethod.GET)
 public @ResponseBody VerifyResetPasswordTokenResponse verifyResetPasswordTokenRequest(
     @PathVariable("token") String token) {
   return userService.verifyResetPasswordTokenRequest(token);
 }
 @RequestMapping(value = "/DeleteUserRequest/{id}", method = RequestMethod.DELETE)
 public @ResponseBody DeleteUserResponse deleteUserRequest(@PathVariable("id") String id) {
   return userService.deleteUserRequest(id);
 }
 @RequestMapping(value = "/CreatePendingResetPasswordRequest", method = RequestMethod.POST)
 public @ResponseBody CreatePendingResetPasswordResponse createPendingResetPasswordRequest(
     @RequestBody CreatePendingResetPasswordRequest request) {
   return userService.createPendingResetPasswordRequest(request);
 }