示例#1
0
 // update standard user when they edit their account details
 // This method uses JDBCTemplate, a spring class used to reduce the amount of code needed to run
 // queries
 @Override
 public void updateUser(User user, String oldUserID) throws SQLException {
   String query =
       "UPDATE users SET user_id = ?, first_name = ?, last_name = ?, account_type = ?, email = ?, password = AES_ENCRYPT(?,'.key.') WHERE user_id = ?";
   // String query = "UPDATE users SET user_id = ?, first_name = ?, last_name = ?, account_type =
   // ?, email = ?, password = ? WHERE user_id = ?";
   JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
   System.out.println(
       "UPDATE users SET user_id = "
           + user.getUserID()
           + ", first_name = "
           + user.getFirstName()
           + ", last_name = "
           + user.getLastName()
           + ", account_type = "
           + user.getAccountType()
           + ", email = "
           + user.getEmail()
           + ", password = "******" WHERE user_id = "
           + oldUserID);
   Object[] args =
       new Object[] {
         user.getUserID(),
         user.getFirstName(),
         user.getLastName(),
         user.getAccountType(),
         user.getEmail(),
         user.getPassword(),
         oldUserID
       };
   jdbcTemplate.update(query, args);
 }
 @Override
 public User modify(User user) {
   System.out.println("ԭ�û���:" + user.getName() + "������:" + user.getPassword());
   user.setName("admin");
   user.setPassword("111111");
   System.out.println("�޸ĺ���û���:" + user.getName() + "������:" + user.getPassword());
   return user;
 }
示例#3
0
  public void notify(Packet packet) {
    Log.trace("Register handling " + packet.toString());

    String type = packet.getType();
    Packet query = packet.getFirstChild("query");

    if (type.equals("get")) {
      required.setSession(packet.getSession());
      required.setID(packet.getID());
      MessageHandler.deliverPacket(required);
      return;

    } else if (type.equals("set")) { // type == set
      String username = query.getChildValue("username");
      User user = userIndex.getUser(username);
      if (user != null) { // user exists
        if (packet.getSession().getStatus() != Session.AUTHENTICATED
            || !username.equals(packet.getSession().getJID().getUser())) {
          Packet iq = new Packet("iq");
          iq.setSession(packet.getSession());
          iq.setID(packet.getID());
          ErrorTool.setError(iq, 401, "User account already exists");
          MessageHandler.deliverPacket(iq);
          return;
        }
      } else {
        user = userIndex.addUser(username);
      }
      user.setPassword(query.getChildValue("password"));
      user.setHash(query.getChildValue("hash"));
      user.setSequence(query.getChildValue("sequence"));
      user.setToken(query.getChildValue("token"));
      if (user.getHash() == null || user.getSequence() == null || user.getToken() == null) {
        if (user.getPassword() != null) {
          user.setToken(Authenticator.randomToken());
          user.setSequence("99");
          user.setHash(
              auth.getZeroKHash(100, user.getToken().getBytes(), user.getPassword().getBytes()));
        }
      } else {
        user.setSequence(Integer.toString(Integer.parseInt(user.getSequence()) - 1));
      }
      Packet iq = new Packet("iq");
      iq.setSession(packet.getSession());
      iq.setID(packet.getID());
      iq.setType("result"); // success
      MessageHandler.deliverPacket(iq);
      Log.trace(
          "Register successfully registered "
              + username
              + " with password "
              + query.getChildValue("password"));
    } else {
      Log.info("Register ignoring " + packet.toString());
    }
  }
示例#4
0
 /**
  * @param aStudent
  * @param aPassword
  * @return if valid validate if password matches the user
  */
 public static boolean validatePassword(User aStudent, String aPassword) {
   boolean isValid = false;
   if (aStudent.getPassword().equals(aPassword)) {
     System.out.println(aStudent.getPassword());
     isValid = true;
   } else {
     isValid = false;
   }
   return isValid;
 }
示例#5
0
  /**
   * Validation de l'object m�tier User.<br>
   * Les r�gles sont les suivantes:
   *
   * <ul>
   *   <li>le login est obligatoire
   *   <li>le login est unique
   *   <li>le mot de passse est obligatoire
   *   <li>le nom est obligatoire
   *   <li>le pr�nom est obligatoire
   *   <li>l'email est obligatoire
   *   <li>Le login doit avoir entre 5 et 10 carat�res.
   *   <li>Le mot de passe doit avoir entre 5 et 10 caract�res.
   *   <li>Le format de l'adresse email doit �tre valide
   * </ul>
   *
   * @param object user � valider
   */
  public Errors validate(final Object object) {

    User user = (User) object;

    Errors errors = CoreObjectFactory.getErrors();

    if (user.getLogin() == null || user.getLogin().trim() == "") {

      errors.rejectValue("login", "user.loginMandatory");

    } else if (user.getLogin().length() < 5 || user.getLogin().length() > 10) {

      // le login doit avoir entre 5 et 10 caract�res
      errors.rejectValue("login", "user.loginIncorrectSize");

    } else if (user.getPersistanceId() == 0
        && userRepository.findUserByLogin(user.getLogin()) != null) {

      // le login doit �tre unique
      errors.rejectValue("login", "user.loginAlreadyExists");
    }

    if (user.getPassword() == null || user.getPassword().trim() == "") {

      errors.rejectValue("password", "user.passwordMandatory");

    } else if (user.getPassword().length() < 5 || user.getPassword().length() > 10) {

      // le password doit avoir entre 5 et 10 caract�res
      errors.rejectValue("password", "user.passwordIncorrectSize");
    }

    if (user.getLastName() == null || user.getLastName().trim() == "") {

      errors.rejectValue("lastName", "user.lastNameMandatory");
    }

    if (user.getFirstName() == null || user.getFirstName().trim() == "") {

      errors.rejectValue("firstName", "user.firstNameMandatory");
    }

    if (user.getEmail() == null || user.getEmail().trim() == "") {

      errors.rejectValue("email", "user.emailMandatory");

    } else if (!EmailValidator.getInstance().isValid(user.getEmail())) {

      // Le format de l'adresse email doit �tre valide

      errors.rejectValue("email", "user.incorrectEmail");
    }

    return errors;
  }
示例#6
0
 @Override
 public void check(User user) {
   Preconditions.checkNotNull(user);
   Preconditions.checkNotNull(user.getCreateDate());
   Preconditions.checkNotNull(user.getFirstName());
   Preconditions.checkNotNull(user.getLastName());
   Preconditions.checkNotNull(user.getEmail());
   Preconditions.checkNotNull(user.getUsername());
   Preconditions.checkNotNull(user.getPassword());
   Preconditions.checkState(user.getUsername().length() >= 1);
   Preconditions.checkState(user.getPassword().length() >= 1);
 }
 @Override
 public User check(String username, String password) {
   if (username == null || password == null) {
     return null;
   }
   User user = cache.getUnchecked(username);
   if (user == null || user.getUsername() == null || user.getPassword() == null) {
     return null;
   }
   String encryptPassword = generateEncryptPassword(user, password);
   if (user.getPassword().equals(encryptPassword)) {
     return user;
   }
   return null;
 }
示例#8
0
 public int create(User user) {
   try {
     Statement stat = conn.createStatement();
     ResultSet rs = stat.executeQuery("Select ID FROM USERS ");
     int i = user.getId();
     String n = user.getName();
     String pass = user.getPassword();
     Date d = user.getDate();
     System.out.println("i= " + i);
     stat.execute(
         "INSERT INTO USERS VALUES("
             + i
             + ",'"
             + n
             + "', '"
             + pass
             + "', TO_DATE('"
             + d
             + "','YYYY-MM-DD'))");
   } catch (SQLException e) {
     e.printStackTrace();
     System.out.println("Alarm in addUser");
   }
   return 1;
 }
示例#9
0
  public void add(final User user) throws ClassNotFoundException, SQLException {

    final String query = "insert into userinfo (id, name, password) values (?,?,?)";
    final String[] params = new String[] {user.getId(), user.getName(), user.getPassword()};

    getJdbcTemplate().update(query, params);
  }
示例#10
0
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @RolesAllowed({ADMIN, USER})
  public User modify(@NotNull User user) {

    User existingUser = null;
    if (sessionContext.isCallerInRole(USER) && !sessionContext.isCallerInRole(ADMIN)) {
      existingUser = userFinder.findByLogin(sessionContext.getCallerPrincipal().getName());

      if (!existingUser.getId().equals(user.getId())
          || !existingUser.getLogin().equals(user.getLogin())) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
      }

      user.setActivated(existingUser.getActivated());
      user.setDisabled(existingUser.getDisabled());
      user.setActionToken(existingUser.getActionToken());
    }

    if (existingUser == null) {
      existingUser = entityManager.find(User.class, user.getId());
    }
    checkNotNull(existingUser);
    user.setPassword(existingUser.getPassword());
    user.setCreationDate(existingUser.getCreationDate());
    user.setRoles(existingUser.getRoles());
    return entityManager.merge(user);
  }
示例#11
0
 @JSON(serialize = false)
 public String json() throws Exception {
   System.out.println("json");
   System.out.println(user.getUsername());
   System.out.println(user.getPassword());
   return "json";
 }
示例#12
0
  @RequestMapping("/addUser6")
  public void addUser6(User user, PrintWriter out) {
    log.info("userName is:" + user.getUserName());
    log.info("password is:" + user.getPassword());
    String json = null;
    /** 使用Jackson */
    ObjectMapper map = new ObjectMapper();
    try {
      json = map.writeValueAsString(user);

    } catch (JsonGenerationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (JsonMappingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    log.info("使用Jackson:" + json);

    /** 使用fastjson */
    json = JSON.toJSONString(user);
    log.info("使用fastjson:" + json);
    out.write(json);
  }
 @Override
 public void update(final User user) {
   if (user == null) {
     throw new IllegalArgumentException("User can't null");
   }
   if (Strings.isNullOrEmpty(user.getUsername())) {
     throw new IllegalArgumentException("Username of the user can't be null or empty");
   }
   User old = find(user.getUsername());
   String newEncryptPassword = generateEncryptPassword(user);
   if (!old.getPassword().equals(newEncryptPassword)) {
     user.setPassword(newEncryptPassword);
   }
   mongoDBUtil.keepConnect(
       userCollectionName,
       new CollectionCallback<Void>() {
         @Override
         public Void process(MongoCollection<Document> collection) {
           collection.updateOne(
               new Document(usernameKey, user.getUsername()),
               new Document("$set", new Document(usernameKey, user.getPassword())));
           return null;
         }
       });
   cache.put(user.getUsername(), user);
 }
示例#14
0
 public CurrentUser(User user) {
   super(
       user.getEmail(),
       user.getPassword(),
       AuthorityUtils.createAuthorityList(user.getProfile().toString()));
   this.user = user;
 }
示例#15
0
文件: Blog.java 项目: pcolusso/social
 @WebMethod
 public String getPassword(String email) throws JAXBException, IOException {
   SocialApp app = getSocialApp();
   Users users = app.getUsers();
   User user = users.getUser(email);
   return user.getPassword();
 }
示例#16
0
 @RequestMapping("/addUser5")
 @ResponseBody
 public User addUser5(User user) {
   log.info("userName is:" + user.getUserName());
   log.info("password is:" + user.getPassword());
   return user;
 }
示例#17
0
 @RequestMapping("/addUser3")
 public String addUser3(User user, Model model) {
   log.info("userName is:" + user.getUserName());
   log.info("password is:" + user.getPassword());
   model.addAttribute(user);
   return "/user/success2";
 }
示例#18
0
 public void putAllDetails(User user) {
   SharedPreferences.Editor spEditor = sharedPreferences.edit();
   spEditor.putString("username", user.getUsername());
   spEditor.putString("name", user.getName());
   spEditor.putString("password", user.getPassword());
   spEditor.putString("age", user.getAge());
   spEditor.putString("email", user.getEmail());
   spEditor.putString("phone", user.getPhone());
   spEditor.putString("position", user.getPosition());
   spEditor.putString("experience", user.getExperience());
   spEditor.putString("curloc", user.getCurloc());
   spEditor.putString("desloc", user.getDesloc());
   spEditor.putString("imageuri", user.getImageUri());
   spEditor.putString("com1name", user.getCom1name());
   spEditor.putString("com1pos", user.getCom1pos());
   spEditor.putString("com1from", user.getCom1from());
   spEditor.putString("com1to", user.getCom1to());
   spEditor.putString("com1resp", user.getCom1resp());
   spEditor.putString("com2name", user.getCom2name());
   spEditor.putString("com2pos", user.getCom2pos());
   spEditor.putString("com2from", user.getCom2from());
   spEditor.putString("com2to", user.getCom2to());
   spEditor.putString("com2resp", user.getCom2resp());
   spEditor.putString("com3name", user.getCom3name());
   spEditor.putString("com3pos", user.getCom3pos());
   spEditor.putString("com3from", user.getCom3from());
   spEditor.putString("com3to", user.getCom3to());
   spEditor.putString("com3resp", user.getCom3resp());
   spEditor.apply();
 }
示例#19
0
 public void start() {
   try {
     ServerSocket ss = new ServerSocket(7777);
     System.out.println("start to accept...");
     Socket socket = ss.accept();
     // 建立输入流
     ObjectInputStream ois =
         new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
     Object obj = ois.readObject();
     if (obj != null) {
       User user = (User) obj; // 把接收到的对象转化为user
       System.out.println("user: "******"password: "******"ceshi".getBytes());
     Thread.sleep(100000);
     ois.close();
     socket.close();
     ss.close();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#20
0
  @RequestMapping(value = "/kkn1234/create", method = RequestMethod.POST)
  public String formSubmit(@ModelAttribute User user, Model model)
      throws MalformedURLException, IOException {
    model.addAttribute("user", user);
    HttpPost post =
        new HttpPost(
            "http://ec2-52-4-138-196.compute-1.amazonaws.com/magento/index.php/customer/account/createpost/");
    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpclient =
        HttpClients.custom().setDefaultCookieStore(cookieStore).build();
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("firstname", user.getFirstName()));
    nameValuePairs.add(new BasicNameValuePair("lastname", user.getLastName()));
    nameValuePairs.add(new BasicNameValuePair("email", user.getEmail()));
    nameValuePairs.add(new BasicNameValuePair("password", user.getPassword()));
    nameValuePairs.add(new BasicNameValuePair("confirmation", user.getConfirmation()));

    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(post);
    response = httpclient.execute(post);
    System.out.println("Status code is " + response.getStatusLine().getStatusCode());
    System.out.println(response.toString());
    System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
    System.out.println(response.getFirstHeader("Location"));
    HttpEntity entity = response.getEntity();
    EntityUtils.consume(entity);
    EntityUtils.consume(response.getEntity());

    /*File newTextFile = new File("C:\\Users\\Kris\\Desktop\\temp.html");
    FileWriter fileWriter = new FileWriter(newTextFile);
    fileWriter.write(response.toString());
    fileWriter.close();*/
    return "result";
  }
示例#21
0
  /**
   * Saves a user.
   *
   * @param user the user to save
   * @param currentUser the user performing the save operation
   */
  public void saveUser(User user, User currentUser) throws IOException {
    Assert.notNull(user);
    Assert.notNull(currentUser);

    ILockedRepository repo = null;
    try {
      repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
      Map<String, Object> userMap = new HashMap<String, Object>();
      userMap.put("loginName", user.getLoginName()); // $NON-NLS-1$
      userMap.put("password", user.getPassword()); // $NON-NLS-1$
      userMap.put("email", user.getEmail()); // $NON-NLS-1$
      userMap.put("disabled", Boolean.valueOf(user.isDisabled())); // $NON-NLS-1$
      if (!user.getOpenIds().isEmpty()) {
        userMap.put("openIds", user.getOpenIds()); // $NON-NLS-1$
      }

      Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
      String json = gson.toJson(userMap);
      File workingDir = RepositoryUtil.getWorkingDir(repo.r());
      File workingFile = new File(workingDir, user.getLoginName() + USER_SUFFIX);
      FileUtils.write(workingFile, json, Charsets.UTF_8);

      Git git = Git.wrap(repo.r());
      git.add().addFilepattern(user.getLoginName() + USER_SUFFIX).call();
      PersonIdent ident = new PersonIdent(currentUser.getLoginName(), currentUser.getEmail());
      git.commit().setAuthor(ident).setCommitter(ident).setMessage(user.getLoginName()).call();
    } catch (GitAPIException e) {
      throw new IOException(e);
    } finally {
      Util.closeQuietly(repo);
    }
  }
示例#22
0
 @Test
 public void testFind() throws Exception {
   User foundUser = h2User.find(user.getId());
   assertEquals(email, foundUser.getEmail());
   assertEquals(password, foundUser.getPassword());
   assertEquals(type, foundUser.getType());
 }
 public boolean checkCredentials(String username, String password) {
   User user = _userMap.get(username);
   if (user != null && user.getPassword().equals(password)) {
     return true;
   }
   return false;
 }
示例#24
0
 public static String getPassword(String name) {
   for (User user : _users) {
     if (user.getName().equals(name)) {
       return user.getPassword();
     }
   }
   return "";
 }
 // User local Database constructor
 public void storeUserData(User user) {
   SharedPreferences.Editor spEditor = userLocalDatabase.edit();
   spEditor.putString("username", user.getUsername());
   spEditor.putString("password", user.getPassword());
   spEditor.putString("email", user.getEmail());
   spEditor.putString("lastname", user.getLastName());
   spEditor.putString("firstname", user.getFirstName());
   spEditor.apply();
 }
示例#26
0
 public boolean equals(Object obj) {
   if (this.getClass() == obj.getClass()) {
     User u = (User) obj;
     return this.getUsername().equals(u.getUsername())
         && this.getPassword().equals(u.getPassword())
         && this.getPoints() == u.getPoints()
         && this.isQuizTaken() == u.isQuizTaken();
   } else return false;
 }
示例#27
0
 @JSON(serialize = false)
 public String text() throws Exception {
   System.out.println(user.getUsername());
   System.out.println(user.getPassword());
   String txt = "aaa测试中文";
   String temp = URLEncoder.encode(txt, "UTF-8");
   inputStream = new ByteArrayInputStream(temp.getBytes());
   return "text";
 }
  public User verifyUser(String[] user) {
    for (User tmpUser : userDB) {
      if (tmpUser.getName().equals(user[0]) && tmpUser.getPassword().equals(user[1]))
        return tmpUser;
    }

    System.out.println("Cannot Find");
    return null;
  }
示例#29
0
 public void storePersonal(User user) {
   SharedPreferences.Editor spEditor = sharedPreferences.edit();
   spEditor.putString("username", user.getUsername());
   spEditor.putString("name", user.getName());
   spEditor.putString("password", user.getPassword());
   spEditor.putString("age", user.getAge());
   spEditor.putString("email", user.getEmail());
   spEditor.putString("phone", user.getPhone());
   spEditor.apply();
 }
示例#30
0
 public boolean containsUser(String name, String pass) {
   boolean result = false;
   User temp = users.get(name);
   if (temp != null) {
     if (temp.getPassword().equals(pass)) {
       result = true;
     }
   }
   return result;
 }