// 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())); } } }
/** * Validates fields from the registration form and either creates a new user or communicates any * validation errors. */ public static Result submit() { Form<User> filledForm = signupForm.bindFromRequest(); // Check accept conditions if (!"true".equals(filledForm.field("accept").value())) { filledForm.reject("accept", "You must accept the terms and conditions"); } // Check repeated password if (!filledForm.field("password").valueOr("").isEmpty()) { if (!filledForm .field("password") .valueOr("") .equals(filledForm.field("repeatPassword").value())) { filledForm.reject("repeatPassword", "Passwords do not match"); } } // Check if the username and email are valid if (!filledForm.hasErrors()) { String un = filledForm.get().username; String email = filledForm.get().email; if (un.equals("admin") || un.equals("guest")) { filledForm.reject("username", "This username is already taken"); } try { Logger.debug("Finding user " + email); User.findByEmail(email); filledForm.reject( "email", "There is already an account associated with this email address."); } catch (Exception e) { // continue - the user does not exist } } // Return validation results to user or save user if (filledForm.hasErrors()) { return badRequest(form.render(filledForm)); } else { User user = filledForm.get(); /* create an object from a form */ User svUser = new User(user.username, user.email, user.password); /* recreate to get save group info */ svUser.save(); return ok(summary.render(svUser)); } }
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()); } }
/** Handle login form submission. */ public static Result authenticate() { Form<Login> filledLogin = form(Application.Login.class).bindFromRequest(); if (filledLogin.hasErrors()) { return badRequest(login.render(filledLogin)); } else { session("email", filledLogin.get().email); return redirect(routes.JobOffers.index()); } }
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)); }
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()); } }
@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())); } } }
public static Result newTask() { User user = loadUser(); Form<Task> filledForm = taskForm.bindFromRequest(); if (filledForm.hasErrors()) { flash("error", "The task could not be saved."); return badRequest(main.render("Tasks", null, tasks.render(user.tasks, filledForm))); } else { Task task = filledForm.get(); task.owner = user; task.save(); return created(main.render("Tasks", null, tasks.render(user.tasks, taskForm))); } }