use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.
the class CurrentUser method updateAlertMail.
public boolean updateAlertMail() {
try {
UserHelper userHelper = new UserHelper();
Connection conn = connect.getPoolConnexion().getConnection();
conn.setAutoCommit(false);
if (!userHelper.setAlertMailForUser(connect.getPoolConnexion().getConnection(), user.getId(), alertmail)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return false;
}
conn.commit();
conn.close();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("conf.alertMailMessage")));
return true;
} catch (SQLException ex) {
Logger.getLogger(CurrentUser.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}
use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.
the class CurrentUser method selectAuthorizedUser.
/**
* retoure la liste des utilisateurs suivant leurs droits
*
* @return
*/
public ArrayList<NodeUser> selectAuthorizedUser() {
UserHelper userHelper = new UserHelper();
int idRoleFrom = 1;
if (user.getIdRole() == 1) {
// l'utilisateur est superAdmin
return selectAllUsers();
}
if (user.getIdRole() == 2) {
// l'utilisateur est admin
idRoleFrom = 2;
}
if (user.getIdRole() > 2) {
// l'utilisateur est autre
idRoleFrom = 3;
}
ArrayList<NodeUser> listeUser = userHelper.getAuthorizedUsers(connect.getPoolConnexion(), idTheso, idRoleFrom);
return listeUser;
}
use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.
the class CurrentUser method renamePseudo.
public void renamePseudo() {
if (pseudo == null || pseudo.isEmpty()) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error6")));
} else if (new UserHelper().isPseudoExist(connect.getPoolConnexion(), pseudo)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error5")));
} else {
new UserHelper().updatePseudo(connect.getPoolConnexion(), user.getId(), pseudo);
user.setName(pseudo);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("user.info5")));
}
name = pseudo;
pseudo = "";
}
use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.
the class CurrentUser method getThesaurusPreferences.
/**
* cette fonction permet de retourner les préférences d'un thésaurus, s'il y
* en a pas, on les initialises par les valeurs par defaut
*
* @param idThesaurus
* @param workLanguage
* @return
*/
public NodePreference getThesaurusPreferences(String idThesaurus, String workLanguage) {
if (user.getId() == 1) {
// superAdmin
authorizedTheso = new ThesaurusHelper().getAllIdOfThesaurus(connect.getPoolConnexion());
} else {
authorizedTheso = new UserHelper().getAuthorizedThesaurus(connect.getPoolConnexion(), user.getId());
}
PreferencesHelper preferencesHelper = new PreferencesHelper();
if (connect.getPoolConnexion() != null) {
nodePreference = preferencesHelper.getThesaurusPreference(connect.getPoolConnexion(), idThesaurus);
if (nodePreference == null) {
// cas où il n'y a pas de préférence pour ce thésaurus, il faut les créer
preferencesHelper.initPreferences(connect.getPoolConnexion(), idThesaurus, workLanguage);
nodePreference = preferencesHelper.getThesaurusPreference(connect.getPoolConnexion(), idThesaurus);
} else {
langSourceEdit = nodePreference.getSourceLang();
// alertNbCdtEdit = nodePreference.getNbAlertCdt();
// alertCdtEdit = nodePreference.isAlertCdt();
selectedThesaurus = new ArrayList<>();
selectedThesaurus.add(idTheso);
}
idTheso = idThesaurus;
versionOfOpentheso = new BaseDeDoneesHelper().getVersionOfOpentheso(connect.getPoolConnexion());
return nodePreference;
}
return null;
}
use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.
the class CurrentUser method addUser.
public void addUser() throws SQLException {
if (pwdEdit1 == null || pwdEdit1.equals("") || pwdEdit2 == null || pwdEdit2.equals("") || nameEdit == null || nameEdit.equals("") || mailEdit.equals("") || mailEdit == null) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error2")));
} else if (!pwdEdit1.equals(pwdEdit2)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error3")));
} else if (new UserHelper().isUserLoginExist(connect.getPoolConnexion(), nameEdit)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error5")));
} else {
UserHelper userHelper = new UserHelper();
Connection conn;
conn = connect.getPoolConnexion().getConnection();
conn.setAutoCommit(false);
int idUser = -1;
if (userHelper.isUserMailExist(conn, mailEdit)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.info7")));
} else {
try {
// Cas de création de SuperAdmin
if (user.getIdRole() == 1) {
// ajout de l'utilisateur
if (!userHelper.addUser(conn, nameEdit, mailEdit, MD5Password.getEncodedPassword(pwdEdit1), roleEdit)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
// récupération de l'Id du User
idUser = userHelper.getIdUser(conn, nameEdit);
if (idUser == -1) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
// ajout du role
if (!userHelper.addRole(conn, idUser, roleEdit, idTheso, "")) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
}
// Cas de création d'admin (par thésaurus)
if (user.getIdRole() == 2) {
// ajout de l'utilisateur
if (!userHelper.addUser(conn, nameEdit, mailEdit, MD5Password.getEncodedPassword(pwdEdit1), roleEdit)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
// récupération de l'Id du User
idUser = userHelper.getIdUser(conn, nameEdit);
if (idUser == -1) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
// ajout du role
if (!userHelper.addRole(conn, idUser, roleEdit, idTheso, "")) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
}
// mise à jour des alerts mails pour l'utilisateur
if (alertmail) {
if (idUser != -1)
if (!userHelper.setAlertMailForUser(conn, idUser, true)) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
conn.rollback();
conn.close();
return;
}
}
userHelper.updateAddUserHistorique(conn, nameEdit);
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(CurrentUser.class.getName()).log(Level.SEVERE, null, ex);
}
mailEdit = "";
pwdEdit1 = "";
pwdEdit2 = "";
nameEdit = "";
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("user.info3")));
}
}
}
Aggregations