• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Required类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中play.data.validation.Required的典型用法代码示例。如果您正苦于以下问题:Java Required类的具体用法?Java Required怎么用?Java Required使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Required类属于play.data.validation包,在下文中一共展示了Required类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: save

import play.data.validation.Required; //导入依赖的package包/类
public static void save(@Required @MaxSize(45) String firstName, @Required @MaxSize(45) String lastName,
                        @MaxSize(45) @MinSize(6) @Equals(value = "passwordConfirm", message = "validation.equals.password") String password,
                        @MaxSize(45) @MinSize(6) @Equals(value = "password", message = "validation.equals.password") String passwordConfirm) {

    if (validation.hasErrors()) {
        params.flash();
        flash.error(Messages.get("form.error"));
        validation.keep();
        index();
    } else {

        User user = getUser();
        user.firstName = firstName;
        user.lastName = lastName;
        if (password!=null && !password.isEmpty()) {
            user.password = password;
        }
        user.needsPasswordReset = false;
        user.save();

        flash.success(Messages.get("form.success"));
        index();
    }
}
 
开发者ID:xandradx,项目名称:ovirt-engine-disaster-recovery,代码行数:25,代码来源:Profile.java


示例2: changePassword

import play.data.validation.Required; //导入依赖的package包/类
public static void changePassword( @Required @MaxSize(45) @MinSize(6) @Equals(value = "passwordConfirm", message = "validation.equals.password") String password,
                        @Required @MaxSize(45) @MinSize(6) @Equals(value = "password", message = "validation.equals.password") String passwordConfirm) {

    if (validation.hasErrors()) {
        params.flash();
        flash.error(Messages.get("form.error"));
        validation.keep();
        index();
    } else {

        User user = getUser();
        user.password = password;
        user.needsPasswordReset = false;
        user.save();
        flash.success(Messages.get("form.success"));
        Application.index();
    }
}
 
开发者ID:xandradx,项目名称:ovirt-engine-disaster-recovery,代码行数:19,代码来源:Profile.java


示例3: ftpserver_export_user_sessions

import play.data.validation.Required; //导入依赖的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);
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:21,代码来源:Manager.java


示例4: addNews

import play.data.validation.Required; //导入依赖的package包/类
public void addNews(@Required String path, @Required String title, @Required Date date, String tags) {
  checkAuthenticity();
  if (validation.hasErrors()) forbidden(validation.errorsMap().toString());
  WebPage.News parent = WebPage.forPath(path);
  if (parent.isStory()) parent = (WebPage.News) parent.parent();
  if (parent.isMonth()) parent = (WebPage.News) parent.parent();
  if (parent.isYear()) parent = (WebPage.News) parent.parent();

  String pathSuffix = new SimpleDateFormat("yyyy/MM/dd").format(date);
  File dir = new File(parent.dir.getRealFile(), pathSuffix);
  while (dir.exists()) dir = new File(dir.getPath() + "-1");
  dir.mkdirs();

  VirtualFile vdir = VirtualFile.open(dir);
  vdir.child("metadata.properties").write("title: " + title + "\ntags: " + defaultString(tags) + "\n");
  vdir.child("content.html").write(Messages.get("web.admin.defaultContent"));

  WebPage.News page = WebPage.forPath(vdir);
  redirect(page.path);
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:21,代码来源:WebAdmin.java


示例5: save

import play.data.validation.Required; //导入依赖的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();
  }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:36,代码来源:ProfileSinfonier.java


示例6: log

import play.data.validation.Required; //导入依赖的package包/类
public static void log(@Required String id) {
  try {
    Codes code200 = Codes.CODE_200;
    JsonObject data = new JsonObject();
    data.addProperty("msg", client.getTopologyLog(id));
    code200.setData(data);

    renderJSON(Codes.CODE_200.toGSON());
  } catch (SinfonierException e) {
    Logger.error(e.getMessage());
    response.status = Codes.CODE_500.getCode();
    renderJSON(Codes.CODE_500.toGSON());
  }

}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:16,代码来源:Topologies.java


示例7: publish

import play.data.validation.Required; //导入依赖的package包/类
public static void publish(@Required String id) throws SinfonierException {
  checkAuthenticity();
  Topology topology = Topology.findById(id);

  if (topology == null) {
    Logger.error("We can\'t find the topology with id: " + id);
    notFound();
  } else {
    topology.setSharing(true);
    topology.save();
    topology(topology.getName());
  }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:14,代码来源:Topologies.java


示例8: privatize

import play.data.validation.Required; //导入依赖的package包/类
public static void privatize(@Required String id) throws SinfonierException {
  checkAuthenticity();
  Topology topology = Topology.findById(id);

  if (topology == null) {
    Logger.error("We can\'t find the topology with id: " + id);
    notFound();
  } else {
    topology.setSharing(false);
    topology.save();
    topology(topology.getName());
  }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:14,代码来源:Topologies.java


示例9: authenticate

import play.data.validation.Required; //导入依赖的package包/类
public static void authenticate(@Required String username, String password, boolean remember) throws Throwable {
    // Check tokens
    String allowed = null;
    try {
        // This is the deprecated method name
        allowed = (String)Security.invoke("authentify", username, password);
    } catch (UnsupportedOperationException e ) {
        // This is the official method name
        allowed = (String)Security.invoke("authenticate", username, password);
    }
    if(validation.hasErrors() || !"true".equals(allowed)) {
        flash.keep("url");
        flash.error(allowed);
        params.flash();
        login();
    }
    // Mark user as connected
    session.put("username", username);
    // Remember if needed
    if(remember) {
        Date expiration = new Date();
        String duration = "30d";  // maybe make this override-able 
        expiration.setTime(expiration.getTime() + Time.parseDuration(duration));
        response.setCookie("rememberme", Crypto.sign(username + "-" + expiration.getTime()) + "-" + username + "-" + expiration.getTime(), duration);

    }
    // Redirect to the original URL (or /)
    redirectToOriginalURL();
}
 
开发者ID:xandradx,项目名称:ovirt-engine-disaster-recovery,代码行数:30,代码来源:Secure.java


示例10: authenticate

import play.data.validation.Required; //导入依赖的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();
}
 
开发者ID:sismics,项目名称:play-restsecure,代码行数:35,代码来源:RestSecure.java


示例11: saveContent

import play.data.validation.Required; //导入依赖的package包/类
public void saveContent(@Required String path, @Required String part) throws IOException {
  checkAuthenticity();
  if (validation.hasErrors()) forbidden();
  validateGitPaths(path);
  WebPage page = WebPage.forPath(path);
  try (OutputStream out = page.dir.child(part).outputstream()) {
    IOUtils.copy(request.body, out);
  }
  renderText(Messages.get("web.admin.saved"));
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:11,代码来源:WebAdmin.java


示例12: delete

import play.data.validation.Required; //导入依赖的package包/类
public void delete(@Required String path, @Required String name, String redirectTo) throws Throwable {
  checkAuthenticity();
  if (validation.hasErrors()) forbidden(validation.errorsMap().toString());
  WebPage page = WebPage.forPath(path);
  VirtualFile file = page.dir.child(name);
  checkFileBelongsToCmsContentRoot(file);
  file.getRealFile().delete();
  if (redirectTo != null) redirect(redirectTo);
  if (!request.querystring.contains("path=")) request.querystring += "&path=" + path;
  redirect(Router.reverse("WebAdmin.browse").url + "?" + request.querystring);
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:12,代码来源:WebAdmin.java


示例13: addPage

import play.data.validation.Required; //导入依赖的package包/类
public void addPage(@Required String parentPath, @Required String title, @Required String name, @Required String template, String redirectTo) {
  checkAuthenticity();
  if (validation.hasErrors()) forbidden(validation.errorsMap().toString());
  WebPage page = WebPage.forPath(parentPath + name);
  if (page.dir.exists()) forbidden();
  page.dir.getRealFile().mkdirs();
  page.dir.child("metadata.properties").write("title: " + title + "\ntemplate: " + template + "\n");
  redirect(defaultIfEmpty(redirectTo, page.path));
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:10,代码来源:WebAdmin.java


示例14: addFile

import play.data.validation.Required; //导入依赖的package包/类
public void addFile(@Required String path, @Required String name, @Required String title, String redirectTo) {
  checkAuthenticity();
  if (validation.hasErrors()) forbidden(validation.errorsMap().toString());
  WebPage page = WebPage.forPath(path);
  name = name.replaceAll("\\W", "");
  String content = defaultContent(defaultString(redirectTo, page.path));
  page.dir.child(name + ".html").write("<h3>" + title + "</h3>\n\n" + content);
  redirect(defaultIfEmpty(redirectTo, page.path));
}
 
开发者ID:codeborne,项目名称:play-web,代码行数:10,代码来源:WebAdmin.java


示例15: changePassword

import play.data.validation.Required; //导入依赖的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();
  }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:43,代码来源:ProfileSinfonier.java


示例16: ObjectField

import play.data.validation.Required; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public ObjectField(Model.Property property) {
    Field field = property.field;
    this.property = property;
    if (CharSequence.class.isAssignableFrom(field.getType())) {
        type = "text";
        if (field.isAnnotationPresent(MaxSize.class)) {
            int maxSize = field.getAnnotation(MaxSize.class).value();
            if (maxSize > 100) {
                type = "longtext";
            }
        }
        if (field.isAnnotationPresent(Password.class)) {
            type = "password";
        }
    }
    if (Number.class.isAssignableFrom(field.getType()) || field.getType().equals(double.class) || field.getType().equals(int.class) || field.getType().equals(long.class)) {
        type = "number";
    }
    if (Boolean.class.isAssignableFrom(field.getType()) || field.getType().equals(boolean.class)) {
        type = "boolean";
    }
    if (Date.class.isAssignableFrom(field.getType())) {
        type = "date";
    }
    if (property.isRelation) {
        type = "relation";
    }
    if (property.isMultiple) {
        multiple = true;
    }
    if(Model.BinaryField.class.isAssignableFrom(field.getType()) || /** DEPRECATED **/ play.db.jpa.FileAttachment.class.isAssignableFrom(field.getType())) {
        type = "binary";
    }
    if (field.getType().isEnum()) {
        type = "enum";
    }
    if (property.isGenerated) {
        type = null;
    }
    if (field.isAnnotationPresent(Required.class)) {
        required = true;
    }
    if (field.isAnnotationPresent(Hidden.class)) {
        type = "hidden";
    }
    if (field.isAnnotationPresent(Exclude.class)) {
        type = null;
    }
    if (java.lang.reflect.Modifier.isFinal(field.getModifiers())) {
        type = null;
    }
    name = field.getName();
}
 
开发者ID:eBay,项目名称:restcommander,代码行数:55,代码来源:CRUD.java


示例17: JavascriptRessource

import play.data.validation.Required; //导入依赖的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();
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:49,代码来源:AsyncJavascript.java


示例18: authenticate

import play.data.validation.Required; //导入依赖的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");
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:52,代码来源:Secure.java



注:本文中的play.data.validation.Required类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EmbeddedDatabaseFactory类代码示例发布时间:2022-05-23
下一篇:
Java IStrategoTuple类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap