@Security.Authenticated(Secured.class) public static Result upload() { User user = getCurrentUser(); if (!user.isAdmin) return redirect(routes.Application.contacts()); Http.MultipartFormData body = request().body().asMultipartFormData(); Http.MultipartFormData.FilePart contactfile = body.getFile("contactfile"); if (contactfile != null) { String fileName = contactfile.getFilename(); File file = contactfile.getFile(); try { File f = new File("public/upload/" + fileName); if (f.isFile()) f.delete(); FileUtils.moveFile(file, new File("public/upload", fileName)); } catch (IOException ioe) { System.out.println("Problem operating on filesystem"); } PoiExcelFileReader.readFile(fileName); flash("success", "Datei: " + fileName + " hochgeladen und Kontakte importiert"); return redirect(routes.Application.contacts()); } else { flash("error", "Ein Fehler ist aufgetreten, bitte versuchen sie es erneut"); return redirect(routes.Application.contacts()); } }
@Security.Authenticated(Secured.class) public static Result newUser() { User user = getCurrentUser(); if (!user.isAdmin) return redirect(routes.Application.contacts()); Form<User> filledForm = userForm.bindFromRequest(); if (!filledForm.field("password").valueOr("").isEmpty()) { if (!filledForm .field("password") .valueOr("") .equals(filledForm.field("repeatPassword").value())) { filledForm.reject("repeatPassword", "Passwörter stimmen nicht überein"); } } if (!filledForm.hasErrors()) { if (userAlreadyExists(filledForm.get().email)) { filledForm.reject("email", "Diese Emailadresse ist bereits vergeben"); } } if (filledForm.hasErrors()) { flash("error", "Bitte korrigieren sie ihre Eingaben!"); return badRequest(views.html.addUser.render(filledForm, getCurrentUser(), User.find.all())); } else { User.create(filledForm.get()); flash("success", "Benutzer " + filledForm.get().email + " erstellt."); return redirect(routes.Application.contacts()); } }
public static Result upload() { MultipartFormData body = request().body().asMultipartFormData(); FilePart input = body.getFile("inputFile"); if (input != null) { String fileName = input.getFilename(); String contentType = input.getContentType(); File file = input.getFile(); SeqFile seq = new SeqFile(file); return redirect(routes.Application.results(true)); } else { flash("error", "Missing file"); return redirect(routes.Application.results(false)); } }
/** Lists all the contacts of the specifed group */ @Security.Authenticated(Secured.class) public static Result filteredContactsBy(String groupname) { User user = getCurrentUser(); if (!user.isAdmin) return redirect(routes.Application.contacts()); String btn = groupname; return ok(views.html.index.render(Contact.findByGroupname(groupname), contactForm, user, btn)); }
/** * 사용자 가입 화면 이동 * * @return */ public static Result signupForm() { if (!UserApp.currentUser().isAnonymous()) { return redirect(routes.Application.index()); } return ok(signup.render("title.signup", form(User.class))); }
/** * 로그인 처리 시스템 설정에서 가입승인 기능이 활성화 되어 있고 사용자 상태가 잠금상태(미승인?)라면 계정이 잠겼다는 메시지를 노출하고 로그인 폼으로 돌아감 시스템 설정에서 * 가입승인 기능이 활성화 되어 있지 않다면, 사용자 상태가 잠금상태라도 로그인이 가능하다 (스펙확인 필요) 요청의 정보로 사용자 인증에 성공하면 로그인쿠키를 생성하고 * 로그인유지하기가 선택되었다면, 로그인유지를 위한 쿠키를 별도로 생성한다 인증에 실패하면 관련된 메시지를 노출하고 로그인 폼으로 돌아간다 * * @return */ public static Result login() { Form<User> userForm = form(User.class).bindFromRequest(); if (userForm.hasErrors()) { return badRequest(login.render("title.login", userForm)); } User sourceUser = form(User.class).bindFromRequest().get(); if (isUseSignUpConfirm()) { if (User.findByLoginId(sourceUser.loginId).state == UserState.LOCKED) { flash(Constants.WARNING, "user.locked"); return redirect(routes.UserApp.loginForm()); } } if (User.findByLoginId(sourceUser.loginId).state == UserState.DELETED) { flash(Constants.WARNING, "user.deleted"); return redirect(routes.UserApp.loginForm()); } User authenticate = authenticateWithPlainPassword(sourceUser.loginId, sourceUser.password); if (authenticate != null) { addUserInfoToSession(authenticate); if (sourceUser.rememberMe) { setupRememberMe(authenticate); } return redirect(routes.Application.index()); } flash(Constants.WARNING, "user.login.failed"); return redirect(routes.UserApp.loginForm()); }
public static Result addUser() { User user = User.finder.where().eq("name", "admin").findUnique(); if (user == null) { User.create("admin", "password123"); } return redirect(routes.Application.login()); }
@Transactional public static Result pesquisarAnuncio() { DynamicForm pesquisarForm = Form.form().bindFromRequest(); List<Anuncio> result = null; if (pesquisarForm.get("optradio").equals("1")) { result = dao.findByAttributeName("Anuncio", "nome", pesquisarForm.get("pesquisa")); } else if (pesquisarForm.get("optradio").equals("2")) { result = dao.findByAttributeInstumento(pesquisarForm.get("pesquisa")); } else if (pesquisarForm.get("optradio").equals("3")) { result = dao.findByAttributeEstilo(pesquisarForm.get("pesquisa")); } else if (pesquisarForm.get("optradio").equals("4")) { if (pesquisarForm.get("objetivo").equals("Tocar Ocasionalmente")) { result = dao.findByAttributeName("Anuncio", "objetivo", "Tocar Ocasionalmente"); } else if (pesquisarForm.get("objetivo").equals("Procuro Banda")) { result = dao.findByAttributeName("Anuncio", "objetivo", "Procuro Banda"); } else if (pesquisarForm.get("objetivo").equals("Procuro musico")) { result = dao.findByAttributeName("Anuncio", "objetivo", "Procuro musico"); } } else if (pesquisarForm.get("optradio").equals("5")) { result = dao.findByAttributeName("Anuncio", "objetivo", "Procuro Banda"); } else if (pesquisarForm.get("optradio").equals("6")) { result = dao.findByAttributeName("Anuncio", "objetivo", "Procuro musico"); } if (result == null) { return redirect(routes.Application.anuncios()); } return ok(views.html.pesquisar.render(result)); }
@SubjectPresent public Result doMerge() { com.feth.play.module.pa.controllers.Authenticate.noCache(response()); // this is the currently logged in user final AuthUser aUser = PlayAuthenticate.getUser(session()); // this is the user that was selected for a login final AuthUser bUser = PlayAuthenticate.getMergeUser(session()); if (bUser == null) { // user to merge with could not be found, silently redirect to login return redirect(routes.Application.index()); } final Form<Accept> filledForm = ACCEPT_FORM.bindFromRequest(); if (filledForm.hasErrors()) { // User did not select whether to merge or not merge return badRequest((Content) ask_merge.render("Merge Form")); } else { // User made a choice :) final boolean merge = filledForm.get().accept; if (merge) { flash( Application.FLASH_MESSAGE_KEY, Messages.get("playauthenticate.accounts.merge.success")); } return PlayAuthenticate.merge(ctx(), merge); } }
/** * Verify. * * @param token the token * @return the result */ public static Result verify(final String token) { Logger.debug("Account verify"); com.feth.play.module.pa.controllers.Authenticate.noCache(response()); final TokenAction ta = tokenIsValid(token, Type.EMAIL_VERIFICATION); if (ta == null) { return badRequest(no_token_or_invalid.render()); } final String email = ta.targetUser.email; // final User verifiedUser = ta.targetUser; // if(session().containsKey("acctType") && StringUtils.equals("event", // session().get("acctType"))) { // verifiedUser.addRoles(SecurityRole.EVENT_ADMIN); // } else { // verifiedUser.addRoles(SecurityRole.PFP_ADMIN); // } User.verify(ta.targetUser); flash( ControllerUtil.FLASH_INFO_KEY, Messages.get("playauthenticate.verify_email.success", email)); if (ControllerUtil.getLocalUser(session()) != null) { return redirect(routes.Application.index()); } else { return redirect(routes.Signup.login()); } }
/** * Action usada para a denúncia de uma Dica considerada como imprópria pelo usuário. * * @param idDica O id da {@code Dica} denunciada. * @return O Result do POST, redirecionando para a página do {@code Tema} caso o POST tenha sido * concluído com sucesso. */ @Transactional @Security.Authenticated(Secured.class) public static Result denunciarDica(Long idDica) { Dica dica = dao.findByEntityId(Dica.class, idDica); String login = session("login"); if (!dica.wasFlaggedByUser(login)) { dica.addUsuarioFlag(login); dica.incrementaFlag(); if (dica.getFlag() == MAX_DENUNCIAS) { dao.removeById(Dica.class, idDica); for (MetaDica metadica : dica.getMetaDicas()) { metadica.getDicasAdicionadas().remove(dica); dao.merge(metadica); } } else { dao.merge(dica); } } else { flash("fail", "Usuário já denunciou a dica."); } dao.flush(); return redirect(routes.Application.tema(dica.getTema().getId())); }
// TODO change to use Contact.create() method @Security.Authenticated(Secured.class) public static Result newContact() { Form<Contact> filledForm = contactForm.bindFromRequest(); String name = filledForm.data().get("name"); String firstName = filledForm.data().get("firstName"); String title = filledForm.data().get("title"); String email = filledForm.data().get("email"); String street = filledForm.data().get("street"); String appendix1 = filledForm.data().get("appendix1"); String appendix2 = filledForm.data().get("appendix2"); String zipcode = filledForm.data().get("zipcode"); String country = filledForm.data().get("country"); String city = filledForm.data().get("city"); String phone = filledForm.data().get("phone"); String yearbook = filledForm.data().get("yearbookSubscription"); String memberCategory = filledForm.data().get("memberCategory"); String membershipSince = filledForm.data().get("membershipSince"); Contact newContact = new Contact(); newContact.name = name; newContact.firstName = firstName; newContact.title = title; newContact.email = email; newContact.street = street; newContact.appendix1 = appendix1; newContact.appendix2 = appendix2; newContact.zipcode = zipcode; newContact.city = city; newContact.country = country; newContact.phone = phone; if (yearbook.equals("true")) newContact.yearbookSubscription = true; newContact.memberCategory = memberCategory; for (int j = 0; j < ContactGroup.options().size(); j++) { String item = "belongsTo[" + j + "]"; if (filledForm.data().get(item) != null) { ContactGroup cg = ContactGroup.find.byId((long) Integer.parseInt(filledForm.data().get(item))); newContact.belongsTo.add(cg); } } if (newContact.belongsTo.isEmpty()) filledForm.reject("belongsTo[]", "Keine Sektion ausgewählt"); // TODO Check fields for errors if (filledForm.hasErrors()) System.out.println(filledForm.errors().toString()); newContact.membershipSince = membershipSince; newContact.createdAt = new Timestamp(new Date().getTime()); newContact.lastEditedAt = newContact.createdAt; newContact.save(); flash("success", "Kontakt " + newContact + " erstellt und gespeichert."); return redirect(routes.Application.contacts()); }
@Security.Authenticated(Secured.class) public static Result addContactGroup() { if (!getCurrentUser().isAdmin) return redirect(routes.Application.contacts()); Form<ContactGroup> contactGroupForm = Form.form(ContactGroup.class); return ok( views.html.addContactGroup.render( contactGroupForm, getCurrentUser(), ContactGroup.find.all())); }
public static Result newTask() { Form<Task> filledForm = taskForm.bindFromRequest(); if (filledForm.hasErrors()) return badRequest(views.html.task.render(Task.all(), filledForm)); else { Task.createTask(filledForm.get()); return redirect(routes.Application.getTasks()); } }
/** Lists all the contacts with yearbook subscription */ @Security.Authenticated(Secured.class) public static Result filteredContactsWithYearbookSubscription() { System.out.println("Method: filteredContactsWithYearbookSubscription()"); User user = getCurrentUser(); if (!user.isAdmin) return redirect(routes.Application.contacts()); String btn = "yearbook"; return ok(views.html.index.render(Contact.withYearbookSubscription(), contactForm, user, btn)); }
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()); } }
public static Result authenticate() { Form<Login> loginForm = form(Login.class).bindFromRequest(); if (loginForm.hasErrors()) { return badRequest(login.render(loginForm)); } else { session("email", loginForm.get().email); return redirect(routes.Application.index()); } }
public static Result authenticate() { Form<User> loginForm = Form.form(User.class).bindFromRequest(); if (loginForm.hasErrors()) { return badRequest(login.render(loginForm)); } else { session().clear(); session("name", loginForm.get().name); return redirect(routes.Application.index()); } }
/** * Returns the view for editing the restaurant. Checks if restaurant with provided id exists, if * it does, returns view for editing. * * @param restaurantId * @return */ @Security.Authenticated(Authenticators.SellerFilter.class) public Result editRestaurant(Integer restaurantId) { Restaurant restaurant = Restaurant.findRestaurantById(restaurantId); if (restaurant != null) { return ok(views.html.restaurant.updateRestaurant.render(restaurant)); } else { return redirect(routes.Application.index()); } }
public static Result authenticate() { Form<Login> loginForm = Form.form(Login.class).bindFromRequest(); if (loginForm.hasErrors()) { return badRequest(views.html.login.render(loginForm, getCurrentUser())); } else { session().clear(); session("email", loginForm.get().email); flash("success", "Sie haben sich erfolgreich eingeloggt als: " + loginForm.get().email); return redirect(routes.Application.contacts()); } }
/** * Ask link. * * @return the result */ @SubjectPresent public static Result askLink() { Logger.debug("Account askLink"); com.feth.play.module.pa.controllers.Authenticate.noCache(response()); final AuthUser u = PlayAuthenticate.getLinkUser(session()); if (u == null) { // account to link could not be found, silently redirect to login return redirect(routes.Application.index()); } return ok(ask_link.render(ACCEPT_FORM, u)); }
@Security.Authenticated(Secured.class) public static Result download() { User user = getCurrentUser(); if (!user.isAdmin) return redirect(routes.Application.contacts()); String filename = PoiExcelFileReader.writeFile(Contact.all()); response().setContentType("application/x-download"); String headerName = "Content-disposition"; String headerValue = "attachment; filename=" + filename; response().setHeader(headerName, headerValue); return ok(new File(filename)); // return redirect(routes.Application.contacts()); }
/** * Saves restaurant into the database. Collects all data from the form, checks if provided hotel * already contains a restaurant (according to project specifications, one hotel can contain only * one restaurant). * * @param hotelId * @return */ @Security.Authenticated(Authenticators.SellerFilter.class) public Result saveRestaurant(Integer hotelId) { // Checking if there is a restaurant with provided // hotel id in the database. if (!Restaurant.existsInDB(hotelId)) { Form<Restaurant> boundForm = restaurantForm.bindFromRequest(); Restaurant restaurant = new Restaurant(); Form<Restaurant> restaurantForm1 = restaurantForm.bindFromRequest(); // Collecting data from the form String name = restaurantForm1.field("name").value(); String restaurantType = restaurantForm1.field("restauranType").value(); Integer capacity = Integer.parseInt(restaurantForm1.field("capacity").value()); String description = restaurantForm1.field("description").value(); String open = restaurantForm1.field("restOpen").value(); String close = restaurantForm1.field("restClose").value(); String workingHours = open + " - " + close; restaurant.name = name; restaurant.restauranType = restaurantType; restaurant.capacity = capacity; restaurant.workingHours = workingHours; restaurant.description = description; // Finding hotel with provided hotel id Hotel hotel = Hotel.findHotelById(hotelId); // Checking if hotel with provided id exists if (hotel != null) { restaurant.hotel = hotel; } // Getting timestamp Calendar c = Calendar.getInstance(); restaurant.timestamp = c.getTime(); // Saving the restaurant into the database restaurant.save(); } else { flash("error", "There is already added restaurant for selected hotel."); return ok(createRestaurant.render(hotelId)); } if (session("userId") != null) { flash("create", "The restaurant was created!"); return redirect(routes.Hotels.showSellerHotels()); } else { return redirect(routes.Application.index()); } }
@Security.Authenticated(Secured.class) public static Result updateContact(Long id) { Form<Contact> updatedForm = contactForm.bindFromRequest(); String name = updatedForm.data().get("name"); String firstName = updatedForm.data().get("firstName"); String title = updatedForm.data().get("title"); String email = updatedForm.data().get("email"); String street = updatedForm.data().get("street"); String appendix1 = updatedForm.data().get("appendix1"); String appendix2 = updatedForm.data().get("appendix2"); String zipcode = updatedForm.data().get("zipcode"); String country = updatedForm.data().get("country"); String city = updatedForm.data().get("city"); String phone = updatedForm.data().get("phone"); String memberCategory = updatedForm.data().get("memberCategory"); String membershipSince = updatedForm.data().get("membershipSince"); String yearbook = updatedForm.data().get("yearbookSubscription"); String contactGroup = ""; for (int j = 0; j < ContactGroup.options().size(); j++) { String item = "belongsTo[" + j + "]"; if (updatedForm.data().get(item) != null) { if (j > 0) contactGroup += "/"; contactGroup += updatedForm.data().get(item); } } if (contactGroup.isEmpty()) updatedForm.reject("belongsTo[]", "Keine Sektion ausgewählt"); Contact.find .byId(id) .update( title, name, firstName, email, street, appendix1, appendix2, zipcode, city, country, phone, membershipSince, memberCategory, yearbook, contactGroup); flash("success", "Kontakt bearbeitet und gespeichert."); return redirect(routes.Application.contacts()); }
/** * 로그인 폼으로 이동 * * @return */ public static Result loginForm() { if (!UserApp.currentUser().isAnonymous()) { return redirect(routes.Application.index()); } String redirectUrl = request().getQueryString("redirectUrl"); String loginFormUrl = routes.UserApp.loginForm().url(); String referer = request().getHeader("Referer"); if (StringUtils.isEmpty(redirectUrl) && !StringUtils.equals(loginFormUrl, referer)) { redirectUrl = request().getHeader("Referer"); } return ok(login.render("title.login", form(User.class), redirectUrl)); }
public static Result enter() { Map<String, String[]> params; params = request().body().asFormUrlEncoded(); String email = params.get("email")[0]; User user = User.find.byId(email); if (user == null) { return redirect(routes.Application.login()); } else { session("email", email); return redirect(routes.Chats.allChats()); } }
@Transactional @Security.Authenticated(Secured.class) public static Result upVoteMetaDica(long idMetaDica) { MetaDica metaDica = dao.findByEntityId(MetaDica.class, idMetaDica); String login = session("login"); if (!metaDica.wasVotedByUser(login)) { metaDica.addUsuarioQueVotou(login); metaDica.incrementaConcordancias(); dao.merge(metaDica); dao.flush(); } return redirect(routes.Application.disciplina(metaDica.getDisciplina().getId())); }
@Transactional @Security.Authenticated(Secured.class) public static Result upVoteDica(long idDica) { Dica dica = dao.findByEntityId(Dica.class, idDica); String login = session("login"); if (!dica.wasVotedByUser(login)) { dica.addUsuarioQueVotou(login); dica.incrementaConcordancias(); dao.merge(dica); dao.flush(); } return redirect(routes.Application.tema(dica.getTema().getId())); }
// TODO Automatic binding of owner is still missing at the moment @Security.Authenticated(Secured.class) public static Result newContactGroup() { User user = getCurrentUser(); if (!user.isAdmin) return redirect(routes.Application.contacts()); Form<ContactGroup> filledForm = contactGroupForm.bindFromRequest(); if (filledForm.hasErrors()) { System.out.println(filledForm.errors().toString()); flash("error", "Bitte korrigieren sie ihre Eingaben!"); return badRequest( views.html.addContactGroup.render(filledForm, getCurrentUser(), ContactGroup.find.all())); } else { ContactGroup.create(filledForm.get()); flash("success", "Kontaktgruppe " + filledForm.get().name + " erstellt."); if (User.findByEmail(request().username()).isAdmin) { // manual binding of owner ContactGroup.find.ref(filledForm.get().id).addOwner(User.findByEmail(request().username())); } return redirect(routes.Application.contacts()); } }
/** * Start the workflow run asynchronously. * * @param name The name of the workflow * @return json response containing id */ @Security.Authenticated(Secured.class) public Result runWorkflow(String name) { FormDefinition form = formDefinitionForWorkflow(name); // Process file upload first if present in form data Http.MultipartFormData body = request().body().asMultipartFormData(); for (Object obj : body.getFiles()) { Http.MultipartFormData.FilePart filePart = (Http.MultipartFormData.FilePart) obj; UserUpload userUpload = uploadFile(filePart); BasicField fileInputField = form.getField(filePart.getKey()); fileInputField.setValue(userUpload); } // Set the form definition field values from the request data Map<String, String[]> data = body.asFormUrlEncoded(); for (String key : data.keySet()) { BasicField field = form.getField(key); field.setValue(data.get(key)); } // Transfer form field data to workflow settings map Map<String, Object> settings = new HashMap<>(); for (BasicField field : form.fields) { settings.put(field.name, field.value()); } settings.putAll(settingsFromConfig(form)); // Update the workflow model object and persist to the db Workflow workflow = Workflow.find.where().eq("name", form.name).findUnique(); if (workflow == null) { workflow = new Workflow(); } workflow.name = form.name; workflow.title = form.title; workflow.yamlFile = form.yamlFile; workflow.save(); // Run the workflow ObjectNode response = runYamlWorkflow(form.yamlFile, workflow, settings); return redirect(routes.Application.index()); }