Exemplo n.º 1
0
 public static Result registerNewUser() {
   Form<Register> regForm = Form.form(Register.class).bindFromRequest();
   if (regForm.hasErrors()) {
     return badRequest(register.render(regForm));
   } else {
     return redirect(routes.Application.login());
   }
 }
Exemplo n.º 2
0
 public static Result authenticate() {
   Form<Login> loginForm = Form.form(Login.class).bindFromRequest();
   if (loginForm.hasErrors()) {
     return badRequest(login.render(loginForm));
   } else {
     session().clear();
     session("email", loginForm.get().email);
     return redirect(routes.Application.start());
   }
 }
Exemplo n.º 3
0
 public static Result newTeam() {
   Form<Team> filledForm = teamForm.bindFromRequest();
   if (filledForm.hasErrors()) {
     System.out.println("Errors: " + filledForm.errors());
     return badRequest(
         views.html.index.render(
             Team.all(),
             teamForm,
             Category.all(),
             categoryForm,
             Interview.all(),
             interviewForm,
             Application.getLoggedinUser()));
   } else {
     filledForm.get().save();
     return redirect(routes.Application.index());
   }
 }
Exemplo n.º 4
0
  @Security.Authenticated(Secured.class)
  public static Result viewMyConversation(Long id) {
    Student s = Student.find.byId(request().username());
    Conversation c = Conversation.find.byId(id.toString());

    if (!c.getParticipants().contains(s)) { // unauthorized access!
      return redirect(routes.Application.viewMyConversations());
    } else {
      // mark all read
      for (Message m : c.messages) {
        if (!m.sender.email.equals(s.email)) {
          m.setRead();
          m.save();
        }
      }

      return ok(viewConversation.render(s, c, form(MessageForm.class)));
    }
  }
Exemplo n.º 5
0
  @Security.Authenticated(Secured.class)
  public static Result addNewMessageForm(Long id) {
    Form<MessageForm> mesForm = Form.form(MessageForm.class).bindFromRequest();
    if (mesForm.hasErrors()) {
      return badRequest(postNewMessage.render(mesForm, id));
    } else {

      Message m =
          new Message(
              mesForm.field("text").value().toString(), Student.find.byId(request().username()));

      Conversation c = null;

      c = Conversation.find.byId(id.toString());
      c.messages.add(m);
      c.save();

      return redirect(routes.Application.viewMyConversation(id));
    }
  }
Exemplo n.º 6
0
 public static Result logout() {
   session().clear();
   flash("success", "You've been logged out");
   return redirect(routes.Application.login());
 }
Exemplo n.º 7
0
 @Security.Authenticated(Secured.class)
 public static Result addNewMessage(Long id) {
   return redirect(
       //                postNewMessage.render(form(MessageForm.class), id)
       routes.Application.viewMyConversation(id));
 }