use of org.structr.common.error.SemanticErrorToken in project structr by structr.
the class EMailValidator method isValid.
@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) {
// with user names.
if (!_eMail.contains("@")) {
valid = false;
errorBuffer.add(new SemanticErrorToken(type.getSimpleName(), eMail, "must_contain_at_character", _eMail));
}
}
return valid;
}
use of org.structr.common.error.SemanticErrorToken in project structr by structr.
the class User method onCreateAndModify.
// ----- public static methods -----
public static void onCreateAndModify(final User user, final SecurityContext securityContext) throws FrameworkException {
final PropertyKey skipSecurityRels = StructrApp.key(User.class, "skipSecurityRelationships");
if (user.getProperty(skipSecurityRels).equals(Boolean.TRUE) && !user.isAdmin()) {
throw new FrameworkException(422, "", new SemanticErrorToken(user.getClass().getSimpleName(), skipSecurityRels, "can_only_be_set_for_admin_accounts"));
}
if (Settings.FilesystemEnabled.getValue()) {
final PropertyKey<Folder> homeFolderKey = StructrApp.key(Folder.class, "homeFolderOfUser");
final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
// use superuser context here
final SecurityContext storedContext = user.getSecurityContext();
try {
user.setSecurityContext(SecurityContext.getSuperUserInstance());
Folder homeDir = user.getHomeDirectory();
if (homeDir == null) {
// create home directory
final App app = StructrApp.getInstance();
Folder homeFolder = app.nodeQuery(Folder.class).and(Folder.name, "home").and(parentKey, null).getFirst();
if (homeFolder == null) {
homeFolder = app.create(Folder.class, new NodeAttribute(Folder.name, "home"), new NodeAttribute(Folder.owner, null), new NodeAttribute(Folder.visibleToAuthenticatedUsers, true));
}
app.create(Folder.class, new NodeAttribute(Folder.name, user.getUuid()), new NodeAttribute(Folder.owner, user), new NodeAttribute(Folder.visibleToAuthenticatedUsers, true), new NodeAttribute(parentKey, homeFolder), new NodeAttribute(homeFolderKey, user));
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
// restore previous context
user.setSecurityContext(storedContext);
}
}
}
Aggregations