/
EMailValidator.java
58 lines (48 loc) · 1.88 KB
/
EMailValidator.java
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
/*
* Copyright (C) 2010-2023 Structr GmbH
*
* This file is part of Structr <http://structr.org>.
*
* Structr is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Structr is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Structr. If not, see <http://www.gnu.org/licenses/>.
*/
package org.structr.common;
import org.structr.common.error.ErrorBuffer;
import org.structr.common.error.SemanticErrorToken;
import org.structr.core.app.StructrApp;
import org.structr.core.graph.NodeInterface;
import org.structr.core.property.PropertyKey;
import org.structr.schema.Validator;
/**
*/
public class EMailValidator implements Validator {
@Override
public boolean isValid(final NodeInterface node, final ErrorBuffer errorBuffer) {
final Class type = node.getClass();
final PropertyKey<String> eMail = StructrApp.key(type, "eMail");
boolean valid = true;
valid &= ValidationHelper.isValidUniqueProperty(node, eMail, errorBuffer);
final String _eMail = (String)node.getProperty(eMail);
if (_eMail != null) {
// verify that the address contains at least the @ character,
// which is a requirement for it to be distinguishable from
// a user name, so email addresses can less easily interfere
// with user names.
if (!_eMail.contains("@")) {
valid = false;
errorBuffer.add(new SemanticErrorToken(type.getSimpleName(), eMail, "must_contain_at_character", _eMail));
}
}
return valid;
}
}