Esempio n. 1
0
 public static void save(Long id, String title, String content, String tags) {
   Post post;
   if (id == null) {
     // Create post
     User author = User.find("byEmail", Security.connected()).first();
     post = new Post(author, title, content);
   } else {
     // Retrieve post
     post = Post.findById(id);
     // Edit
     post.title = title;
     post.content = content;
     post.tags.clear();
   }
   // Set tags list
   for (String tag : tags.split("\\s+")) {
     if (tag.trim().length() > 0) {
       post.tags.add(Tag.findOrCreateByName(tag));
     }
   }
   // Validate
   validation.valid(post);
   if (validation.hasErrors()) {
     render("@form", post);
   }
   // Save
   post.save();
   index();
 }
Esempio n. 2
0
 @Before
 static void setConnectedUser() {
   if (Security.isConnected()) {
     User user = User.find("byEmail", Security.connected()).first();
     renderArgs.put("user", user.fullname);
   }
 }
Esempio n. 3
0
 @Before
 static void setConnectedUser() {
   if (Security.isConnected()) {
     User user = User.find("byUsername", Security.connected()).first();
     if (!user.isAdmin) {
       flash.error(Messages.get("UserIsNotAuthorized"));
       Application.index();
     }
   }
 }
Esempio n. 4
0
  public static void editerBateau(String nomBateau, String couleurVoile, String couleurcoque) {
    if (Security.isConnected()) {
      Utilisateur user = Utilisateur.find("byEmail", Security.connected()).first();
      renderArgs.put("user", user);
    }

    Utilisateur user = Utilisateur.find("byEmail", Security.connected()).first();

    if (validation.hasErrors()) {
      // add http parameters to the flash scope
      params.flash();
    } else {
      user.couleurcoque = couleurcoque;
      user.couleurVoile = couleurVoile;
      user.nomBateau = nomBateau;
      user.save();
    }
    render("Admin/index.html");
  }
Esempio n. 5
0
  public static void sauvegardermoncompte(String pseudo, String password) {

    if (Security.isConnected()) {
      Utilisateur user = Utilisateur.find("byEmail", Security.connected()).first();
      renderArgs.put("user", user);
    }

    Utilisateur user = Utilisateur.find("byEmail", Security.connected()).first();

    if (validation.hasErrors()) {
      // add http parameters to the flash scope
      params.flash();
    } else {
      user.pseudo = pseudo;
      user.password = password;
      user.save();
    }
    render("Admin/index.html");
  }
Esempio n. 6
0
  @Before
  static void header() {
    Journal journal = Journal.all().first();
    renderArgs.put("journal", journal);
    renderArgs.put("journalName", journal.name);
    renderArgs.put("journalDesc", journal.description);

    User currentUser = User.find("byEmail", Security.connected()).<User>first();
    renderArgs.put("currentUser", currentUser);
  }
Esempio n. 7
0
  @Before
  static void setConnectedUser() {
    if (Security.isConnected()) {
      User user = User.find("byEmail", Security.connected()).first();

      if (user == null) {
        user = new User("*****@*****.**", "1234", "Andreas");
        user.save();
      }

      renderArgs.put("user", user.fullname);
    }
  }
Esempio n. 8
0
 public static void uploadFile(String filename, File file) {
   User user = User.find("byEmail", Security.connected()).first();
   Upload uploadObj = new Upload();
   uploadObj.UploadFile(filename, user, file);
   Admin.upload();
 }
Esempio n. 9
0
 public static void index() {
   String user = Security.connected();
   List<Post> posts = Post.find("author.email", user).fetch();
   render(posts);
 }