Exemple #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());
   }
 }
Exemple #2
0
 public static Result newTask() {
   Form<Task> filledForm = taskForm.bindFromRequest();
   if (filledForm.hasErrors()) {
     return badRequest(views.html.index.render(Task.all(), filledForm));
   } else {
     Task.create(filledForm.get());
     return redirect(routes.Application.tasks());
   }
 }
Exemple #3
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());
   }
 }
  public static Result createNewUser() {
    Form<User> nu = userForm.bindFromRequest();

    ObjectNode jsonData = Json.newObject();
    String userName = null;

    try {
      userName =
          nu.field("firstName").value()
              + " "
              + (nu.field("middleInitial")).value()
              + " "
              + (nu.field("lastName")).value();
      jsonData.put("userName", userName);
      jsonData.put("firstName", nu.get().getFirstName());
      jsonData.put("middleInitial", nu.get().getMiddleInitial());
      jsonData.put("lastName", nu.get().getLastName());
      jsonData.put("password", nu.get().getPassword());
      jsonData.put("affiliation", nu.get().getAffiliation());
      jsonData.put("title", nu.get().getTitle());
      jsonData.put("email", nu.get().getEmail());
      jsonData.put("mailingAddress", nu.get().getMailingAddress());
      jsonData.put("phoneNumber", nu.get().getPhoneNumber());
      jsonData.put("faxNumber", nu.get().getFaxNumber());
      jsonData.put("researchFields", nu.get().getResearchFields());
      jsonData.put("highestDegree", nu.get().getHighestDegree());

      JsonNode response =
          RESTfulCalls.postAPI(
              Constants.URL_HOST + Constants.CMU_BACKEND_PORT + Constants.ADD_USER, jsonData);

      // flash the response message
      Application.flashMsg(response);
      return redirect(routes.Application.createSuccess());

    } catch (IllegalStateException e) {
      e.printStackTrace();
      Application.flashMsg(RESTfulCalls.createResponse(ResponseType.CONVERSIONERROR));
    } catch (Exception e) {
      e.printStackTrace();
      Application.flashMsg(RESTfulCalls.createResponse(ResponseType.UNKNOWN));
    }
    return ok(signup.render(nu));
  }
Exemple #5
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)));
    }
  }
Exemple #6
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));
    }
  }
Exemple #7
0
 public static Result deleteTask(Long id) {
   Task.delete(id);
   return redirect(routes.Application.tasks());
 }
Exemple #8
0
 public static Result index() {
   return redirect(routes.Application.tasks());
 }
Exemple #9
0
 public static Result logout() {
   session().clear();
   flash("success", "You've been logged out");
   return redirect(routes.Application.login());
 }
Exemple #10
0
 @Security.Authenticated(Secured.class)
 public static Result addNewMessage(Long id) {
   return redirect(
       //                postNewMessage.render(form(MessageForm.class), id)
       routes.Application.viewMyConversation(id));
 }