1
2
3
4
5
6
7
8
9
10
11
12 package fr.hyphonem.conges.forms;
13
14 import javax.servlet.http.HttpServletRequest;
15
16 import org.apache.regexp.RE;
17 import org.apache.struts.action.ActionError;
18 import org.apache.struts.action.ActionErrors;
19 import org.apache.struts.action.ActionForm;
20 import org.apache.struts.action.ActionMapping;
21
22
23
24
25
26 public class LoginForm extends ActionForm {
27
28
29
30 private static final long serialVersionUID = 1L;
31
32 private String login;
33
34 private String password;
35
36
37
38
39 public LoginForm() {
40 super();
41 resetFields();
42 }
43
44
45
46
47
48
49
50
51
52 public void reset(ActionMapping mapping, HttpServletRequest request) {
53 resetFields();
54 }
55
56 private void resetFields() {
57 login = "";
58 password = "";
59 }
60
61 public ActionErrors validate(ActionMapping mapping,
62 HttpServletRequest request) {
63 ActionErrors errors = new ActionErrors();
64
65 if (login == null || login.equals("")) {
66 errors.add("login.required", new ActionError("login.required"));
67 }
68 if (password == null || password.equals("")) {
69 errors.add("password.required",
70 new ActionError("password.required"));
71 }
72
73
74 RE regexp = new RE("^[a-zA-Z0-9]*$");
75 if (!regexp.match(login)) {
76 errors.add("error.alnum", new ActionError("error.alnum", "login"));
77 }
78 if (!regexp.match(password)) {
79 errors.add("error.alnum",
80 new ActionError("error.alnum", "password"));
81 }
82
83 request.setAttribute("loginForm", this);
84 return errors;
85 }
86
87
88
89
90 public String getLogin() {
91 return login;
92 }
93
94
95
96
97 public String getPassword() {
98 return password;
99 }
100
101
102
103
104 public void setLogin(String string) {
105 login = string;
106 }
107
108
109
110
111 public void setPassword(String string) {
112 password = string;
113 }
114
115 }