Hi,
Is there any possibility to set programmatically an user from database setActive(true) if it is false?
I saw that if it is false userSessionSource.getUserSession().getUser returns only Anonymus and Admin.
Please advise.
Regards,
-n
Hi,
Is there any possibility to set programmatically an user from database setActive(true) if it is false?
I saw that if it is false userSessionSource.getUserSession().getUser returns only Anonymus and Admin.
Please advise.
Regards,
-n
As for any other entity, you can load the User instance using DataManager
, set the field and save it using DataManager.commit()
.
Unfortunately doesn’t work.
User “John” stays Active = false in database even I enter as Admin.
@Subscribe
private void onInit(InitEvent event) {
loginButton.addClickListener(e ->{
User u = dataManager.load (User.class).query("select e from sec$User e where e.login = 'john'").one();
u.setActive(true);
dataManager.commit();
expiredUserService.expiredUser();
});
}
and ExpiredUserService:
public void expiredUser( ){
// Transaction tx = persistence.createTransaction();
try (Transaction tx =persistence.getTransaction())
{
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery( "select u.login from sec$User u where u.login = 'john' ");
String str = (String) query.getFirstResult();
LocalDate actdate = LocalDate.now();
LocalDate mycal = stringToDate("19/11/2019");
if(mycal.compareTo(actdate)<0&&str.equals("john")) {
userSessionSource.getUserSession().getUser().setActive(false);
} else{
userSessionSource.getUserSession().getUser().setActive(true); }
tx.commit();
}
User u = //...
u.setActive(true);
dataManager.commit(u);