Bonsoir ,
je veux développer une page de login pour la gestion des roles , sachant que toutes les relations et les dépendances fonctionnent parfaitement.
j'ai réussi a faire un pas avec un login prédéfini (admin,admin) mais je veux que ca récupère les donnés depuis la base ou j'ai une table personne(login,password,role) .Aussi j'ai un souci avec la redirection suivant les roles, j'ai deux projet ejb , web , merci d'avance
Class Personne ejb :
Class session PersonneImp ejb :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 package metier.entities; import java.io.Serializable; import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; @Entity public class Personne implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String researchId; private String orcidId; private String scopusAuthorId; private String firstname; private String lastname; private String login; private String password; private String email; private String tel; private String role; private String titre; public String getTitre() { return titre; } public void setTitre(String titre) { this.titre = titre; } public String getRole() { return role; } public void setRole(String role) { this.role = role; } @ManyToMany private List<Projet> projets; public List<Projet> getProjets() { return projets; } public void setProjets(List<Projet> projets) { this.projets = projets; } @OneToMany(mappedBy = "personne") private List<File> files; public List<File> getFiles() { return files; } public void setFiles(List<File> files) { this.files = files; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getResearchId() { return researchId; } public void setResearchId(String researchId) { this.researchId = researchId; } public String getOrcidId() { return orcidId; } public void setOrcidId(String orcidId) { this.orcidId = orcidId; } public String getScopusAuthorId() { return scopusAuthorId; } public void setScopusAuthorId(String scopusAuthorId) { this.scopusAuthorId = scopusAuthorId; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public Personne(String researchId, String orcidId, String scopusAuthorId, String firstname, String lastname, String login, String password, String email, String tel, String role, String titre) { super(); this.researchId = researchId; this.orcidId = orcidId; this.scopusAuthorId = scopusAuthorId; this.firstname = firstname; this.lastname = lastname; this.login = login; this.password = password; this.email = email; this.tel = tel; this.role = role; this.titre = titre; } public Personne() { super(); } public Personne(String firstname, String lastname) { super(); this.firstname = firstname; this.lastname = lastname; } }
Class MAnagedBean projet web :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 package metier.session.impl; import java.util.List; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import metier.entities.Personne; import metier.session.interfaces.IPersonneLocal; import metier.session.interfaces.IPersonneRemote; @Stateless(name = "PERSONNE") public class PersonneImpl implements IPersonneLocal, IPersonneRemote { @PersistenceContext(unitName = "UP_LABAPP") private EntityManager em; @Override public void addPersonne(Personne personne) { em.persist(personne); } @SuppressWarnings("unchecked") @Override public List<Personne> getAllPersonne() { Query req = em.createQuery("select p from Personne p"); return req.getResultList(); } @Override public Personne getPersonne(Long idP) { Personne personne = em.find(Personne.class, idP); return personne; } @Override public void removePersonne(Long idP) { Personne personne = em.find(Personne.class, idP); em.remove(personne); } @Override public void updatePersonne(Personne personne) { Personne personne1 = em.find(Personne.class, personne.getId()); personne1.setResearchId(personne.getResearchId()); personne1.setEmail(personne.getEmail()); personne1.setFirstname(personne.getFirstname()); personne1.setLastname(personne.getLastname()); personne1.setLogin(personne.getLogin()); personne1.setOrcidId(personne.getOrcidId()); personne1.setPassword(personne.getPassword()); personne1.setResearchId(personne.getResearchId()); personne1.setTel(personne.getTel()); personne1.setScopusAuthorId(personne.getScopusAuthorId()); personne1.setRole(personne.getRole()); personne1.setTitre(personne.getTitre()); em.persist(personne1); } @Override public Personne findPersonneByLogin(String l) { return null; } }
page login.xhtml web :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 package web.mb; import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.faces.model.SelectItem; import javax.faces.model.SelectItemGroup; import org.primefaces.context.RequestContext; import metier.entities.Personne; import metier.session.interfaces.IPersonneLocal; @ManagedBean(name = "personneMB") @RequestScoped public class PersonneMB { @EJB private IPersonneLocal metier; private String researchId; private String orcidId; private String scopusAuthorId; private String firstname; private String lastname; private String login; private String password; private String email; private String tel; private String role; private String titre; private List<SelectItem> titres; public void SignIn(ActionEvent event) { RequestContext context = RequestContext.getCurrentInstance(); FacesMessage message = null; boolean loggedIn = false; if(login != null && login.equals("admin") && password != null && password.equals("admin")) { loggedIn = true; message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", login); } else { loggedIn = false; message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "Invalid credentials"); } FacesContext.getCurrentInstance().addMessage(null, message); context.addCallbackParam("loggedIn", loggedIn); } @PostConstruct public void init() { SelectItemGroup titre1 = new SelectItemGroup("Chercheur IPT"); titre1.setSelectItems(new SelectItem[] { new SelectItem("Biologiste adjoint", "Biologiste adjoint"), new SelectItem("Biologiste", "Biologiste"), new SelectItem("Biologiste principal", "Biologiste principal") }); SelectItemGroup titre2 = new SelectItemGroup("Universitaire"); titre2.setSelectItems(new SelectItem[] { new SelectItem("Professeur", "Professeur"), new SelectItem("Maitre assistant", "Maitre assistant"), new SelectItem("Maitre conferences", "Maitre conferences") }); SelectItemGroup titre3 = new SelectItemGroup("Etudiant"); titre3.setSelectItems( new SelectItem[] { new SelectItem("Mastère/PFE", "Mastère/PFE"), new SelectItem("Thèse", "Thèse") }); titres = new ArrayList<SelectItem>(); titres.add(titre1); titres.add(titre2); titres.add(titre3); } public List<SelectItem> getTitres() { return titres; } public void setTitres(List<SelectItem> titres) { this.titres = titres; } public String addPersonne() { metier.addPersonne(new Personne(researchId, orcidId, scopusAuthorId, firstname, lastname, login, password, email, tel, role, titre)); return "success"; } public List<Personne> getListPersone() { return metier.getAllPersonne(); } public String removePersonne(Personne personne) { metier.removePersonne(personne.getId()); return "success"; } public Personne findPersonne(Long idP) { if (metier.getPersonne(idP) != null) System.out.println("found nom : " + firstname); else System.out.println("Not Found"); return metier.getPersonne(idP); } public String getResearchId() { return researchId; } public void setResearchId(String researchId) { this.researchId = researchId; } public String getOrcidId() { return orcidId; } public void setOrcidId(String orcidId) { this.orcidId = orcidId; } public String getScopusAuthorId() { return scopusAuthorId; } public void setScopusAuthorId(String scopusAuthorId) { this.scopusAuthorId = scopusAuthorId; } public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public String getRole() { return role; } public void setRole(String role) { this.role = role; } public String getTitre() { return titre; } public void setTitre(String titre) { this.titre = titre; } }
Code xhtml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <h:head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title><ui:define name="title">Nom de l'application - Login</ui:define></title> </h:head> <h:body> <h:form> <p:growl id="growl" sticky="true" showDetail="true" life="3000" /> <p:dialog visible="true" header="Login" widgetVar="dlg" resizable="false"> <h:panelGrid columns="2" cellpadding="5"> <h:outputLabel for="username" value="Username:" /> <p:inputText id="username" value="#{personneMB.login}" required="true" label="username" /> <h:outputLabel for="password" value="Password:" /> <p:password id="password" value="#{personneMB.password}" required="true" label="password" /> <f:facet name="footer"> <p:commandButton value="Login" update="growl" actionListener="#{personneMB.SignIn}" oncomplete="handleLoginRequest(xhr, status, args)" /> </f:facet> </h:panelGrid> </p:dialog> </h:form> <script type="text/javascript"> function handleLoginRequest(xhr, status, args) { if (args.validationFailed || !args.loggedIn) { PF('dlg').jq.effect("shake", { times : 5 }, 100); } else { PF('dlg').hide(); $('#loginLink').fadeOut(); } } </script> </h:body> </html>
Partager