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
| public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
AjouterAdminForm formbean = (AjouterAdminForm) form;
ListeAdmin l = new ListeAdmin();
boolean stat = true;
if (formbean.getCompte() == null) {
formbean.setCompte_error();
stat = false;
}
else
{
while(l.résultat.next())
{
if (formbean.getCompte().equalsIgnoreCase(l.compte()))
{
formbean.setCompte_error_2();
stat=false;
}
}
}
if (formbean.getNom_admin() == null) {
formbean.setNom_admin_error();
stat = false;
}
if (formbean.getMot_de_passe().length() < 4) {
formbean.setMot_de_passe_error();
stat = false;
}
if (!formbean.getMot_de_passe().equals(formbean.getMot_de_passe_2())) {
formbean.setMot_de_passe_error2();
stat = false;
}
if (!testEmail(formbean.getAdd_mail()))
{ formbean.setAdd_mail_error();
stat=false;
}
if (stat) {
String req="INSERT INTO admin (nom_admin,compte,mot_de_passe,mail) VALUES (";
req=req+"'"+formbean.getNom_admin()+"',";
req=req+"'"+formbean.getCompte()+"',";
req=req+"'"+formbean.getMot_de_passe()+"',";
req=req+"'"+formbean.getAdd_mail()+"');";
ConnexionBD con=new ConnexionBD();
con.miseAJour(req);
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILLURE);
}
}
public boolean testEmail(String email) {
email = email.toLowerCase();
String charOk = "abcdefghijklmnopqrstuvwxyz0123456789_@.";
boolean test = false;
if (email.length() < 8) {
return false;
}// Si l'email fait moins de 8 caractéres
if (email.indexOf('@') < 0) {
return false;
}// Si l'email ne contient pas d'@'
if (email.indexOf('.') < 0) {
return false;
}// Si l'email ne contient pas de '.'
if (((email.indexOf('.', (((email.indexOf('@')) + 1))))) == (email.indexOf('@') + 1)) {
return false;
}// Si l'email as un '.' apres l'@
if (((email.indexOf('.', (((email.indexOf('@')) - 1))))) == (email.indexOf('@') - 1)) {
return false;
}// Si l'email as un '.' avant l'@
if ((email.indexOf('.')) == 0) {
return false;
}// Si l'email as un '.' au debut
if ((email.charAt((email.length() - 1)) == '.')) {
return false;
}// Si l'email a un '.' a la fin
if ((email.indexOf('@')) == 0) {
return false;
}// Si l'email as un '@' au debut
if ((email.charAt((email.length() - 1)) == '@')) {
return false;
}// Si l'email a un '@' a la fin
// Si l'email n'a pas de '.' un peu apres le '@'
boolean tmp = false;
for (int i = 1; i < (email.length() - (email.indexOf('@'))); i++) {
if (email.charAt((email.indexOf('@')) + i) == '.') {
tmp = true;
i = (email.length());
}
}
if (tmp == false) {
return false;
}
// Si l'email a plusieurs '@'
for (int i = 0; i < email.length(); i++) {
if (email.charAt(i) == '@') {
for (int j = i + 1; j < email.length(); j++) {
if (email.charAt(j) == '@') {
return false;
}
}
}
}
// Si l'email a 2 '.' d'affilé
for (int i = 0; i < (email.length() - 1); i++) {
if ((email.charAt(i) == '.') && (email.charAt(i + 1) == '.')) {
return false;
}
}
// Si l'email contient un caractére interdis
for (int i = 0; i < email.length(); i++) {
for (int j = 0; j < charOk.length(); j++) {
if ((email.charAt(i)) == (charOk.charAt(j))) {
test = true;
j = (charOk.length());
} else {
test = false;
}
}
if (test == false) {
return test;
}
}
return test;
}
} |
Partager