当前位置: 首页>>代码示例>>Java>>正文


Java Required类代码示例

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


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


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