Пример #1
0
 public UserTree(User user) {
   this.setUid(user.getUid());
   this.setUsername(user.getUsername());
   this.setPassword(user.getPassword());
   this.setIsadmin(user.isIsadmin());
   this.setEmployeename(user.getEmployeename());
   this.setUsertype(user.getUsertype());
   this.setUsertypename(user.getUsertypename());
   this.setEmail(user.getEmail());
   this.setComment(user.getComment());
   this.setCreateby(user.getCreateby());
   this.setCreatetime(user.getCreatetime());
   this.setEditby(user.getEditby());
   this.setEdittime(user.getEdittime());
   this.setLastlogin(user.getLastlogin());
   this.setSex(user.getSex());
   this.setBirthday(user.getBirthday());
   this.setIdcard(user.getIdcard());
   this.setAddress(user.getAddress());
   this.setMobile(user.getMobile());
   this.setTelephone(user.getTelephone());
   this.setEmergencycontact(user.getEmergencycontact());
   this.setAvatarurl(user.getAvatarurl());
   this.setPostuid(user.getPostuid());
   this.setPostname(user.getPostname());
   this.setParentuid(user.getParentuid());
 }
Пример #2
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;
  }
  // 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) {
      }
      ;
    }
  }
Пример #4
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.
  }
Пример #5
0
 @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);
 }
Пример #6
0
 @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;
   }
 }
Пример #7
0
 /**
  * This method registers a new user in the system
  *
  * @param ui the new user's information
  * @param pw the new user's password
  * @return the authentication of the registered user
  */
 public Auth newUser(UserInfo ui, String pw) {
   User u = new User(ui);
   u.setPassword(pw);
   u.setAdministrator(false);
   if (dbc.newUser(u)) {
     User nu = dbc.loadUser(u.getId());
     return new SAuth(Auths.getInstance().login(nu, nu.getPassword()));
   }
   return null;
 }
  @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";
  }
Пример #9
0
 private boolean checkPassword() {
   char[] oldPassword = _user.getPassword().toCharArray();
   char[] verifyToBeChangedPassword = jPasswordFieldOldPassword.getPassword();
   char[] newPassword = jPasswordFieldNewPassword.getPassword();
   char[] confirmPassword = jPasswordFieldConfirmationNewPassword.getPassword();
   if (Arrays.equals(oldPassword, verifyToBeChangedPassword)) {
     if (Arrays.equals(newPassword, confirmPassword)) {
       return true;
     } else {
       JOptionPane.showMessageDialog(
           this, "Parola noua nu coincide.", "Inane warning", JOptionPane.WARNING_MESSAGE);
     }
   } else {
     JOptionPane.showMessageDialog(
         this, "Parola veche nu este corecta.", "Inane warning", JOptionPane.WARNING_MESSAGE);
   }
   return false;
 }
  public void insertValues(User user) {

    try {

      stmt = conn.createStatement();
      String sql =
          "INSERT INTO user values('"
              + user.getUserId()
              + "','"
              + user.getUserEmail()
              + "','"
              + user.getPassword()
              + "','"
              + user.getRole()
              + "')";
      stmt.execute(sql);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #11
0
  public static int insertOneUser(User user) {
    int uid = getMaxUserID() + 1;
    String userName = user.getUserName();
    String email = user.getEmail();
    String password = user.getPassword();
    try {
      conn = RDSManagement.getConnection();
      st = (Statement) conn.createStatement();
      String sql =
          "insert into User values("
              + uid
              + ",'"
              + userName
              + "', '"
              + email
              + "','"
              + password
              + "');";
      System.out.println(sql);
      int count = st.executeUpdate(sql);
      System.out.println("Inserted " + count + " items into Event");

    } 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;
  }
  public void updateUserBd(User user, String id) {

    Session session = HibernateUtil.openSession();
    Transaction transaction = null;

    try {
      transaction = session.getTransaction();
      transaction.begin();

      SQLQuery query =
          session.createSQLQuery(
              "UPDATE user SET surname=?, name=?, middleName=?, login=?, password=?, mobileTelephone=?, email=? WHERE id=?;");
      query.setParameter(0, user.getSurname());
      query.setParameter(1, user.getName());
      query.setParameter(2, user.getMiddleName());
      query.setParameter(3, user.getLogin());
      query.setParameter(4, user.getPassword());
      query.setParameter(5, user.getMobileTelephone());
      query.setParameter(6, user.getEmail());
      query.setParameter(7, id);
      int resultUpdate =
          query.executeUpdate(); // возвращает количество субъектов которые были изменены

      System.out.println("Update отчет " + resultUpdate);

      // session.saveOrUpdate(user);
      transaction.commit(); // применяем транзакцию
    } catch (Exception e) {

      // отменяем транзакцию
      transaction.rollback();
      e.printStackTrace();
    } finally {
      session.close();
    }
  }
Пример #13
0
  public int createNewUser(User newUser) throws SQLException, ParseException {

    stmt = con.createStatement();

    try {

      String query =
          "INSERT INTO borrower VALUES (bid_counter.nextVal, '"
              + newUser.getPassword()
              + "', '"
              + newUser.getName()
              + "', '"
              + newUser.getAddress()
              + "', "
              + newUser.getPhone()
              + ", '"
              + newUser.getEmailAddress()
              + "', "
              + newUser.getSinOrStNo()
              + ", '"
              + formatDate(newUser.getExpiryDate())
              + "', '"
              + newUser.getType()
              + "')";

      System.out.println(query);

      stmt.executeUpdate(query);

      updateMessage("Adding User", true);

      String newQuery = "SELECT BID from Borrower where sinOrStNo = " + newUser.getSinOrStNo();

      ResultSet rs = stmt.executeQuery(newQuery);
      rs.next();
      return rs.getInt(1);

    }
    /*catch (IOException e)
    {
        System.out.println("IOException!");
    }*/

    catch (SQLException ex) {
      System.out.println("Message: " + ex.getMessage());
      try {
        // undo the insert
        con.rollback();
      } catch (SQLException ex2) {
        System.out.println("Message: " + ex2.getMessage());
        throw ex2;
      }
      throw ex;

      //		if(newUser == null){
      //			throw new SQLException("Null User");
      //		}
      //		System.out.println(newUser.getName() + " was added to the database");
      //		this.updateStatusBar("New user added to DB");

    }
  }
Пример #14
0
  public String login() throws Exception {
    final String login_fail = "login_fail";

    this.status = "默认!!!";
    if (ServletActionContext.getRequest().getMethod().equalsIgnoreCase("get")) {
      return ActionSupport.SUCCESS;
    }
    if (username == null || username == "") {
      this.status = "用户名不能为空";
      return login_fail;
    }

    Session session = model.Util.sessionFactory.openSession();
    Criteria q = session.createCriteria(User.class).add(Restrictions.eq("username", username));
    List ul = q.list();

    if (ul.isEmpty()) {
      session.close();
      return login_fail;
    }
    User u = (User) ul.get(0);
    if (!u.getPassword().equals(password)) {
      session.close();
      return login_fail;
    }

    String role = "";
    ul =
        session
            .createCriteria(model.AdminProfile.class)
            .add(Restrictions.eq("user.id", u.getId()))
            .list();
    if (!ul.isEmpty()) {
      role = util.Const.AdminRole;
    } else {
      ul =
          session
              .createCriteria(model.StudentProfile.class)
              .add(Restrictions.eq("user.id", u.getId()))
              .list();
      if (!ul.isEmpty()) {
        model.StudentProfile loginStudent = (StudentProfile) ul.get(0);
        if (loginStudent.isPassed != model.StudentProfile.Passed) {
          session.close();
          return login_fail;
        }

        role = util.Const.StudentRole;
        if (loginStudent.getIsUpgradePrivilege() == 1) {
          role = util.Const.StudentToAdminRole;
        }

        ActionContext.getContext().getSession().put("student_id", loginStudent.getId());
      } else {
        session.close();
        return login_fail;
      }
    }

    session.close();
    //		System.out.println(u.getPassword());
    //		System.out.println(u.username);
    if (!u.getPassword().equals(password)) return login_fail;

    ActionContext.getContext().getSession().put("username", username);
    ActionContext.getContext().getSession().put("fullName", u.getFullName());
    ActionContext.getContext().getSession().put("role", role);
    ActionContext.getContext().getSession().put("user_id", u.getId());
    //		ActionContext.getContext().getSession().containsKey(key)

    if (role.equals(util.Const.AdminRole)) {
      ChooseClass.insertDataToDutyTimeTable();
      ChooseClass.insertDataToChooseClassSwitchTable();
      return "admin_login_success";
    } else if (role.equals(util.Const.StudentRole) || role.equals(util.Const.StudentToAdminRole)) {
      ChooseClass.insertDataToDutyTimeTable();
      ChooseClass.insertDataToChooseClassSwitchTable();
      return "student_login_success";
    }
    System.out.println("ERROR");
    return "SB";
  }