// 根据编号获得团购
 @Action(
     value = "searchGroupon",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, type = "json")})
 public String searchGroupon() {
   User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
   // 获得这个学校所有的团购项目
   if (groupon.getName() != null) {
     //            name = CommonUtil.getSortString(name.trim());
     name = "%" + groupon.getName() + "%";
   }
   List<Groupon> groupons =
       grouponService.effectiveGroupons(sessionUser.getSchool().getId(), page, name);
   List<GrouponBean> grouponBeanList = new ArrayList<>();
   for (int i = 0; i < groupons.size(); i++) {
     GrouponBean bean = new GrouponBean();
     bean.setId(groupons.get(i).getId());
     bean.setName(groupons.get(i).getName());
     bean.setClassNo(groupons.get(i).getClassNo());
     bean.setTel(groupons.get(i).getTel());
     bean.setEndTime(CommonUtil.dateToString(groupons.get(i).getEndTime()));
     grouponBeanList.add(bean);
   }
   String json = JSONArray.fromObject(grouponBeanList).toString();
   PrintWriter writer = CommonUtil.getJsonPrintWriter(ServletActionContext.getResponse());
   writer.write(json);
   writer.flush();
   writer.close();
   return SUCCESS;
 }
예제 #2
0
  public List<User> getAll() {

    try {

      connection = connectionFactory.getConnection();

      String sql = "SELECT * FROM eeproject.Login;";
      Statement statement = connection.createStatement();

      ResultSet rs = statement.executeQuery(sql);

      while (rs.next()) {
        User user = new User();
        user.setUsername(rs.getString(1));
        user.setPassword(rs.getString(2));

        LOG.log(Level.INFO, "User: "******"List size: " + list.size());
      }

    } catch (SQLException ex) {
      LOG.log(Level.SEVERE, null, ex);
    } finally {
      connectionFactory.closeConnection();
      LOG.log(Level.INFO, "Connection closed");
    }

    return list;
  }
예제 #3
0
 public User selectByPrimaryKey(String userId) {
   User user = this.userDao.selectByPrimaryKey(userId);
   if (user != null) {
     user.setBirthdayStr(DateUtils.formatDate2Str(user.getBirthday(), "yyyy-MM-dd"));
   }
   return user;
 }
  // Sending request------------------------------------------------------------------
  @RequestMapping(value = "/sendRequest", method = RequestMethod.GET)
  public ModelAndView sendRequest(@RequestParam int teamId) {

    ModelAndView result;
    Collection<Team> teams;
    Collection<Team> teamsRequested = new ArrayList<Team>();
    Team team;
    Boolean showSend = true;
    Collection<RequestTeam> requestTeam;
    User principal;

    principal = userService.findByPrincipal();
    team = teamService.findOne(teamId);
    requestTeamService.sendRequest(teamId);
    teams = teamService.findAllOtherUser(principal.getId());
    requestTeam = requestTeamService.findAllRequestSendFromUser(principal.getId());

    for (RequestTeam r : requestTeam) {
      teamsRequested.add(r.getTeam());
    }

    result = new ModelAndView("team/list");

    result.addObject("teams", teams);
    result.addObject("teamsRequested", teamsRequested);
    result.addObject("showSend", showSend);
    result.addObject("requestURI", "team/user/listAllTeams.do");

    return result;
  }
예제 #5
0
 public int countByCriteria(User paramUser) {
   if ("1".equals(SessionUtils.getUserRole())) paramUser.setRole("'2','3'");
   else {
     paramUser.setRole("'3'");
   }
   int count = this.userDao.countByCriteria(paramUser);
   return count;
 }
예제 #6
0
 public void update(String userIds, Map map)
     throws IllegalAccessException, InvocationTargetException {
   User paramUser = new User();
   BeanUtils.populate(paramUser, map);
   String[] userIdArr = userIds.split(",");
   for (int i = 0; i < userIdArr.length; i++) {
     paramUser.setUserId(userIdArr[i]);
     update(paramUser);
   }
 }
예제 #7
0
  public Collection<Team> findAllTeamsByUserId() {
    Collection<Team> all;
    User user;
    int userId;

    user = userService.findByPrincipal();
    userId = user.getId();
    all = teamRepository.findAllTeamsByUserId(userId);

    return all;
  }
 // 1 进入团购的页面
 @Action(
     value = "grouponPage",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, location = "/userPages/groupon.jsp")})
 public String grouponPage() {
   User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
   // 获得这个学校所有的团购项目
   List<Groupon> groupons =
       grouponService.effectiveGroupons(sessionUser.getSchool().getId(), page, null);
   ServletActionContext.getContext().getValueStack().set("groupons", groupons);
   return SUCCESS;
 }
예제 #9
0
  public void DisjoinTeam(Team team) {

    User user;

    user = userService.findByPrincipal();

    team.getUsers().remove(user);
    user.getTeams().remove(team);

    save(team);
    userService.save(user);
  }
예제 #10
0
  public void joinTeam(Team team, RequestTeam requestTeam) {

    User user;

    user = requestTeam.getUser();

    requestTeam.setRequest(true);
    team.getUsers().add(user);
    user.getTeams().add(team);

    requestTeamService.save(requestTeam);
    save(team);
    userService.save(user);
  }
예제 #11
0
파일: UserDao.java 프로젝트: yhpdev/NewOS
 /**
  * 查询 用户名 密码
  *
  * @param user
  */
 public User selectUsPs(User user) {
   QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());
   String sql = "SELECT * FROM user WHERE username = ? AND password = ?";
   try {
     User query =
         queryRunner.query(
             sql,
             new BeanHandler<User>(User.class),
             new Object[] {user.getUsername(), user.getPassword()});
     return query;
   } catch (SQLException e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #12
0
  private User getUserWithMetaByUserId(String userId) {
    User currentUser = selectByPrimaryKey(userId);

    UserMeta userMeta = new UserMeta();
    userMeta.setUserId(userId);
    List<UserMeta> userMetaList = this.userMetaService.selectByCriteria(userMeta);
    Map userMetaMap = new HashMap();
    if (userMetaList != null) {
      for (UserMeta temp : userMetaList) {
        userMetaMap.put(temp.getMetaKey(), temp.getMetaValue());
      }
      currentUser.setUserMeta(userMetaMap);
    }
    return currentUser;
  }
 // 1 团购增删改查
 @Action(
     value = "grouponOpePage",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, location = "/userPages/grouponindex.jsp")})
 public String grouponOpePage() {
   User sessionUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
   Groupon findGroupon = null;
   if (groupon.getId() != null && groupon.getId() != 0) {
     findGroupon = grouponService.getGrouponDetail(groupon.getId());
     if (findGroupon == null && !findGroupon.getUser().getId().equals(sessionUser.getId())) {
       findGroupon = null;
     }
   }
   ServletActionContext.getContext().getValueStack().set("groupon", findGroupon);
   return SUCCESS;
 }
예제 #14
0
  public Team save(Team team) {
    Team result;
    User principal;

    principal = userService.findByPrincipal();

    result = teamRepository.save(team);

    if (team.getId() == 0) {
      principal.getTeamsCreated().add(result);
      principal.getTeams().add(result);
    }

    userService.save(principal);

    return result;
  }
  // Listing------------------------------------------------------------------
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  public ModelAndView list() {

    ModelAndView result;
    Collection<RequestTeam> requestTeams;
    User principal;

    principal = userService.findByPrincipal();
    requestTeams = requestTeamService.findAllRequestTeamUser(principal.getId());

    result = new ModelAndView("requestTeam/list");

    result.addObject("requestTeams", requestTeams);
    result.addObject("requestURI", "requestTeam/user/list.do");

    return result;
  }
예제 #16
0
  @Override
  public boolean isValidUsernameAndPassword(String username, String password) {
    list = getAll();
    if (username != null || password != null) {
      LOG.log(Level.INFO, " Login: "******" Password:"******" List size: " + list.size());
      for (int i = 0; i < list.size(); i++) {

        User user = list.get(i);
        LOG.log(Level.INFO, " Users: " + user.toString());
        if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
          return true;
        }
      }
    }
    return false;
  }
예제 #17
0
  public void delete(Team team) {

    User captain;

    captain = team.getCaptain();

    for (Tournament t : team.getTournaments()) {
      Assert.isTrue(t.getFinishMoment().before(new Date()));
    }

    captain.getTeams().remove(team);
    captain.getTeamsCreated().remove(team);

    Assert.notNull(team);
    checkPrincipal(team);
    teamRepository.delete(team);

    userService.save(captain);
  }
예제 #18
0
  public JSONObject update(Map map) throws Exception {
    boolean isSuccess = true;
    String message = "";

    User paramUser = new User();
    BeanUtils.populate(paramUser, map);
    paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd"));

    List<User> userList = selectByCriteria(new User());
    if (userList != null) {
      for (User user : userList) {
        if ((paramUser.getEmail().equals(user.getEmail()))
            && (!paramUser.getUserId().equals(user.getUserId()))) {
          isSuccess = false;
          message = "邮箱已被使用.";
          break;
        }
      }
    }

    if (isSuccess) {
      update(paramUser);

      Map userMetaMap = new HashMap();
      userMetaMap.put("theme", (String) map.get("theme"));
      userMetaMap.put("homePage", (String) map.get("homePage"));
      userMetaMap.put("showTodo", (String) map.get("showTodo"));
      userMetaMap.put("showNote", (String) map.get("showNote"));
      userMetaMap.put("showPicture", (String) map.get("showPicture"));
      userMetaMap.put("showAccount", (String) map.get("showAccount"));
      userMetaMap.put("showFeed", (String) map.get("showFeed"));
      userMetaMap.put("showDocument", (String) map.get("showDocument"));
      userMetaMap.put("showSystem", (String) map.get("showSystem"));
      this.userMetaService.updateByUserIdAndMetaKey(paramUser.getUserId(), userMetaMap);

      ((HttpSession) map.get("session")).removeAttribute("CLIENT_SESSION");

      User currentUser = getUserWithMetaByUserId((String) map.get("userId"));

      ClientSession cs = SessionUtils.getClientSession(currentUser);
      ((HttpSession) map.get("session")).setAttribute("CLIENT_SESSION", cs);
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", message);
    return res;
  }
예제 #19
0
 public List<User> selectByCriteria(User paramUser) {
   List userList = this.userDao.selectByCriteria(paramUser);
   List results = new ArrayList();
   if (userList != null) {
     for (int i = 0; i < userList.size(); i++) {
       User user = (User) userList.get(i);
       user.setBirthdayStr(DateUtils.formatDate2Str(user.getBirthday(), "yyyy-MM-dd"));
       user.setSex((String) Constants.SEX_MAP.get(user.getSex()));
       user.setStatus((String) Constants.USER_STATUS_MAP.get(user.getStatus()));
       user.setCreateDateStr(
           DateUtils.formatDate2Str(user.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
       results.add(user);
     }
   }
   return results;
 }
예제 #20
0
  public JSONObject resetPwd(Map map) throws Exception {
    boolean isSuccess = true;
    String message = "";

    String userId = (String) map.get("userId");

    String email = (String) map.get("email");

    String verifyCode = (String) map.get("verifyCode");
    String verifyCodeInSession = (String) map.get("verifyCodeInSession");

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      message = "验证码错误.";
    }

    List userList = null;
    if ((StringUtils.isNotEmpty(userId)) && (StringUtils.isNotEmpty(email))) {
      User paramUser = new User();
      paramUser.setUserId(userId);
      paramUser.setEmail(email);
      userList = selectByCriteria(paramUser);
    }
    if ((userList == null) || (userList.size() != 1)) {
      isSuccess = false;
      message = "用户名或邮箱错误.";
    }

    if (isSuccess) {
      User user = (User) userList.get(0);

      String newPassword = RandomStringUtils.random(6, true, true);

      String title = "密码重置";
      String content = user.getUserId() + ",您好:<br/>您的新密码是:" + newPassword;
      boolean rs = ServletHelp.sendEmail(email, title, content);
      if (rs) {
        User paramUser = new User();
        paramUser.setUserId(userId);
        paramUser.setPassword(MD5Utils.getMD5String(newPassword));
        update(paramUser);
      } else {
        isSuccess = false;
        message = "邮件发送失败.";
      }
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", message);
    return res;
  }
예제 #21
0
  /**
   * Handles the HTTP <code>POST</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException If a servlet-specific error occurs
   * @throws IOException If an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // get Parameters from jsp page.
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    // authorize user from database, if exist, store it in session.
    User userObj = UserDAO.getUser(username, password);
    if (userObj != null) {
      HttpSession session = request.getSession(true);
      session.setAttribute("username", username);
      session.setAttribute("userId", userObj.getUserId());
      RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/JSP/home.jsp");
      dispatcher.forward(request, response);
    } else {
      response.sendRedirect("invalid.jsp");
      // redirect user to invalid.jsp page if the input does not match
    }
  }
예제 #22
0
  public Map login(String userId, String password) throws Exception {
    Map res = new HashMap();
    res.put("success", Boolean.valueOf(true));

    User paramUser = new User();
    paramUser.setUserId(userId);
    paramUser.setPassword(MD5Utils.getMD5String(password));
    List userList = this.userDao.selectByCriteria(paramUser);
    if ((userList == null) || (userList.size() != 1)) {
      res.put("success", Boolean.valueOf(false));
      res.put("message", "用户名或密码错误.");
    } else {
      User currentUser = (User) userList.get(0);
      if (!"1".equals(currentUser.getStatus())) {
        res.put("success", Boolean.valueOf(false));
        res.put("message", "该用户已被禁用.");
      } else {
        currentUser = getUserWithMetaByUserId(currentUser.getUserId());

        ClientSession cs = SessionUtils.getClientSession(currentUser);
        res.put("session", cs);
      }
    }

    return res;
  }
예제 #23
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      HttpSession session = request.getSession();
      User user = (User) session.getAttribute("user");

      if (user != null) {
        int roleId = user.getRoleId();
        // Administradores
        if (roleId == 3 || roleId == 7 || roleId == 8) {
          // perform list user operations
          String info =
              (String) request.getAttribute("info") != null
                  ? (String) request.getAttribute("info")
                  : "";
          String error =
              (String) request.getAttribute("error") != null
                  ? (String) request.getAttribute("error")
                  : "";
          request.setAttribute("info", info);
          request.setAttribute("error", error);
          RequestDispatcher rd = getServletContext().getRequestDispatcher("/search.jsp");
          rd.forward(request, response);
        } else {
          request.setAttribute("info", "");
          request.setAttribute("error", "Usted no posee permisos para realizar esta operación");
          RequestDispatcher rd = getServletContext().getRequestDispatcher("/mainMenu.jsp");
          rd.forward(request, response);
        }
      } else {
        RequestDispatcher rd = getServletContext().getRequestDispatcher("/index.jsp");
        rd.forward(request, response);
      }

    } catch (Exception e) {
      throw new ServletException(e);
    }
  }
예제 #24
0
  public void insert(User user) {
    String userId = SessionUtils.getCurrentUserId();
    if (StringUtils.isEmpty(userId)) {
      userId = user.getUserId();
    }

    user.setPassword(MD5Utils.getMD5String(user.getPassword()));

    user.setDelflag("1");

    Timestamp sysdate = new Timestamp(System.currentTimeMillis());
    user.setCreateUser(userId);
    user.setCreateTime(sysdate);
    user.setUpdateUser(userId);
    user.setUpdateTime(sysdate);
    this.userDao.insert(user);
  }
예제 #25
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // user持ってくる
    User user = (User) request.getSession().getAttribute("user");

    // EditBeanつくり!
    EditBean editBean = new EditBean();

    // サービス開始
    PointService service = null;
    service = new PointService();
    service.start();

    // 【指摘事項の取り出し】
    List<Point> pointList = service.getPoint(user.getUserID());

    editBean.setPointList(pointList);
    System.out.println("あ");
    System.out.println(pointList);

    request.setAttribute("bean", editBean);
    RequestDispatcher disp = request.getRequestDispatcher("/Tab.jsp");
    disp.forward(request, response);
  }
예제 #26
0
파일: UserDao.java 프로젝트: yhpdev/NewOS
  /**
   * 数据库操作 更新个人用户数据 管理用户
   *
   * @param user
   */
  public void updateUserInfoServlet(User user) {
    QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    String sql =
        "UPDATE user SET username = ?, password = ?, sex = ?, profession = ?, favourite = ?, note = ?, type = ?  WHERE id = ?;";

    try {
      queryRunner.update(
          sql,
          new Object[] {
            user.getUsername(),
            user.getPassword(),
            user.getSex(),
            user.getProfession(),
            user.getFavourite(),
            user.getNote(),
            user.getType(),
            user.getId()
          });
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
예제 #27
0
파일: UserDao.java 프로젝트: yhpdev/NewOS
 /** 插入数据 */
 public Integer insertUser(User user) {
   QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());
   try {
     String sql = "INSERT INTO user VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     Object param[] = {
       getID(),
       user.getUsername(),
       user.getPassword(),
       user.getSex(),
       user.getProfession(),
       user.getFavourite(),
       user.getNote(),
       user.getType()
     };
     int update = queryRunner.update(sql, param);
     return update;
   } catch (SQLException e) {
     e.printStackTrace();
     return null;
   }
 }
예제 #28
0
 public void testGetPassword() throws Exception {
   assertEquals("1234", u.getPassword());
 }
예제 #29
0
 public void testEquals() throws Exception {
   User u3 = new User("admin", "1234");
   assertTrue(u3.equals(this.u));
 }
예제 #30
0
 public void testGetId() throws Exception {
   assertEquals("admin", u.getUserName());
 }