///////////////////////////////////////////////////// //Projet : Gestion des compétences //Classe : PageLogin //Fichier : PageLogin.java //Crée le : 05/10/07 //Modifié le : 23/10/2007 //Cette classe est la page de login de l'application ///////////////////////////////////////////////////// package com.labinal.client.ihm; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.FlexTable; import com.gwtext.client.core.EventObject; import com.gwtext.client.core.Position; import com.gwtext.client.widgets.Button; import com.gwtext.client.widgets.MessageBox; import com.gwtext.client.widgets.event.ButtonListenerAdapter; import com.gwtext.client.widgets.event.KeyListener; import com.gwtext.client.widgets.form.Form; import com.gwtext.client.widgets.form.FormConfig; import com.gwtext.client.widgets.form.TextField; import com.gwtext.client.widgets.form.TextFieldConfig; import com.gwtext.client.widgets.layout.ContentPanel; import com.labinal.client.Conteneur; import com.labinal.client.dto.DTOInfoUser; import com.labinal.client.ihm.elementsTemplate.PageInterface; import com.labinal.client.ihm.elementsTemplate.extConfig.MyButtonConfig; import com.labinal.client.widgets.Composite; import com.labinal.client.widgets.HorizontalPanel; import com.labinal.client.widgets.VerticalPanel; /** * Cette classe permet de gérer la phase de login de l'application * - Authentification * - Stockage des informations de l'utilisateur dans l'objet complexe infoUser * - informations provenants de l'annuaire LDAP * - infoSite * - collectionDroits */ public class PageLogin extends Composite implements PageInterface{ private static PageLogin instancy; private FlexTable widgetComposite = new FlexTable(); /** * Cette méthode est le constructeur de la classe * */ private PageLogin() { super(); initWidget(widgetComposite); setOrientation(); widgetComposite.getFlexCellFormatter().setWidth(0, 0, "100%"); widgetComposite.getFlexCellFormatter().setHeight(0,0,"100%"); widgetComposite.getCellFormatter().setHorizontalAlignment(0, 0, HorizontalPanel.ALIGN_CENTER); widgetComposite.getCellFormatter().setVerticalAlignment(0, 0, VerticalPanel.ALIGN_MIDDLE); widgetComposite.setWidget(0, 0, getIdentificationPanel()); } public ContentPanel getIdentificationPanel(){ final Form form = new Form(new FormConfig() { { setLabelAlign(Position.RIGHT); setWidth(400); setHeader(Conteneur.get().getConstants().labelIdentification()+"\n\n"); setLabelWidth(100); setSurroundWithBox(true); } }); form.add(new TextField(new TextFieldConfig() { { setFieldLabel(Conteneur.get().getConstants().user()); setName("username"); setWidth(175); setAllowBlank(false); } })); form.add(new TextField(new TextFieldConfig() { { setFieldLabel(Conteneur.get().getConstants().password()); setName("password"); setWidth(175); setPassword(true); setAllowBlank(false); } })); Button connexion = new Button(new MyButtonConfig()); connexion.setText(Conteneur.get().getConstants().boutonConnexion()); connexion.addButtonListener(getButtonListener(form)); form.addButton(connexion); // key Listener sur le bouton entrer form.getEl().addKeyListener(13, new KeyListener(){ public void onKey(int key, EventObject e) { identification(form.findField("username").getValueAsString(),form.findField("password").getValueAsString()); } }); form.render(); ContentPanel contentPanelIdentification = new ContentPanel(); contentPanelIdentification.add(form); return contentPanelIdentification; } public ButtonListenerAdapter getButtonListener(final Form form){ return new ButtonListenerAdapter() { public void onClick(Button button, EventObject e) { identification(form.findField("username").getValueAsString(),form.findField("password").getValueAsString()); } }; } /** * Méthode permettant l'affichage de la fenêtre principale de l'application contenant le titre, * le bandeau, le message de bienvenue, le menu, la barre de statut et la page * affichant la rubrique demandée **/ public void afficherEcranAccueil(String login) { //Création du menu de l'application avec restrictions selon les droits de l'utilisateur Conteneur.get().CreateMenu(); Conteneur.get().getHautDePage().setDeconnexionVisible(true); Conteneur.get().getHautDePage().getBienvenue().setVisible(true); if (Conteneur.get().getDivision() != null) { Conteneur.get().getHautDePage().getDivision().setVisible(true); Conteneur.get().getHautDePage().setDivision(Conteneur.get().getDivision()); } Conteneur.get().getHautDePage().setUtilisateur(Conteneur.get().getUser().getPrenom() + " " + Conteneur.get().getUser().getNom(), login); Conteneur.get().setPage("pageAccueil", PageAccueil.getInstance()); Conteneur.get().afficherMenu(true); Conteneur.get().afficherStatut(true); // // IAS - DEBUG // // REPRODUCT ERROR CLIENT // String currentDivision = Conteneur.get().getDivision(); // if (currentDivision == null) // Conteneur.redirect("Conteneur.html"); // else // Conteneur.redirect("Conteneur.html?division="+currentDivision); // // END REPRODUCT ERROR CLIENT // // } /** * return instancy. * @return instancy. */ public static PageLogin getInstance(){ if (null == instancy){ instancy = new PageLogin(); } return instancy; } public void setOrientation(){ // TODO : il vous faudra peut etre ajuster la position des masques dans la feuille de style default.css if (Conteneur.get().getOrientation().compareTo("horizontal")==0) widgetComposite.setStyleName("gwt-PageHorizontaleLogin"); else widgetComposite.setStyleName("gwt-PageVerticaleLogin"); } /** * Gestion de l'identification * @param username * @param password */ private void identification(final String username, String password){ // Conteneur.maskPage(); /** controle des login et mot de passe * si ok, affiche la page principale ainsi que le menu, * la barre de statut et le titre **/ Conteneur.get().getServiceAuthentification().identification(username, password, Conteneur.get().getDivision(), Conteneur.get().getLocale(), new AsyncCallback() { public void onFailure(Throwable arg0) { Conteneur.unMaskPage(); MessageBox.alert(Conteneur.get().getConstants().erreurAuth(), Conteneur.get().getConstants().AUTH002()); } // Arg0 is connected user DTOInfoUser entity public void onSuccess(Object arg0) { // try { // if DTOInfoUser != null if(arg0!=null) { Conteneur.unMaskPage(); DTOInfoUser dtoInfoUser = (DTOInfoUser)(arg0); if ((dtoInfoUser.getIsCanalab() == null) || (dtoInfoUser.getListDroits().isEmpty()) ) { // MessageBox.alert(Conteneur.get().getConstants().erreurAuth(), Conteneur.get().getConstants().AUTH004()); } else { Conteneur.get().setUser(dtoInfoUser); afficherEcranAccueil(username); Conteneur.get().Trace("debug", "Connection OK !!!" ); } } else { Conteneur.unMaskPage(); MessageBox.alert(Conteneur.get().getConstants().erreurAuth(), Conteneur.get().getConstants().AUTH001()); } } catch (ClassCastException classCastEx){ Conteneur.get().Trace("error", "IDENTIFICATION - ERROR - ClassCastException : " + classCastEx.getCause() + "\n" + classCastEx.getMessage()); } catch (NullPointerException nullPointertEx){ Conteneur.get().Trace("error", "IDENTIFICATION - ERROR - NullPointerException : " + nullPointertEx.getCause() + "\n" + nullPointertEx.getMessage()); } catch (Throwable e) { Conteneur.get().Trace("error", "IDENTIFICATION - ERROR - Throwable : " + e.getCause() + "\n" + e.getMessage()); } } }); } }