1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.imca.web.backingbeans;
17
18 import javax.faces.context.FacesContext;
19 import javax.mail.MessagingException;
20 import net.sf.imca.services.LoginRegisterService;
21 import net.sf.imca.model.PersonBO;
22 import net.sf.imca.model.exceptions.DataCheckingException;
23 import net.sf.imca.model.exceptions.LogInException;
24 import net.sf.imca.model.exceptions.RegistrationException;
25
26
27
28
29
30
31 public class LoginBean {
32
33 private String email = "";
34
35 private String password = "";
36
37 private String confirmPassword = "";
38
39
40
41
42 private String userFeedbackMessage = "";
43
44 private String firstName = "";
45
46 private String lastName = "";
47
48 private String countryCode = "";
49
50 public String actionLogin() {
51
52 LoginRegisterService service = new LoginRegisterService();
53 PersonBO person;
54
55 try {
56 person = service.login(email, password);
57 } catch (LogInException e) {
58 userFeedbackMessage = e.getMessage();
59 return Utils.ACTION_FAIL;
60 }
61
62 WebUser webUser = Utils.getWebUser();
63
64 webUser.setPerson(person);
65 webUser.setLogedIn(true);
66 FacesContext context = FacesContext.getCurrentInstance();
67 context.getViewRoot().setLocale(person.getLocale());
68
69 Utils.setWebUser(webUser);
70
71 return Utils.ACTION_SUCCESS;
72 }
73
74 public String actionLogout() {
75 WebUser webUser = Utils.getWebUser();
76 webUser = new WebUser();
77 Utils.setWebUser(webUser);
78 return Utils.ACTION_LOGOUT;
79 }
80
81 public String actionSendPassword() {
82 userFeedbackMessage = "";
83 LoginRegisterService service = new LoginRegisterService();
84 try {
85 service.sendPassword(email);
86 userFeedbackMessage = "Password Sent";
87 return Utils.ACTION_SUCCESS;
88 } catch (MessagingException e) {
89 userFeedbackMessage = "Error: " + e.getMessage();
90 return Utils.ACTION_FAIL;
91 } catch (DataCheckingException e) {
92 userFeedbackMessage = "Error: " + e.getMessage();
93 return Utils.ACTION_FAIL;
94 }
95 }
96
97 public String actionRegister() {
98 userFeedbackMessage = "";
99 LoginRegisterService service = new LoginRegisterService();
100 try {
101 service.register(email, password, confirmPassword,
102 countryCode, firstName, lastName);
103 userFeedbackMessage = "Registered Successfully.";
104 return actionLogin();
105 } catch (RegistrationException e) {
106 userFeedbackMessage = "Error During Registration: " + e.getMessage()
107 + email;
108 return Utils.ACTION_FAIL;
109 } catch (DataCheckingException e) {
110 userFeedbackMessage = "Error with the registration data: "
111 + e.getMessage();
112 return Utils.ACTION_FAIL;
113 }
114 }
115
116 public String getUserFeedbackMessage() {
117 return userFeedbackMessage;
118 }
119
120 public void setUserFeedbackMessage(String userFeedbackMessage) {
121 this.userFeedbackMessage = userFeedbackMessage;
122 }
123
124 public String getEmail() {
125 return email;
126 }
127
128 public void setEmail(String email) {
129 this.email = email;
130 }
131
132 public String getPassword() {
133 return password;
134 }
135
136 public void setPassword(String password) {
137 this.password = password;
138 }
139
140 public String getConfirmPassword() {
141 return confirmPassword;
142 }
143
144 public void setConfirmPassword(String confirmPassword) {
145 this.confirmPassword = confirmPassword;
146 }
147
148 public String getFirstName() {
149 return firstName;
150 }
151
152 public void setFirstName(String firstName) {
153 this.firstName = firstName;
154 }
155
156 public String getLastName() {
157 return lastName;
158 }
159
160 public void setLastName(String lastName) {
161 this.lastName = lastName;
162 }
163
164 public String getCountryCode() {
165 return countryCode;
166 }
167
168 public void setCountryCode(String countryCode) {
169 this.countryCode = countryCode;
170 }
171
172 }