本文整理汇总了Java中play.data.validation.Validation.hasErrors方法的典型用法代码示例。如果您正苦于以下问题:Java Validation.hasErrors方法的具体用法?Java Validation.hasErrors怎么用?Java Validation.hasErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.data.validation.Validation
的用法示例。
在下文中一共展示了Validation.hasErrors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ftpserver_export_user_sessions
import play.data.validation.Validation; //导入方法依赖的package包/类
@Check("adminFtpServer")
public static void ftpserver_export_user_sessions(@Required String user_session_ref) throws Exception {
if (Validation.hasErrors()) {
notFound();
}
response.contentType = "text/csv";
String contentDisposition = "%1$s; filename*=UTF-8''%2$s; filename=\"%2$s\"";
response.setHeader("Content-Disposition", String.format(contentDisposition, "attachment", "FTP_activity_" + Loggers.dateFilename(System.currentTimeMillis()) + ".csv"));
try {
FTPActivity.getAllUserActivitiesCSV(user_session_ref, response.out);
} catch (Exception e) {
if (e.getMessage().equals("noindex")) {
renderText("(No data)");
}
}
IOUtils.closeQuietly(response.out);
}
示例2: save
import play.data.validation.Validation; //导入方法依赖的package包/类
public static void save(@Required(message = "validation.requiere.email") String email,
@Required(message = "validation.requiere.name") String name,
@Required String preferredLang, String twitter, String organization,
String timeZone, String web) {
checkAuthenticity();
User current = getCurrentUser();
User user = DarwinFactory.getInstance().loadUser(email);
if (user != null && !Validation.hasErrors()) {
if (current.getEmail().equals(email) || current.isAdminUser()) {
Logger.debug("Edit profile "+email+", name="+name+", preferredLang="+preferredLang);
user.setName(name);
user.setPreferredLang(preferredLang);
// Save SinfonierUser fields
SinfonierUser sinfonierUser = (SinfonierUser) user.getImplementation();
sinfonierUser.setTwitter(twitter);
sinfonierUser.setOrganization(organization);
sinfonierUser.setTimeZoneID(timeZone);
sinfonierUser.setWeb(web);
user.save();
// TODO: Change render when Bug #19153 is fixed in Darwin library.
//showUserProfile(email);
render("Profile/index.html", user);
} else {
forbidden();
}
} else if (Validation.hasErrors()) {
params.flash();
render("Profile/edit.html", user);
} else {
notFound();
}
}
示例3: authenticate
import play.data.validation.Validation; //导入方法依赖的package包/类
public static void authenticate(@Required String username, String password, boolean remember) throws Throwable {
if (!Play.mode.isDev()) {
Validation.required("password", password);
} else {
if (password == null) {
password = "";
}
}
if (Validation.hasErrors()) {
badRequestJson();
}
// Check tokens
String userId = (String) Security.invoke("authenticate", username, password);
if (userId == null) {
validation.addError("global", "login.error");
forbiddenJson();
}
// Mark user as connected
session.put("username", userId);
// Remember if needed
if (remember) {
Date expiration = new Date();
String duration = Play.configuration.getProperty("secure.rememberme.duration","30d");
expiration.setTime(expiration.getTime() + Time.parseDuration(duration) * 1000 );
response.setCookie("rememberme", Crypto.sign(username + "-" + expiration.getTime()) + "-" + username + "-" + expiration.getTime(), duration);
}
Security.invoke("afterAuthenticate", userId);
okJson();
}
示例4: _ifErrors
import play.data.validation.Validation; //导入方法依赖的package包/类
public static void _ifErrors(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
if (Validation.hasErrors()) {
body.call();
TagContext.parent().data.put("_executeNextElse", false);
} else {
TagContext.parent().data.put("_executeNextElse", true);
}
}
示例5: changePassword
import play.data.validation.Validation; //导入方法依赖的package包/类
public static void changePassword(String email,
@Required(message = "validation.required.profile.password")
@Password @Equals(value="newPassword2", message = "validation.match.profile.password")
String newPassword1,
@Required(message = "validation.required.profile.password")
String newPassword2)
throws SinfonierException {
checkAuthenticity();
User current = getCurrentUser();
User user = DarwinFactory.getInstance().loadUser(email);
if (user != null) {
if (!Validation.hasErrors()) {
if (current.getEmail().equals(email) || current.isAdminUser()) {
Logger.debug("Change password "+email);
try {
user.changePassword(newPassword1);
} catch (PasswordConstraintViolationException e) {
throw new SinfonierException(SinfonierError.PASSWORD_CONSTRAINS, e);
}
user.save();
// TODO: Change render when Bug #19153 is fixed in Darwin library.
//showUserProfile(email);
render("Profile/index.html", user);
} else {
forbidden();
}
} else {
for (play.data.validation.Error error : Validation.errors()) {
Logger.error(error.message());
}
params.flash();
// TODO: Change redirect when Bug #19469 is fixed in Darwin library.
//showUserProfile(email);
render("Profile/index.html", user);
}
} else {
notFound();
}
}
示例6: JavascriptRessource
import play.data.validation.Validation; //导入方法依赖的package包/类
public static void JavascriptRessource(@Required String name, Long suffix_date) {
if (Validation.hasErrors()) {
badRequest();
}
File ressource_file = JSSourceManager.getPhysicalFileFromRessourceName(name);
if (ressource_file == null) {
notFound();
}
long last_modified = ressource_file.lastModified();
String etag = last_modified + "--";
if (suffix_date != null) {
if (suffix_date > 0) {
response.setHeader("Cache-Control", "max-age=864000");
}
}
if (request.isModified(etag, last_modified) == false) {
response.setHeader("Etag", etag);
notModified();
}
if (FilenameUtils.isExtension(ressource_file.getName(), "gz")) {
if (request.headers.containsKey("accept-encoding") == false) {
badRequest("// Your browser don't accept encoding files.");
}
if (request.headers.get("accept-encoding").value().indexOf("gzip") == -1) {
badRequest("// Your browser don't accept GZipped files.");
}
response.setHeader("Content-Encoding", "gzip");
}
response.setHeader("Content-Length", ressource_file.length() + "");
response.setHeader("Content-Type", "text/javascript");
response.setHeader("Etag", etag);
response.setHeader("Last-Modified", Utils.getHttpDateFormatter().format(new Date(last_modified)));
try {
FileUtils.copyFile(ressource_file, response.out);
} catch (IOException e) {
Loggers.Play_JSSource.error("Can't response (send) js file: " + ressource_file, e);
notFound();
}
ok();
}
示例7: authenticate
import play.data.validation.Validation; //导入方法依赖的package包/类
public static void authenticate(@Required String username, @Required String password, String domainidx, boolean remember) throws Throwable {
String remote_address = request.remoteAddress;
if (Validation.hasErrors()) {
rejectUser();
return;
}
if (AccessControl.validThisIP(remote_address) == false) {
Loggers.Play.warn("Refuse IP addr for user username: " + username + ", domainidx: " + domainidx + ", remote_address: " + remote_address);
rejectUser();
return;
}
UserNG authuser = null;
if (MyDMAM.getPlayBootstrapper().getAuth().isForceSelectDomain()) {
String domain_name = null;
try {
domain_name = MyDMAM.getPlayBootstrapper().getAuth().getDeclaredDomainList().get(Integer.valueOf(domainidx));
} catch (Exception e) {
}
authuser = MyDMAM.getPlayBootstrapper().getAuth().authenticateWithThisDomain(remote_address, username.trim().toLowerCase(), password, domain_name, Lang.getLocale().getLanguage());
} else {
authuser = MyDMAM.getPlayBootstrapper().getAuth().authenticate(remote_address, username.trim().toLowerCase(), password, Lang.getLocale().getLanguage());
}
if (authuser == null) {
Loggers.Play.error("Can't login username: " + username + ", domainidx: " + domainidx + ", " + getUserSessionInformation());
AccessControl.failedAttempt(remote_address, username);
rejectUser();
}
username = authuser.getKey();
AccessControl.releaseIP(remote_address);
Session.current().put("username", Crypto.encryptAES(username));
Cache.set("user:" + username + ":privileges", authuser.getUser_groups_roles_privileges(), MyDMAM.getPlayBootstrapper().getSessionTTL());
String long_name = authuser.getFullname();
if (long_name == null) {
long_name = authuser.getName();
}
Loggers.Play.info(long_name + " has a successful authentication, with privileges: " + getSessionPrivileges().toString() + ". User key: " + username);
redirect("Application.index");
}