/**
   * 生成日志
   *
   * @param logType 1 为系统管理日志 2为登录日志 3为业务日志
   * @param logContent 日志内容
   * @param result 操作结果
   * @return
   */
  public boolean insertSystemLog(String logType, String logContent, boolean result) {
    DbContextHolder.setDbType(DbContextHolder.DATA_SOURCE_COMMON);
    Systemdiary systemLog = new Systemdiary();
    systemLog.setDiaryCode(GenUUID.generateUUID());
    systemLog.setOperContent(logContent);
    systemLog.setDiaryType(logType);
    systemLog.setOperTime(CurrentDate.getCurrentDate());
    if (result) {
      systemLog.setOperResult("操作成功");
    } else {
      systemLog.setOperResult("操作失败");
    }
    Map<String, Object> session = (Map<String, Object>) ActionContext.getContext().getSession();
    User nowuser = (User) session.get("currentUser");
    if (nowuser != null) {
      systemLog.setOperPerson(nowuser.getUserName());
    }

    if (logType != null) {
      if (logType.equals("1")) {
        systemLog.setDiaryName("系统管理日志");
      } else if (logType.equals("2")) {
        systemLog.setDiaryName("系统登录日志");
      } else {
        systemLog.setDiaryName("系统业务日志");
      }
    }
    return systemLogDao.executeInsertEntity(systemLog);
  }
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    try {
      User user = new User();
      services.ServiceProxy proxy = new services.ServiceProxy();
      proxy.setEndpoint("http://localhost:8080/CMPE273VideoLibrary/services/Service");
      System.out.println("Login :::::::: Form Submitted");
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      // System.out.println("Username :::::::" + username);
      // System.out.println("Password :::::::" + password);
      user = proxy.signIn(username, password);
      if (user.getErrorMsg().equals("SUCCESS")) {
        if ((user.getPreference().getPreferenceId() == 1)
            || (user.getPreference().getPreferenceId() == 2)
            || (user.getPreference().getPreferenceId() == 3)) {
          HttpSession session = request.getSession();
          session.setAttribute("user", user);
          response.sendRedirect("Home.jsp");
        }
      } else {

        request.setAttribute("errorMsg", user.getErrorMsg());
        System.out.println("error Msg in servlet:" + request.getAttribute("errorMsg"));
        // response.sendRedirect("SignIn.jsp");
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("Login.jsp");
        requestDispatcher.forward(request, response);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #3
0
 /**
  * Logs in a user into the authentication system. This log in function does not allow
  * administrators.
  *
  * @param nick is user's nick.
  * @param pw is the user's password hashed with sha1.
  * @return the authentication object or null if failed.
  */
 public Auth login(String nick, String pw) {
   User u = dbc.loadUser(nick);
   if (u == null || u.isAdministrator()) return null;
   Auth a = Auths.getInstance().login(u, pw);
   if (a == null) return null;
   return new SAuth(a);
 }
  // PAS FINI ?
  @Override
  public boolean createUser(User user) throws SQLException {
    if (SQLSettings.getPDS() == null) System.err.println("getPDS() not started.");
    ResultSet rset = null;
    int rset2;
    Statement stmt = null;
    Connection connection = null;

    try {
      connection = SQLSettings.getPDS().getConnection();
      stmt = connection.createStatement();
      String encryptedPass = null;

      rset = stmt.executeQuery("select PASSWORD('" + user.getPassword() + "') ;");
      if (rset != null) {
        while (rset.next()) {
          encryptedPass = rset.getString(1);
        }
        rset2 =
            stmt.executeUpdate(
                "create user '"
                    + user.getLogin()
                    + "'@'%' IDENTIFIED BY PASSWORD '"
                    + encryptedPass
                    + "' ;");

        String[] viewCommand = Scripts.getCreateUserViews(user);
        // On cree les vues utilisateur et on donne les acces
        for (String curcom : viewCommand) rset2 = stmt.executeUpdate(curcom);

        // on insere le tuple dans user_view
        UserViewDAO uvdao = new MySQLUserViewDAO();
        uvdao.addUserView(user.getLogin(), user.getId());

        return true;
      }

      return false;

    } catch (SQLException e) {
      e.printStackTrace();
      throw e;
    } finally {
      try {
        if (rset != null) rset.close();
      } catch (Exception e) {
      }
      ;
      try {
        if (stmt != null) stmt.close();
      } catch (Exception e) {
      }
      ;
      try {
        if (connection != null) connection.close();
      } catch (Exception e) {
      }
      ;
    }
  }
 @Override
 protected Object process(EntityManager em, Object... params) throws ClassNotFoundException {
   // TODO Auto-generated method stub
   DAO<User> udao = new DAO<User>(User.class, em);
   User u = udao.singleResultQueryRead(User.class, "User.getById", params[0]);
   return u.getCreatedCourses();
 }
Beispiel #6
0
 public static void update(User user) {
   if (user.getId() == null) {
     throw new UpdateUserException("require userId");
   }
   User sourceUser = (User) findById(user.getId());
   if (sourceUser == null) {
     throw new UpdateUserException("no matched user, userId is [" + user.getId() + "]");
   }
   boolean needUpdate = false;
   if (!StringUtils.equals(user.name, sourceUser.name)) {
     needUpdate = true;
   }
   if (!needUpdate && !StringUtils.equals(user.profileImageUrl, sourceUser.profileImageUrl)) {
     needUpdate = true;
   }
   if (!needUpdate && !StringUtils.equals(user.screenName, sourceUser.screenName)) {
     needUpdate = true;
   }
   if (!needUpdate && user.uid != sourceUser.uid) {
     needUpdate = true;
   }
   if (needUpdate) {
     user.save();
   }
 }
Beispiel #7
0
  /** This method is used to retrieve data and show it on the screen */
  public void render() {
    jLabelName.setText(this.subscription.getTitle());
    jLabelGender.setText("Man");
    jLabelAge.setText(String.valueOf(this.subscription.getMinimumAge()));
    jLabelDays.setText(CourseInfo.implode(this.subscription.getDays(), ", "));
    jLabelDuration.setText(
        String.valueOf(this.subscription.getStartTime())
            + " - "
            + String.valueOf(this.subscription.getEndTime()));
    jLabelDescription.setText(this.subscription.getDescription());
    jLabelBranch.setText(this.subscription.getBranch().getCity());

    // Empty results
    jLabelUser.setText("");
    jBtnSubmit.setVisible(false);

    // Age range
    if (this.subscription.getMaximumAge() <= 16) jLabelAge.setText("< 16");
    else if (this.subscription.getMaximumAge() <= 18) jLabelAge.setText("16 - 18");
    else if (this.subscription.getMaximumAge() <= 65) jLabelAge.setText("18 - 65");
    else if (this.subscription.getMaximumAge() <= 150) jLabelAge.setText("65+");

    // Enrollments
    ArrayList<User> users = Enrollment.readBySubscriptionId(this.subscription.getId());

    for (User user : users) {
      if (user.getFullName() != "" && user.getFirstname() != null) {
        this.model.insertRow(0, new Object[] {user.getId(), user.getFullName()});
      }
    }

    // Make a selection listener
    this.row = jTableUsers.getSelectionModel();
    this.row.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  }
Beispiel #8
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String email = request.getParameter("email");
    String pass = request.getParameter("password");
    String admin_mail = "*****@*****.**";
    String accion = request.getParameter("action");

    if ("logout".equals(accion) && request.getSession().getAttribute("user") != null) {
      HttpSession session = request.getSession(false);
      if (session != null) {
        session.removeAttribute("user");
        session.invalidate();
      }
      response.sendRedirect("/index.jsp");
    } else {
      User user = dao.getUserByMail(email);
      request.setAttribute("user", user);
      boolean status = user.validate(pass);
      if (status) {
        HttpSession session = request.getSession(false);
        session.setAttribute("user", user.getFirstName() + ' ' + user.getLastName());
        if (admin_mail.equals(email)) {
          session.setAttribute("isAdmin", "true");
        } else {
          session.setAttribute("isAdmin", "false");
        }
        response.getWriter().print("Ok");
      } else {
        response.getWriter().print("Error");
      }
    }
  }
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub

    HttpSession session = request.getSession();
    User curuser = (User) session.getAttribute("curuser");
    String uemail = curuser.getEmail();

    double price = (Double) session.getAttribute("cprice");
    String name = (String) session.getAttribute("cname");
    String temp_quant = request.getParameter("quantity");
    int quant = Integer.parseInt(temp_quant);

    Cart cartentry = new Cart();
    cartentry.setName(name);
    cartentry.setPrice(price);
    cartentry.setQuant(quant);
    cartentry.setUemail(uemail);
    cartentry.setBought(0);

    Utils<Cart> db = new Utils<Cart>();
    db.insert(cartentry);

    // Prod prod = new Prod();
    // prod.setName(name);
    // prod.setPrice(price);
    // prod.setQuant(quant);

    // List<Prod> items = (List<Prod>) session.getAttribute("items");
    // items.add(prod);

    response.setContentType("text/html");

    getServletContext().getRequestDispatcher("/ProductList").forward(request, response);
  }
Beispiel #10
0
  @Override
  public String execute(HttpServletRequest request, HttpServletResponse response)
      throws FunctionalException, TechnicalException {
    String username = request.getParameter(BaseConfig.USERNAME);
    String password = request.getParameter(BaseConfig.PASSWORD);

    UserService service;
    if (BaseConfig.USEMOCK) {
      service = UserServiceMock.getInstance();
    } else {
      service = UserServiceImpl.getInstance();
    }

    User user = null;

    user = service.find(username);

    if (user != null && user.getPassword().equals(password)) {

      HttpSession session = request.getSession();
      session.setAttribute(BaseConfig.USERNAME, user.getName());
      Role role = user.getRole();
      session.setAttribute(BaseConfig.ROLE, role);

    } else {
      throw new FunctionalException(Level.WARNING, BaseConfig.INVALID_DATA);
    }

    return BaseConfig.APP_CONTEXT; // Redirect to home page.
  }
Beispiel #11
0
 private void setAllFildsToUser() {
   if (checkPassword()) {
     _user.setLogin(jTextFieldAccountName.getText());
     _user.setRedirectUrl(jTextFieldRedirectUrl.getText());
     _user.setPassword(new String(jPasswordFieldNewPassword.getPassword()));
   }
 }
Beispiel #12
0
  // 修改成员信息
  public String UpdateMember() throws Exception {
    UserDAO uDAO = null;
    String retMess = "UpdateMemberFailed";

    try {
      uDAO = DAOFactory.getUserDAOInstance();
      User user = new User();
      // 获得uId
      setUserId(Integer.parseInt(ServletActionContext.getRequest().getParameter("uId")));

      user.setuId(getUserId());
      user.setuMgr(getUserMgr());
      user.setuEducation(getUserEducation());

      if (uDAO.doUpdateMember(user)) {
        ArrayList<User> uList = (ArrayList<User>) uDAO.doSelectById(getUserId());

        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("uList", uList);

        ArrayList<String> mgrList = (ArrayList<String>) uDAO.doSelectAllMgr(getUserId());
        request.setAttribute("mgrList", mgrList);

        retMess = "UpdateMember";
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return retMess;
  }
Beispiel #13
0
  public static int updateOneUser(User user) {
    int uid = user.getUid();
    String userName = user.getUserName();
    String email = user.getEmail();
    String password = user.getPassword();
    try {
      conn = RDSManagement.getConnection();
      st = (Statement) conn.createStatement();
      String sql =
          "update User set email ='"
              + email
              + "', password ='******' where uid = "
              + uid
              + ";";
      System.out.println(sql);
      st.executeUpdate(sql);
      System.out.println("Update user: " + uid);

    } catch (SQLException e) {
      System.out.println(e.getMessage());
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        st.close();
        conn.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return uid;
  }
Beispiel #14
0
 public static FeedItem valueOf(com.umeng.comm.core.beans.FeedItem feedItem, int feedType) {
   if (feedItem == null) return null;
   FeedItem newFeedItem = new model.FeedItem();
   newFeedItem.id = feedItem.id;
   newFeedItem.text = feedItem.text;
   newFeedItem.sourceFeed = FeedItem.valueOf(feedItem.sourceFeed, -1);
   newFeedItem.addTime = feedItem.addTime;
   newFeedItem.atFriends = new ArrayList<>();
   for (CommUser atUser : feedItem.atFriends) {
     newFeedItem.atFriends.add(User.valueOf(atUser));
   }
   newFeedItem.creator = User.valueOf(feedItem.creator);
   newFeedItem.imageUrls = new ArrayList<>();
   for (ImageItem imageUrl : feedItem.imageUrls) {
     newFeedItem.imageUrls.add(imageUrl.originImageUrl);
   }
   newFeedItem.topics = new ArrayList<>();
   for (com.umeng.comm.core.beans.Topic newTopic : feedItem.topics) {
     newFeedItem.topics.add(Topic.valueOf(newTopic));
   }
   newFeedItem.commentCount = feedItem.commentCount;
   newFeedItem.likeCount = feedItem.likeCount;
   newFeedItem.forwardCount = feedItem.forwardCount;
   newFeedItem.locationAddr = feedItem.locationAddr;
   newFeedItem.feedType = feedType;
   newFeedItem.publishTime = feedItem.publishTime;
   return newFeedItem;
 }
Beispiel #15
0
 public static com.umeng.comm.core.beans.FeedItem toValueOf(FeedItem feedItem) {
   if (feedItem == null) return null;
   com.umeng.comm.core.beans.FeedItem newFeedItem = new com.umeng.comm.core.beans.FeedItem();
   newFeedItem.id = feedItem.id;
   newFeedItem.text = feedItem.text;
   newFeedItem.sourceFeed = FeedItem.toValueOf(feedItem.sourceFeed);
   newFeedItem.addTime = feedItem.addTime;
   newFeedItem.atFriends = new ArrayList<>();
   for (User atUser : feedItem.atFriends) {
     newFeedItem.atFriends.add(User.toValue(atUser));
   }
   newFeedItem.creator = User.toValue(feedItem.creator);
   newFeedItem.imageUrls = new ArrayList<>();
   for (String imageUrl : feedItem.imageUrls) {
     newFeedItem.imageUrls.add(new ImageItem("", imageUrl, imageUrl));
   }
   newFeedItem.topics = new ArrayList<>();
   for (Topic newTopic : feedItem.topics) {
     newFeedItem.topics.add(Topic.toValue(newTopic));
   }
   newFeedItem.commentCount = feedItem.commentCount;
   newFeedItem.likeCount = feedItem.likeCount;
   newFeedItem.forwardCount = feedItem.forwardCount;
   newFeedItem.locationAddr = feedItem.locationAddr;
   newFeedItem.publishTime = feedItem.publishTime;
   return newFeedItem;
 }
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    // Get a hold of the account manager
    ServletContext context = request.getServletContext();

    // Get the name and password entered by the user
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String firstName = request.getParameter("firstName");
    String lastName = request.getParameter("lastName");
    String imageUrl = request.getParameter("imageUrl");

    // Check with the account manager and see if the username exists. If it does,
    // switch to the "account name in use" page. Otherwise, switch to the
    // "welcome" page.
    if (User.userExists(username)) {
      HttpSession session = request.getSession();
      User user = User.getUser(username);
      session.setAttribute("username", username);
      request.getRequestDispatcher("account-exists.jsp").forward(request, response);
    } else {
      User.createUser(username, password, firstName, lastName, imageUrl);
      HttpSession session = request.getSession();
      User user = User.getUser(username);
      session.setAttribute("username", username);
      request.getRequestDispatcher("index.jsp").forward(request, response);
    }
  }
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public String getMovie(@PathVariable String id, ModelMap model) {
    configureSessionFactory();
    Session session = null;
    Transaction tx = null;
    try {
      session = sessionFactory.openSession();
      tx = session.beginTransaction();
      Query query = session.createQuery("from User u where u.id = '" + id + "'");
      List users = query.list();
      User user = null;
      if (users != null && users.size() > 0) user = (User) users.get(0);
      tx.commit();
      session.flush();
      if (user != null) {
        model.addAttribute("movie", user.getName());
        return "list";
      } else {
        model.addAttribute("movie", "There is a problem in the communication");
        return "list";
      }
    } catch (Exception ex) {
      ex.printStackTrace();

      // Rolling back the changes to make the data consistent in case of any failure
      // in between multiple database write operations.
      tx.rollback();
      model.addAttribute("movie", "There is a problem in the communication");
      return "list";
    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
Beispiel #18
0
 /**
  * @param user
  * @param friend
  * @return String "OWN" if the user, "KNOWN" if he is a friend, "UNKNOWN" if he is not a friend.
  */
 @SuppressWarnings("unchecked")
 @POST
 @Path("/isfriend")
 @Produces("text/plain")
 @Consumes("application/json")
 public String isFriend(String json) {
   Gson gson = new Gson();
   Map<String, String> jsonFriend = gson.fromJson(json, HashMap.class);
   String user = jsonFriend.get("user");
   String friend = jsonFriend.get("friend");
   String isFriend = "";
   if (user.equals(friend)) {
     isFriend = "OWN";
   } else {
     isFriend = "UNKNOWN";
     List<User> friends = FriendDB.getFriends(new User(user));
     for (User fr : friends) {
       if (fr.equals(friend)) {
         isFriend = "KNOWN";
         break;
       }
     }
   }
   return isFriend;
 }
  public String download() throws Exception {
    LogWriter.println(this.getClass().toString() + ":download下的方法被调用了");
    // 创建新的ExportExcel类以创建excel
    ExportExcel<YearCountTaxModel> ex = new ExportExcel<YearCountTaxModel>(new YearCountTaxModel());
    //
    SXSSFWorkbook workbook = new SXSSFWorkbook(300);
    if (getSessionUser() == null) {
      return "noSession";
    }
    // 获取记录总数,这里除以40000是为什么
    long count =
        yearCountTaxService.getAllMessageCount(
                    user.getUpperDistrict() + user.getDistrictName(), beginyear, endyear)
                / 40000
            + 1;
    LogWriter.println("获取的记录数位:" + count);

    for (int i = 0; i < count; ++i) {
      getAllList(i * 40000, 40000);
      // 获取需要下载的数据list
      // 获取需要下载的数据list
      workbook = ex.creatExcel(workbook, analyList);
    }
    // 创建输出流
    excelFile = ex.downLoadExcel(workbook);
    systemLogService.insertSystemLog("3", "下载按年度统计纳税征缴情况", true);
    return "excel";
  }
Beispiel #20
0
 public List<Rating> getRatings() {
   List<Rating> allRatings = new ArrayList<>();
   for (User user : users) {
     allRatings.addAll(user.getRatings());
   }
   allRatings.addAll(ratings);
   return allRatings;
 }
Beispiel #21
0
 public User getUserByNickname(String nickname) {
   for (User user : users) {
     if (user.getNickname().equals(nickname)) {
       return user;
     }
   }
   return null;
 }
 @Override
 public void save(User user) throws UserExistedException {
   if (userDao.get(user.getLoginName()) != null) {
     throw new UserExistedException();
   }
   user.setPassword(SecurityUtils.encryptPassword(user.getLoginName(), user.getPassword()));
   user.setRegTime(new Date());
   userDao.save(user);
 }
Beispiel #23
0
 @Override
 public PostIt updatePostIt(String name, String token, int id) throws RemoteException {
   for (User user : users) {
     if (user.getUserName().equals(name)) {
       return user.getPostIt(token, id);
     }
   }
   return null;
 }
  /**
   * Update the list of managed parks of a Park Manager.
   *
   * @author Taylor Gorman
   */
  public void updateParkList(String theEmail, List<String> theManagedParks) {
    List<User> myManagerList = myUserList.getParkManagerListCopy();

    for (User manager : myManagerList) {
      if (manager.getEmail().equals(theEmail)) {
        ((ParkManager) manager).setManagedParks(theManagedParks);
      }
    }
  }
 @Override
 public User getUser(String loginName, String password) {
   User user = userDao.get(loginName);
   if ((user != null)
       && user.getPassword().equals(SecurityUtils.encryptPassword(loginName, password))) {
     return user;
   } else {
     return null;
   }
 }
Beispiel #26
0
 public boolean checkToken(String token) {
   for (User user : users) {
     if (user.getToken() != null) {
       if (user.getToken().equals(token)) {
         return true;
       }
     }
   }
   return false;
 }
Beispiel #27
0
 @Override
 public List<PostIt> getAllPostIts(String name, String Token) throws RemoteException {
   // retorna todos os postits do usuario
   for (User user : users) {
     if (user.getUserName().equals(name)) {
       return user.getAllPostIt(Token);
     }
   }
   return null;
 }
Beispiel #28
0
 @Override
 public boolean addNewUser(String name, String pass) throws RemoteException {
   for (User user : users) {
     if (user.getUserName().equals(name)) return false;
   }
   users.add(new User(name, pass));
   System.out.println("Usuario " + name + " criado! Senha " + pass);
   saveData();
   return true;
 }
Beispiel #29
0
 public User getUserFromToken(String token) {
   for (User user : users) {
     if (user.getToken() != null) {
       if (user.getToken().equals(token)) {
         return user;
       }
     }
   }
   return null;
 }
  @Test
  public void testApplyCourse() {
    Course course = new Course();
    User student = new User();
    student.setUserType(UserType.STUDENT);
    student.applyCourse(course);

    assertEquals(1, student.getAppliedCourses().size());
    assertEquals(1, course.getApplicationNum());
  }