Пример #1
0
 @Override
 public void changePwd(String name, String pwd) {
   String hql = "from User u where u.name = ?";
   Query query = getSession().createQuery(hql);
   query.setString(0, name);
   List<?> list = query.list();
   Iterator<?> it = list.iterator();
   while (it.hasNext()) {
     User user = (User) it.next();
     user.setPassword(pwd);
   }
 }
Пример #2
0
 @Override
 public List<?> searchUser(User user) {
   Criteria criteria = getSession().createCriteria(User.class);
   if (user != null) {
     if (user.getName() != null && !user.getName().equals("")) {
       criteria.add(Restrictions.eq("name", user.getName()));
     }
     if (user.getPassword() != null && !user.getPassword().equals("")) {
       criteria.add(Restrictions.eq("password", user.getPassword()));
     }
   }
   List<?> list = criteria.addOrder(Order.asc("id")).list();
   return list; // 通过判定list的size(),可以进行登录验证
 }
Пример #3
0
 @Override
 public void modifyUser(User user) {
   // 获取当前租户的名字,因此名字不能改,密码修改需要另外验证!
   String name = user.getName();
   Criteria criteria = getSession().createCriteria(User.class);
   if (user != null) {
     if (name != null && !name.equals("")) {
       criteria.add(Restrictions.eq("name", name));
     }
   }
   List<?> list = criteria.list();
   Iterator<?> it = list.iterator();
   while (it.hasNext()) {
     User myuser = (User) it.next();
     myuser.setAddress(user.getAddress());
     myuser.setEmail(user.getEmail());
     myuser.setPhone(user.getPhone());
     myuser.setTenant(user.getTenant());
     myuser.setPermit(user.getPermit());
     getSession().update(myuser);
   }
 }