Beispiel #1
0
 public List<Role> getRoles() {
   try {
     return (List<Role>)
         DB.exec(
             (db) -> {
               Criteria crit = db.session().createCriteria(Role.class);
               return crit.list();
             });
   } catch (Exception e) {
     getApp().getLog().error(e);
     return null;
   }
 }
Beispiel #2
0
 public User getUserByNick(String nick, boolean includeDeleted) {
   try {
     return (User)
         DB.exec(
             (db) -> {
               Criteria crit = db.session().createCriteria(User.class);
               crit = crit.add(Restrictions.eq("nick", nick));
               if (!includeDeleted) crit = crit.add(Restrictions.eq("deleted", false));
               return crit.uniqueResult();
             });
   } catch (Exception e) {
     getApp().getLog().error(e);
     return null;
   }
 }
Beispiel #3
0
 public boolean updateUser(
     BeanFieldGroup<User> fieldGroup, String currentPass, String newClearPass)
     throws BLException, FieldGroup.CommitException, CloneNotSupportedException {
   BeanItem<User> old = fieldGroup.getItemDataSource();
   Object oldUser = old.getBean().clone();
   fieldGroup.commit();
   BeanItem<User> item = fieldGroup.getItemDataSource();
   User u = item.getBean();
   boolean userUpdated = false;
   try {
     userUpdated =
         (boolean)
             DB.execWithTransaction(
                 (db) -> {
                   User user = (User) db.session().merge(u);
                   UserManager mgr = new UserManager(db);
                   boolean updated = false;
                   if (!newClearPass.isEmpty()) {
                     boolean passwordOK = false;
                     boolean newPasswordOK = false;
                     try {
                       passwordOK = mgr.checkPassword(user, currentPass);
                       newPasswordOK = mgr.checkNewPassword(user, newClearPass);
                       if (passwordOK && newPasswordOK) {
                         mgr.setPassword(user, newClearPass);
                         updated = true;
                       } else if (!newPasswordOK) {
                         throw new BLException("This password has already been used");
                       }
                     } catch (BLException e) {
                       // do nothing
                       return false;
                     }
                   }
                   updated =
                       updated
                           || addRevisionUpdated(
                               db,
                               getEntityName(),
                               String.valueOf(u.getId()),
                               oldUser,
                               u,
                               new String[] {
                                 "nick", "name", "email", "active", "roles", "password"
                               });
                   return updated;
                 });
   } catch (Exception e) {
     getApp().getLog().error(e);
     return false;
   }
   if (userUpdated && u.equals(getApp().getUser())) {
     try {
       DB.exec(
           (db) -> {
             db.session().refresh(getApp().getUser());
             return null;
           });
     } catch (Exception e) {
       getApp().getLog().error(e);
     }
   }
   return userUpdated;
 }