@Test
 public void testUserCreate() throws Exception {
   System.out.println("testUserCreate: START");
   // =================================================================================
   int id = 0;
   String username = "******";
   String password = "******";
   boolean active = true;
   boolean admin = true;
   String dob = "11/03/1966";
   String email = "*****@*****.**";
   String securityQuestion1 = "XXX";
   String securityAnswer1 = "XXX";
   String securityQuestion2 = "YYY";
   String securityAnswer2 = "YYY";
   Date birthDate = sdf.parse(dob);
   // =================================================================================
   System.out.println("testUserCreate: START: CREATE");
   UserDTO user = new UserDTO();
   assertNotNull(user);
   // ***************************************************************
   user.setId(id);
   user.setUsername(username);
   user.setPassword(password);
   user.setActive(active);
   user.setEmail(email);
   user.setSecurityQuestion1(securityQuestion1);
   user.setSecurityAnswer1(securityAnswer1);
   user.setSecurityQuestion2(securityQuestion2);
   user.setSecurityAnswer2(securityAnswer2);
   System.out.println("testUserCreate: user="******"testUserCreate: FINISH: CREATE");
 }
Exemple #2
0
  @RequestMapping("add")
  public String register(UserDTO userDTO) {

    userService.createNewUser(userDTO.getUsername(), userDTO.getPassword(), userDTO.isEnable());

    return "index";
  }
Exemple #3
0
  public UserDTO login(UserDTO user) {
    UserDTO dto = null;
    try (Connection conn = Conn.getConnection();
        PreparedStatement pstmt =
            conn.prepareStatement(
                "select user_id,name,auth from user where user_id=? and password=?"); ) {
      pstmt.setInt(1, user.getUid());
      pstmt.setString(2, Sha256.encrypt(user.getPassword()));
      // pstmt.setString(2, user.getPassword());
      try (ResultSet rs = pstmt.executeQuery(); ) {
        if (rs.next()) {
          dto = new UserDTO();
          dto.setUid(rs.getInt("user_id"));
          dto.setName(rs.getString("name"));
          dto.setAuth(rs.getString("auth"));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return dto;
  }
Exemple #4
0
  public static Pair<Boolean, String> updateProject(
      ProjectDTO projectDTO, boolean changedProjectName, String originalProjectName) {
    try {
      // Additional duplication control
      Project existingProject;
      if (changedProjectName) {
        existingProject = ProxyManager.getProjectProxy().findProjectByName(projectDTO.getName());
      } else existingProject = null;

      if (existingProject != null && changedProjectName) {
        System.out.println("Existing project exists!");
        return Pair.of(false, "Project with this name already exists!");
      }

      Project p = ProxyManager.getProjectProxy().findProjectByName(originalProjectName);
      p.setProjectId(projectDTO.getProjectId());
      p.setName(projectDTO.getName());
      p.setDescription(projectDTO.getDescription());
      p.setStatus(projectDTO.getStatus());
      Team team = new Team();
      team.setTeamId(projectDTO.getTeamTeamId().getTeamId());
      team.setScrumMasterId(projectDTO.getTeamTeamId().getScrumMasterId());
      team.setProductOwnerId(projectDTO.getTeamTeamId().getProductOwnerId());

      List<User> userList = new ArrayList<User>();
      if (projectDTO.getTeamTeamId().getUserList() != null) {
        for (UserDTO userDTO : projectDTO.getTeamTeamId().getUserList()) {
          User user = new User();
          user.setUserId(userDTO.getUserId());
          user.setUsername(userDTO.getUsername());
          user.setPassword(userDTO.getPassword());
          user.setFirstName(userDTO.getFirstName());
          user.setLastName(userDTO.getLastName());
          user.setEmail(userDTO.getEmail());
          user.setIsAdmin(userDTO.isAdmin());
          user.setSalt(userDTO.getSalt());
          user.setIsActive(userDTO.isActive());
          user.setTimeCreated(userDTO.getTimeCreated());
          userList.add(user);
        }
        team.setUserList(userList);
      } else return Pair.of(false, "No project list when saving team.");
      p.setTeamTeamId(team);
      try {
        if (p == null) return Pair.of(false, "Data error!");
        ProxyManager.getProjectProxy().edit(p);

      } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        return Pair.of(false, e.getMessage());
      }
    } catch (Exception e) {
      e.printStackTrace();
      return Pair.of(false, e.getMessage());
    }
    return Pair.of(true, "Project updated successfully.");
  }
Exemple #5
0
  public static Pair<Boolean, String> saveNewProject(ProjectDTO projectDTO) {

    // check for project in database
    System.out.println("Project to check in base: " + projectDTO.getName());
    Project existingProject =
        ProxyManager.getProjectProxy().findProjectByName(projectDTO.getName());
    try {
      if (existingProject != null) {
        System.out.println("Existing project exists!");
        return Pair.of(false, "Project with this name already exists!");
      } else System.out.println("Project check passed, no existing project.");

      Project p = new Project();
      p.setName(projectDTO.getName());
      p.setDescription(projectDTO.getDescription());
      p.setStatus(projectDTO.getStatus());
      Team team = new Team();
      team.setTeamId(projectDTO.getTeamTeamId().getTeamId());
      team.setScrumMasterId(projectDTO.getTeamTeamId().getScrumMasterId());
      team.setProductOwnerId(projectDTO.getTeamTeamId().getProductOwnerId());

      List<User> userList = new ArrayList<User>();
      if (projectDTO.getTeamTeamId().getUserList() != null) {
        for (UserDTO userDTO : projectDTO.getTeamTeamId().getUserList()) {
          User user = new User();
          user.setUserId(userDTO.getUserId());
          user.setUsername(userDTO.getUsername());
          user.setPassword(userDTO.getPassword());
          user.setFirstName(userDTO.getFirstName());
          user.setLastName(userDTO.getLastName());
          user.setEmail(userDTO.getEmail());
          user.setIsAdmin(userDTO.isAdmin());
          user.setSalt(userDTO.getSalt());
          user.setIsActive(userDTO.isActive());
          user.setTimeCreated(userDTO.getTimeCreated());
          userList.add(user);
        }
        team.setUserList(userList);
      } else return Pair.of(false, "No user list when saving team.");
      p.setTeamTeamId(team);
      try {
        if (p == null) return Pair.of(false, "Data error!");

        ProxyManager.getProjectProxy().create(p);

      } catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
        return Pair.of(false, e.getMessage());
      }
    } catch (Exception e) {
      e.printStackTrace();
      return Pair.of(false, e.getMessage());
    }
    return Pair.of(true, "Project saved successfully.");
  }
Exemple #6
0
  public void setTempPassword(UserDTO user) {
    try (Connection conn = Conn.getConnection();
        PreparedStatement pstmt =
            conn.prepareStatement("update user set password=? where user_id=?"); ) {

      pstmt.setString(1, Sha256.encrypt(user.getPassword()));
      pstmt.setInt(2, user.getUid());
      pstmt.executeUpdate();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #7
0
  public void userAdd(UserDTO user) {

    try (Connection conn = Conn.getConnection();
        PreparedStatement pstmt = conn.prepareStatement("insert into user values(?,?,?,?)"); ) {
      pstmt.setInt(1, user.getUid());
      pstmt.setString(2, Sha256.encrypt(user.getPassword()));
      pstmt.setString(3, user.getName());
      pstmt.setString(4, user.getAuth());
      pstmt.executeUpdate();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #8
0
  public boolean passwordCheck(UserDTO user) {
    boolean check = false;
    try (Connection conn = Conn.getConnection();
        PreparedStatement pstmt =
            conn.prepareStatement("select user_id from user where user_id=? and password=? "); ) {
      pstmt.setInt(1, user.getUid());
      pstmt.setString(2, Sha256.encrypt(user.getPassword()));
      ResultSet rs = pstmt.executeQuery();
      if (rs.next()) {
        check = true;
      } else {

        check = false;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return check;
  }
  public void testThirdPayYJX() throws Exception {
    // 用户相关信息
    UserDTO user = (new UserSet()).setNormalUser();
    String username = user.getUsername();
    String password = user.getPassword();
    String payPwd = user.getPayPwd();
    int loginId = user.getLoginId();
    BigDecimal acc = user.getAcc(); // 账户最低余额:0-普通账户,-5000-vip账户
    BigDecimal before_pay = null; // 支付前账户余额
    BigDecimal after_pay = null; // 支付后账户余额

    // 产品相关信息
    ProductDTO[] products = new ProductDTO[2];
    products[0] = (new ProductSet()).setYJX();
    products[1] = (new ProductSet()).setYJX_Coupon();

    // 登录
    Ins_Front insF = new Ins_Front();
    insF.loginFront(selenium, username, password);

    for (int i = 0; i < products.length; i++) {
      System.out.println(i + 1);
      String proName = products[i].getProName();
      String proType = products[i].getProductType();
      int coupon = products[i].getPCoupon(); // 支付时是否可以使用优惠券:0-不可以,1-可以

      // 前台购买保险产品,购买前查询账户余额
      before_pay = (new CommSql()).getAccBall(loginId, acc);
      PayResultDTO payResult = insF.pay_YJX(selenium, proName, payPwd, 4, true, loginId);
      Thread.sleep(30000);
      after_pay = (new CommSql()).getAccBall(loginId, acc);
      System.out.println("购买前账户余额:" + before_pay);
      System.out.println("购买后账户余额:" + after_pay);
      // 支付完成后判断订单、投保单状态及账户余额的正确性
      CheckAfterPay check = new CheckAfterPay();
      check.checkAfterThirdPay(selenium, before_pay, after_pay, payResult, coupon, proType);
    }
  }