コード例 #1
0
ファイル: Application.java プロジェクト: TijsDelvaux/Stedunt
  // src: 1 = viewAdvertisements
  // src: 2 = viewMyOwnAdvertisements
  @Security.Authenticated(Secured.class)
  public static Result changeStudAdvertisementForm(Long adId, Long src) {

    Form<StudentAdvertisementForm> adForm =
        Form.form(StudentAdvertisementForm.class).bindFromRequest();
    String description = adForm.get().description;
    String studies = adForm.get().studies;
    boolean testAd = adForm.get().test;

    StudentAdvertisement.create(
        Student.find.byId(request().username()), studies, description, adId, testAd);

    if (adForm.hasErrors()) {
      return badRequest(
          changeStudentAdvertisement.render(
              Student.find.byId(request().username()), adForm, null, src));
    } else {
      if (src == 1) {
        return ok(
            viewAdvertisements.render(
                Student.find.byId(request().username()),
                StudentAdvertisement.find.all(),
                TutorAdvertisement.find.all()));
      } else {
        return ok(
            viewOwnAdvertisements.render(
                Student.find.byId(request().username()),
                StudentAdvertisement.find.all(),
                TutorAdvertisement.find.all()));
      }
    }
  }
コード例 #2
0
ファイル: Application.java プロジェクト: TijsDelvaux/Stedunt
 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());
   }
 }
コード例 #3
0
ファイル: Application.java プロジェクト: TijsDelvaux/Stedunt
 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());
   }
 }
コード例 #4
0
ファイル: Application.java プロジェクト: TijsDelvaux/Stedunt
  @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));
    }
  }
コード例 #5
0
ファイル: Application.java プロジェクト: TijsDelvaux/Stedunt
  @Security.Authenticated(Secured.class)
  public static Result addNewStudAdvertisementForm(Long src) {
    Form<StudentAdvertisementForm> adForm =
        Form.form(StudentAdvertisementForm.class).bindFromRequest();

    if (adForm.hasErrors()) {

      System.out.println("ERRORS");
      System.out.println(adForm.errorsAsJson());
      System.out.println(adForm.errors().entrySet());

      return badRequest(
          postNewStudentAdvertisement.render(
              Student.find.byId(request().username()), adForm, null, src));
    } else {

      String description = adForm.get().description;
      String studies = adForm.get().studies;
      boolean testAd = adForm.get().test;

      if (testAd) {
        System.out.println("CREATED TESTAD");
      }

      StudentAdvertisement.create(
          Student.find.byId(request().username()), studies, description, testAd);
      if (src == 1) {
        return ok(
            viewAdvertisements.render(
                Student.find.byId(request().username()),
                StudentAdvertisement.find.all(),
                TutorAdvertisement.find.all()));
      } else {
        return ok(
            viewOwnAdvertisements.render(
                Student.find.byId(request().username()),
                StudentAdvertisement.find.all(),
                TutorAdvertisement.find.all()));
      }
    }
  }
コード例 #6
0
ファイル: Application.java プロジェクト: TijsDelvaux/Stedunt
 @Security.Authenticated(Secured.class)
 public static Result addNewTutAdvertisementForm(Long src) {
   Form<TutorAdvertisementForm> adForm = Form.form(TutorAdvertisementForm.class).bindFromRequest();
   if (adForm.hasErrors()) {
     return badRequest(
         postNewTutorAdvertisement.render(
             Student.find.byId(request().username()), adForm, null, src));
   } else {
     if (src == 1) {
       return ok(
           viewAdvertisements.render(
               Student.find.byId(request().username()),
               StudentAdvertisement.find.all(),
               TutorAdvertisement.find.all()));
     } else {
       return ok(
           viewOwnAdvertisements.render(
               Student.find.byId(request().username()),
               StudentAdvertisement.find.all(),
               TutorAdvertisement.find.all()));
     }
   }
 }