Search in sources :

Example 1 with CptMinMailBean

use of fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean in project esup-ecandidat by EsupPortail.

the class CandidatController method editMail.

/**
 * Edite le mail du candidat
 * @param cptMin
 */
public void editMail(final CompteMinima cptMin) {
    /* Verrou --> normalement le lock est géré en amont mais on vérifie qd même */
    final String lockError = getLockError(cptMin, ConstanteUtils.LOCK_INFOS_PERSO);
    if (lockError != null) {
        Notification.show(lockError, Type.WARNING_MESSAGE);
        return;
    }
    final CandidatCompteMinimaWindow cptMinWin = new CandidatCompteMinimaWindow(cptMin, true, false);
    cptMinWin.addCompteMinimaWindowListener(e -> {
        cptMin.setTemValidMailCptMin(false);
        compteMinimaRepository.save(cptMin);
        final String base64encodedString = Base64.getUrlEncoder().withoutPadding().encodeToString(cptMin.getNumDossierOpiCptMin().getBytes());
        final String path = loadBalancingController.getApplicationPathForCandidat() + "rest/candidat/mail/" + base64encodedString;
        final CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(), cptMin.getNumDossierOpiCptMin(), null, path, campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)), null);
        mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN_MOD_MAIL, mailBean, null, getCodLangueCptMin(cptMin));
        Notification.show(applicationContext.getMessage("compteMinima.editmail.notif", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
        MainUI.getCurrent().reconstructMainMenu();
    });
    UI.getCurrent().addWindow(cptMinWin);
}
Also used : CptMinMailBean(fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean) CandidatCompteMinimaWindow(fr.univlorraine.ecandidat.views.windows.CandidatCompteMinimaWindow)

Example 2 with CptMinMailBean

use of fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean in project esup-ecandidat by EsupPortail.

the class CandidatController method saveCompteMinima.

/**
 * Enregistre un compte à minima
 * @param  cptMin
 * @return        le compte enregistré
 */
private CompteMinima saveCompteMinima(CompteMinima cptMin) {
    // Generateur de mot de passe
    final PasswordHashService passwordHashUtils = PasswordHashService.getCurrentImplementation();
    final Campagne campagne = campagneController.getCampagneActive();
    if (campagne == null) {
        Notification.show(applicationContext.getMessage("compteMinima.camp.error", null, UI.getCurrent().getLocale()), Type.ERROR_MESSAGE);
        return null;
    }
    cptMin.setCampagne(campagne);
    final String prefix = parametreController.getPrefixeNumDossCpt();
    Integer sizeNumDossier = ConstanteUtils.GEN_SIZE;
    if (prefix != null) {
        sizeNumDossier = sizeNumDossier - prefix.length();
    }
    String numDossierGenere = passwordHashUtils.generateRandomPassword(sizeNumDossier, ConstanteUtils.GEN_NUM_DOSS);
    while (isNumDossierExist(numDossierGenere)) {
        numDossierGenere = passwordHashUtils.generateRandomPassword(sizeNumDossier, ConstanteUtils.GEN_NUM_DOSS);
    }
    if (prefix != null) {
        numDossierGenere = prefix + numDossierGenere;
    }
    cptMin.setNumDossierOpiCptMin(numDossierGenere);
    final String pwd = passwordHashUtils.generateRandomPassword(ConstanteUtils.GEN_SIZE, ConstanteUtils.GEN_PWD);
    try {
        cptMin.setPwdCptMin(passwordHashUtils.createHash(pwd));
        cptMin.setTypGenCptMin(passwordHashUtils.getType());
    } catch (final CustomException e) {
        Notification.show(applicationContext.getMessage("compteMinima.pwd.error", null, UI.getCurrent().getLocale()), Type.ERROR_MESSAGE);
        return null;
    }
    /* La date avant destruction */
    LocalDateTime datValid = LocalDateTime.now();
    final Integer nbJourToKeep = parametreController.getNbJourKeepCptMin();
    datValid = datValid.plusDays(nbJourToKeep);
    datValid = LocalDateTime.of(datValid.getYear(), datValid.getMonth(), datValid.getDayOfMonth(), 23, 0, 0);
    cptMin.setDatFinValidCptMin(datValid);
    try {
        cptMin = saveBaseCompteMinima(cptMin, campagne);
    } catch (final Exception ex) {
        logger.error(applicationContext.getMessage("compteMinima.numdossier.error", null, UI.getCurrent().getLocale()) + " numDossier=" + numDossierGenere, ex);
        Notification.show(applicationContext.getMessage("compteMinima.numdossier.error", null, UI.getCurrent().getLocale()), Type.ERROR_MESSAGE);
        return null;
    }
    final CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(), cptMin.getNumDossierOpiCptMin(), pwd, getLienValidation(numDossierGenere), campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)), formatterDate.format(cptMin.getDatFinValidCptMin()));
    mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN, mailBean, null, getCodLangueCptMin(cptMin));
    Notification.show(applicationContext.getMessage("compteMinima.create.success", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
    return cptMin;
}
Also used : LocalDateTime(java.time.LocalDateTime) CptMinMailBean(fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean) PasswordHashService(fr.univlorraine.ecandidat.services.security.PasswordHashService) CustomException(fr.univlorraine.ecandidat.utils.CustomException) Campagne(fr.univlorraine.ecandidat.entities.ecandidat.Campagne) CustomException(fr.univlorraine.ecandidat.utils.CustomException) SiScolException(fr.univlorraine.ecandidat.services.siscol.SiScolException)

Example 3 with CptMinMailBean

use of fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean in project esup-ecandidat by EsupPortail.

the class CandidatController method initPasswordOrActivationCode.

/**
 * Initialise le pwd du compte
 * @param  eMail
 * @return       true si tout se passe bien
 */
public Boolean initPasswordOrActivationCode(final String eMail, final String mode) {
    // Generateur de mot de passe
    final PasswordHashService passwordHashUtils = PasswordHashService.getCurrentImplementation();
    final CompteMinima cptMin = searchCptMinByEMail(eMail);
    if (cptMin == null) {
        Notification.show(applicationContext.getMessage("compteMinima.id.oublie.mail.err", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
        return false;
    }
    final String pwd = passwordHashUtils.generateRandomPassword(ConstanteUtils.GEN_SIZE, ConstanteUtils.GEN_PWD);
    try {
        cptMin.setPwdCptMin(passwordHashUtils.createHash(pwd));
        cptMin.setTypGenCptMin(passwordHashUtils.getType());
    } catch (final CustomException e) {
        Notification.show(applicationContext.getMessage("compteMinima.pwd.error", null, UI.getCurrent().getLocale()), Type.ERROR_MESSAGE);
        return false;
    }
    compteMinimaRepository.save(cptMin);
    if (mode.equals(ConstanteUtils.FORGOT_MODE_ID_OUBLIE)) {
        final CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(), cptMin.getNumDossierOpiCptMin(), pwd, null, campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)), null);
        mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN_ID_OUBLIE, mailBean, null, getCodLangueCptMin(cptMin));
        Notification.show(applicationContext.getMessage("compteMinima.id.oublie.success", null, UI.getCurrent().getLocale()), Type.HUMANIZED_MESSAGE);
    } else {
        final CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(), cptMin.getNumDossierOpiCptMin(), pwd, getLienValidation(cptMin.getNumDossierOpiCptMin()), campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)), formatterDate.format(cptMin.getDatFinValidCptMin()));
        mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN, mailBean, null, getCodLangueCptMin(cptMin));
        Notification.show(applicationContext.getMessage("compteMinima.code.oublie.success", null, UI.getCurrent().getLocale()), Type.HUMANIZED_MESSAGE);
    }
    return true;
}
Also used : CompteMinima(fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima) CptMinMailBean(fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean) PasswordHashService(fr.univlorraine.ecandidat.services.security.PasswordHashService) CustomException(fr.univlorraine.ecandidat.utils.CustomException)

Example 4 with CptMinMailBean

use of fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean in project esup-ecandidat by EsupPortail.

the class CandidatController method deleteCandidatCnil.

/**
 * Supprime un candidat
 * @param cptMin
 * @param listener
 */
public void deleteCandidatCnil(final CompteMinima cptMin, final CandidatAdminListener listener) {
    final CandidatAdminDeleteWindow win = new CandidatAdminDeleteWindow();
    win.setWidth(850, Unit.PIXELS);
    String message = applicationContext.getMessage("candidat.delete.window", null, UI.getCurrent().getLocale());
    if (cptMin.getCandidat() != null) {
        message = message + "<br/><br/>";
        if (cptMin.getCandidat().getCandidatures().size() > 0) {
            message = message + applicationContext.getMessage("candidat.delete.cnil.hascand", null, UI.getCurrent().getLocale());
            message = message + "<ul>";
            for (final Candidature cand : cptMin.getCandidat().getCandidatures()) {
                // définition du statut
                String statut = cand.getTypeStatut().getLibTypStatut();
                if (cand.getDatAnnulCand() != null) {
                    statut = applicationContext.getMessage("cancel.label", null, UI.getCurrent().getLocale());
                }
                // definition du libellé opi
                String opi = applicationContext.getMessage("candidat.delete.cnil.cand.noopi", null, UI.getCurrent().getLocale());
                if (cand.getOpi() != null && cand.getOpi().getDatPassageOpi() != null) {
                    opi = applicationContext.getMessage("candidat.delete.cnil.cand.hasopi", new Object[] { formatterDate.format(cand.getOpi().getDatPassageOpi()) }, UI.getCurrent().getLocale());
                }
                message = message + applicationContext.getMessage("candidat.delete.cnil.cand", new Object[] { cand.getFormation().getLibForm(), statut, opi }, UI.getCurrent().getLocale());
            }
            message = message + "</ul>";
        } else {
            message = message + applicationContext.getMessage("candidat.delete.cnil.nocand", null, UI.getCurrent().getLocale());
        }
    }
    win.setMessage(message);
    win.addDeleteCandidatWindowListener(sendMail -> {
        try {
            if (cptMin.getCandidat() != null) {
                for (final Candidature candidature : cptMin.getCandidat().getCandidatures()) {
                    for (final PjCand pjCand : candidature.getPjCands()) {
                        candidaturePieceController.removeFileToPj(pjCand);
                    }
                }
            }
            compteMinimaRepository.delete(cptMin);
            if (sendMail) {
                final CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(), cptMin.getNumDossierOpiCptMin(), null, null, campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)), null);
                mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN_DELETE, mailBean, null, getCodLangueCptMin(cptMin));
            }
            userController.setNoDossierNomCandidat(null);
            Notification.show(applicationContext.getMessage("candidat.delete.ok", null, UI.getCurrent().getLocale()), Type.TRAY_NOTIFICATION);
            MainUI.getCurrent().buildMenuGestCand(false);
        } catch (final Exception ex) {
            logger.error(applicationContext.getMessage("candidat.delete.error", null, UI.getCurrent().getLocale()), ex);
            Notification.show(applicationContext.getMessage("candidat.delete.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
            return;
        }
    });
    UI.getCurrent().addWindow(win);
}
Also used : CptMinMailBean(fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean) PjCand(fr.univlorraine.ecandidat.entities.ecandidat.PjCand) Candidature(fr.univlorraine.ecandidat.entities.ecandidat.Candidature) CustomException(fr.univlorraine.ecandidat.utils.CustomException) SiScolException(fr.univlorraine.ecandidat.services.siscol.SiScolException) CandidatAdminDeleteWindow(fr.univlorraine.ecandidat.views.windows.CandidatAdminDeleteWindow)

Example 5 with CptMinMailBean

use of fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean in project esup-ecandidat by EsupPortail.

the class CandidatController method deleteCandidat.

/**
 * Supprime un candidat
 * @param cptMin
 * @param listener
 */
public void deleteCandidat(final CompteMinima cptMin, final CandidatAdminListener listener) {
    if (cptMin.getCandidat() != null && cptMin.getCandidat().getCandidatures().size() > 0) {
        Notification.show(applicationContext.getMessage("candidat.delete.has.candidature", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
        return;
    }
    final CandidatAdminDeleteWindow win = new CandidatAdminDeleteWindow(applicationContext.getMessage("candidat.delete.window", null, UI.getCurrent().getLocale()));
    win.addDeleteCandidatWindowListener(sendMail -> {
        try {
            deleteCandidatBase(cptMin);
            if (sendMail) {
                final CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(), cptMin.getNumDossierOpiCptMin(), null, null, campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)), null);
                mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN_DELETE, mailBean, null, getCodLangueCptMin(cptMin));
            }
            userController.setNoDossierNomCandidat(null);
            Notification.show(applicationContext.getMessage("candidat.delete.ok", null, UI.getCurrent().getLocale()), Type.TRAY_NOTIFICATION);
            MainUI.getCurrent().buildMenuGestCand(false);
        } catch (final Exception ex) {
            logger.error(applicationContext.getMessage("candidat.delete.error", null, UI.getCurrent().getLocale()), ex);
            Notification.show(applicationContext.getMessage("candidat.delete.error", null, UI.getCurrent().getLocale()), Type.WARNING_MESSAGE);
            return;
        }
    });
    UI.getCurrent().addWindow(win);
}
Also used : CptMinMailBean(fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean) CustomException(fr.univlorraine.ecandidat.utils.CustomException) SiScolException(fr.univlorraine.ecandidat.services.siscol.SiScolException) CandidatAdminDeleteWindow(fr.univlorraine.ecandidat.views.windows.CandidatAdminDeleteWindow)

Aggregations

CptMinMailBean (fr.univlorraine.ecandidat.utils.bean.mail.CptMinMailBean)5 CustomException (fr.univlorraine.ecandidat.utils.CustomException)4 SiScolException (fr.univlorraine.ecandidat.services.siscol.SiScolException)3 PasswordHashService (fr.univlorraine.ecandidat.services.security.PasswordHashService)2 CandidatAdminDeleteWindow (fr.univlorraine.ecandidat.views.windows.CandidatAdminDeleteWindow)2 Campagne (fr.univlorraine.ecandidat.entities.ecandidat.Campagne)1 Candidature (fr.univlorraine.ecandidat.entities.ecandidat.Candidature)1 CompteMinima (fr.univlorraine.ecandidat.entities.ecandidat.CompteMinima)1 PjCand (fr.univlorraine.ecandidat.entities.ecandidat.PjCand)1 CandidatCompteMinimaWindow (fr.univlorraine.ecandidat.views.windows.CandidatCompteMinimaWindow)1 LocalDateTime (java.time.LocalDateTime)1