Java Code Examples for play.data.Form#get()

The following examples show how to use play.data.Form#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Account.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@Restrict(@Group(LocalAuthController.USER_ROLE))
public static Result doChangePassword() {
	com.feth.play.module.pa.controllers.Authenticate.noCache(response());
	final Form<Account.PasswordChange> filledForm = PASSWORD_CHANGE_FORM
			.bindFromRequest();
	if (filledForm.hasErrors()) {
		// User did not select whether to link or not link
		return badRequest(password_change.render(filledForm));
	} else {
		final User user = LocalAuthController.getLocalUser(session());
		final String newPassword = filledForm.get().password;
		user.changePassword(new GSNUsernamePasswordAuthUser(newPassword),
				true);
		flash(LocalAuthController.FLASH_MESSAGE_KEY,
				Messages.get("playauthenticate.change_password.success"));
		return redirect(routes.LocalAuthController.profile());
	}
}
 
Example 2
Source File: Items.java    From pfe-samples with MIT License 6 votes vote down vote up
@DB
public Result create() {
    Form<CreateItem> submission = Form.form(CreateItem.class).bindFromRequest();
    if (submission.hasErrors()) {
        return render(
                version(MimeTypes.HTML, () -> badRequest(views.html.createForm.render(submission))),
                version(MimeTypes.JSON, () -> badRequest(submission.errorsAsJson()))
        );
    } else {
        CreateItem createItem = submission.get();
        Item item = service.shop.create(createItem.name, createItem.price);
        if (item != null) {
            return render(
                    version(MimeTypes.HTML, () -> redirect(routes.Items.details(item.id))),
                    version(MimeTypes.JSON, () -> ok(Json.toJson(item)))
            );
        } else {
            return internalServerError();
        }
    }
}
 
Example 3
Source File: ItemMultipleChoiceConfAdapter.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String processRequestForm(Form form) {
    Form<ItemMultipleChoiceConfForm> realForm = (Form<ItemMultipleChoiceConfForm>) form;
    ItemMultipleChoiceConfForm itemForm = realForm.get();

    ItemMultipleChoiceConf itemConf = new ItemMultipleChoiceConf();
    itemConf.statement = itemForm.statement;
    itemConf.score = itemForm.score;
    itemConf.penalty = itemForm.penalty;
    ImmutableList.Builder<ItemChoice> itemChoiceBuilder = ImmutableList.builder();
    for (int i = 0; i < itemForm.choiceContents.size(); ++i) {
        boolean isCorrect = false;
        if ((itemForm.isCorrects != null) && (itemForm.isCorrects.size() > i) && (itemForm.isCorrects.get(i) != null)) {
            isCorrect = true;
        }
        itemChoiceBuilder.add(new ItemChoice(itemForm.choiceAliases.get(i), itemForm.choiceContents.get(i), isCorrect));
    }
    itemConf.choices = itemChoiceBuilder.build();

    return new Gson().toJson(itemConf);
}
 
Example 4
Source File: LessonController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postEditLesson(long lessonId) throws LessonNotFoundException {
    Lesson lesson = lessonService.findLessonById(lessonId);

    if (!LessonControllerUtils.isAllowedToUpdateLesson(lessonService, lesson)) {
        return notFound();
    }

    Form<LessonEditForm> lessonEditForm = Form.form(LessonEditForm.class).bindFromRequest();

    if (formHasErrors(lessonEditForm)) {
        return showEditLesson(lessonEditForm, lesson);
    }

    if (!lesson.getSlug().equals(lessonEditForm.get().slug) && lessonService.lessonExistsBySlug(lessonEditForm.get().slug)) {
        lessonEditForm.reject("slug", Messages.get("error.lesson.slugExists"));
    }

    LessonEditForm lessonEditData = lessonEditForm.get();
    lessonService.updateLesson(lesson.getJid(), lessonEditData.slug, lessonEditData.additionalNote, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    return redirect(routes.LessonController.viewLesson(lesson.getId()));
}
 
Example 5
Source File: ProblemController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postCreateProblem() {
    Form<ProblemCreateForm> problemCreateForm = Form.form(ProblemCreateForm.class).bindFromRequest();

    if (formHasErrors(problemCreateForm)) {
        return showCreateProblem(problemCreateForm);
    }

    if (problemService.problemExistsBySlug(problemCreateForm.get().slug)) {
        problemCreateForm.reject("slug", Messages.get("error.problem.slugExists"));
    }

    ProblemCreateForm problemCreateData = problemCreateForm.get();
    ProblemControllerUtils.setJustCreatedProblem(problemCreateData.slug, problemCreateData.additionalNote, problemCreateData.initLanguageCode);

    if (problemCreateData.type.equals(ProblemType.PROGRAMMING.name())) {
        return redirect(org.iatoki.judgels.sandalphon.problem.programming.routes.ProgrammingProblemController.createProgrammingProblem());
    } else if (problemCreateData.type.equals(ProblemType.BUNDLE.name())) {
        return redirect(org.iatoki.judgels.sandalphon.problem.bundle.routes.BundleProblemController.createBundleProblem());
    }

    return internalServerError();
}
 
Example 6
Source File: ProblemController.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postEditProblem(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAllowedToUpdateProblem(problemService, problem)) {
        return notFound();
    }

    Form<ProblemEditForm> problemEditForm = Form.form(ProblemEditForm.class).bindFromRequest();

    if (formHasErrors(problemEditForm)) {
        return showEditProblem(problemEditForm, problem);
    }

    if (!problem.getSlug().equals(problemEditForm.get().slug) && problemService.problemExistsBySlug(problemEditForm.get().slug)) {
        problemEditForm.reject("slug", Messages.get("error.problem.slugExists"));
    }

    ProblemEditForm problemEditData = problemEditForm.get();
    problemService.updateProblem(problem.getJid(), problemEditData.slug, problemEditData.additionalNote, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    return redirect(routes.ProblemController.viewProblem(problem.getId()));
}
 
Example 7
Source File: Account.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
@SubjectPresent
public static Result doLink() {
	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.LocalAuthController.index());
	}

	final Form<Accept> filledForm = ACCEPT_FORM.bindFromRequest();
	if (filledForm.hasErrors()) {
		// User did not select whether to link or not link
		return badRequest(ask_link.render(filledForm, u));
	} else {
		// User made a choice :)
		final boolean link = filledForm.get().accept;
		if (link) {
			flash(LocalAuthController.FLASH_MESSAGE_KEY,
					Messages.get("playauthenticate.accounts.link.success"));
		}
		return PlayAuthenticate.link(ctx(), link);
	}
}
 
Example 8
Source File: ItemShortAnswerConfAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String processRequestForm(Form form) {
    Form<ItemShortAnswerConfForm> realForm = (Form<ItemShortAnswerConfForm>) form;
    ItemShortAnswerConfForm itemForm = realForm.get();
    ItemShortAnswerConf itemConf = new ItemShortAnswerConf();
    itemConf.statement = itemForm.statement;
    itemConf.score = itemForm.score;
    itemConf.penalty = itemForm.penalty;
    itemConf.inputValidationRegex = itemForm.inputValidationRegex;
    itemConf.gradingRegex = itemForm.gradingRegex;

    return new Gson().toJson(itemConf);
}
 
Example 9
Source File: ItemStatementConfAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getMetaFromForm(Form form) {
    Form<ItemStatementConfForm> realForm = (Form<ItemStatementConfForm>) form;
    ItemStatementConfForm itemForm = realForm.get();

    return itemForm.meta;
}
 
Example 10
Source File: Account.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
@SubjectPresent
public static 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.LocalAuthController.index());
	}

	final Form<Accept> filledForm = ACCEPT_FORM.bindFromRequest();
	if (filledForm.hasErrors()) {
		// User did not select whether to merge or not merge
		return badRequest(ask_merge.render(filledForm, aUser, bUser));
	} else {
		// User made a choice :)
		final boolean merge = filledForm.get().accept;
		if (merge) {
			flash(LocalAuthController.FLASH_MESSAGE_KEY,
					Messages.get("playauthenticate.accounts.merge.success"));
		}
		return PlayAuthenticate.merge(ctx(), merge);
	}
}
 
Example 11
Source File: ItemMultipleChoiceConfAdapter.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getMetaFromForm(Form form) {
    Form<ItemMultipleChoiceConfForm> realForm = (Form<ItemMultipleChoiceConfForm>) form;
    ItemMultipleChoiceConfForm itemForm = realForm.get();

    return itemForm.meta;
}
 
Example 12
Source File: BundleProblemPartnerController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postEditPartner(long problemId, long partnerId) throws ProblemNotFoundException, ProblemPartnerNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAuthorOrAbove(problem)) {
        return notFound();
    }

    ProblemPartner problemPartner = problemService.findProblemPartnerById(partnerId);

    Form<ProblemPartnerUpsertForm> problemForm = Form.form(ProblemPartnerUpsertForm.class).bindFromRequest();
    Form<BundlePartnerUpsertForm> bundleForm = Form.form(BundlePartnerUpsertForm.class).bindFromRequest();

    if (formHasErrors(problemForm) || formHasErrors(bundleForm)) {
        return showEditPartner(problemForm, bundleForm, problem, problemPartner);
    }

    ProblemPartnerUpsertForm problemData = problemForm.get();

    ProblemPartnerConfig problemConfig = new ProblemPartnerConfigBuilder()
          .setIsAllowedToUpdateProblem(problemData.isAllowedToUpdateProblem)
          .setIsAllowedToUpdateStatement(problemData.isAllowedToUpdateStatement)
          .setIsAllowedToUploadStatementResources(problemData.isAllowedToUploadStatementResources)
          .setAllowedStatementLanguagesToView(PartnerControllerUtils.splitByComma(problemData.allowedStatementLanguagesToView))
          .setAllowedStatementLanguagesToUpdate(PartnerControllerUtils.splitByComma(problemData.allowedStatementLanguagesToUpdate))
          .setIsAllowedToManageStatementLanguages(problemData.isAllowedToManageStatementLanguages)
          .setIsAllowedToViewVersionHistory(problemData.isAllowedToViewVersionHistory)
          .setIsAllowedToRestoreVersionHistory(problemData.isAllowedToRestoreVersionHistory)
          .setIsAllowedToManageProblemClients(problemData.isAllowedToManageProblemClients)
          .build();

    BundlePartnerUpsertForm bundleData = bundleForm.get();

    BundleProblemPartnerConfig bundleConfig = new BundleProblemPartnerConfig(bundleData.isAllowedToSubmit, bundleData.isAllowedToManageItems);

    problemService.updateProblemPartner(partnerId, problemConfig, bundleConfig, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    return redirect(org.iatoki.judgels.sandalphon.problem.base.partner.routes.ProblemPartnerController.editPartner(problem.getId(), problemPartner.getId()));
}
 
Example 13
Source File: ProgrammingProblemGradingController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postEditLanguageRestriction(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProgrammingProblemControllerUtils.isAllowedToManageGrading(problemService, problem)) {
        return notFound();
    }

    Form<LanguageRestrictionEditForm> languageRestrictionEditForm = Form.form(LanguageRestrictionEditForm.class).bindFromRequest(request());

    if (formHasErrors(languageRestrictionEditForm)) {
        return showEditLanguageRestriction(languageRestrictionEditForm, problem);
    }

    problemService.createUserCloneIfNotExists(IdentityUtils.getUserJid(), problem.getJid());

    LanguageRestrictionEditForm data = languageRestrictionEditForm.get();
    LanguageRestriction languageRestriction = LanguageRestrictionAdapter.createLanguageRestrictionFromForm(data.allowedLanguageNames, data.isAllowedAll);

    try {
        programmingProblemService.updateLanguageRestriction(IdentityUtils.getUserJid(), problem.getJid(), languageRestriction);
    } catch (IOException e) {
        languageRestrictionEditForm.reject("problem.programming.language.error.cantUpdate");
        return showEditLanguageRestriction(languageRestrictionEditForm, problem);
    }

    return redirect(routes.ProgrammingProblemGradingController.editLanguageRestriction(problem.getId()));
}
 
Example 14
Source File: ProblemVersionController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postCommitVersionLocalChanges(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isPartnerOrAbove(problemService, problem)) {
        return notFound();
    }

    Form<VersionCommitForm> versionCommitForm = Form.form(VersionCommitForm.class).bindFromRequest();
    if (formHasErrors(versionCommitForm)) {
        boolean isClean = !problemService.userCloneExists(IdentityUtils.getUserJid(), problem.getJid());
        return showViewVersionLocalChanges(versionCommitForm, problem, isClean);
    }

    VersionCommitForm versionCommitData = versionCommitForm.get();

    if (problemService.fetchUserClone(IdentityUtils.getUserJid(), problem.getJid())) {
        flash("localChangesError", Messages.get("problem.version.local.cantCommit"));
    } else if (!problemService.commitThenMergeUserClone(IdentityUtils.getUserJid(), problem.getJid(), versionCommitData.title, versionCommitData.description, IdentityUtils.getIpAddress())) {
        flash("localChangesError", Messages.get("problem.version.local.cantMerge"));
    } else if (!problemService.pushUserClone(IdentityUtils.getUserJid(), problem.getJid(), IdentityUtils.getIpAddress())) {
        flash("localChangesError", Messages.get("problem.version.local.cantMerge"));
    } else {
        try {
            problemService.discardUserClone(IdentityUtils.getUserJid(), problem.getJid());
        } catch (IOException e) {
            // do nothing
        }
    }

    return redirect(routes.ProblemVersionController.viewVersionLocalChanges(problem.getId()));
}
 
Example 15
Source File: Items.java    From pfe-samples with MIT License 5 votes vote down vote up
@DB
public Result update(Long id) {
    Form<CreateItem> submission = Form.form(CreateItem.class).bindFromRequest();
    if (submission.hasErrors()) {
        return badRequest(submission.errorsAsJson());
    } else {
        CreateItem updateItem = submission.get();
        Item updated = service.shop.update(id, updateItem.name, updateItem.price);
        if (updated != null) {
            return ok(Json.toJson(updated));
        } else {
            return internalServerError();
        }
    }
}
 
Example 16
Source File: LessonVersionController.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postCommitVersionLocalChanges(long lessonId) throws LessonNotFoundException {
    Lesson lesson = lessonService.findLessonById(lessonId);

    if (!LessonControllerUtils.isPartnerOrAbove(lessonService, lesson)) {
        return notFound();
    }

    Form<VersionCommitForm> versionCommitForm = Form.form(VersionCommitForm.class).bindFromRequest();
    if (formHasErrors(versionCommitForm)) {
        boolean isClean = !lessonService.userCloneExists(IdentityUtils.getUserJid(), lesson.getJid());
        return showViewVersionLocalChanges(versionCommitForm, lesson, isClean);
    }

    VersionCommitForm versionCommitData = versionCommitForm.get();

    if (lessonService.fetchUserClone(IdentityUtils.getUserJid(), lesson.getJid())) {
        flash("localChangesError", Messages.get("lesson.version.local.cantCommit"));
    } else if (!lessonService.commitThenMergeUserClone(IdentityUtils.getUserJid(), lesson.getJid(), versionCommitData.title, versionCommitData.description, IdentityUtils.getIpAddress())) {
        flash("localChangesError", Messages.get("lesson.version.local.cantMerge"));
    } else if (!lessonService.pushUserClone(IdentityUtils.getUserJid(), lesson.getJid(), IdentityUtils.getIpAddress())) {
        flash("localChangesError", Messages.get("lesson.version.local.cantMerge"));
    } else {
        try {
            lessonService.discardUserClone(IdentityUtils.getUserJid(), lesson.getJid());
        } catch (IOException e) {
            // do nothing
        }
    }

    return redirect(routes.LessonVersionController.viewVersionLocalChanges(lesson.getId()));
}
 
Example 17
Source File: GroupController.java    From htwplus with MIT License 4 votes vote down vote up
public Result add() {
    Navigation.set(Level.GROUPS, "Erstellen");

    // Get data from request
    Form<Group> filledForm = groupForm.bindFromRequest();

    // Perform JPA Validation
    if (filledForm.hasErrors()) {
        return badRequest(create.render(filledForm));
    } else {
        Group group = filledForm.get();
        int groupType;
        try {
            groupType = Integer.parseInt(filledForm.data().get("type"));
        } catch (NumberFormatException ex) {
            filledForm.reject("type", "Bitte eine Sichtbarkeit wählen!");
            return ok(create.render(filledForm));
        }

        String successMsg;
        switch (groupType) {

            case 0:
                group.groupType = GroupType.open;
                successMsg = "Öffentliche Gruppe";
                break;

            case 1:
                group.groupType = GroupType.close;
                successMsg = "Geschlossene Gruppe";
                break;

            case 2:
                group.groupType = GroupType.course;
                successMsg = "Kurs";
                String token = filledForm.data().get("token");
                if (!Group.validateToken(token)) {
                    filledForm.reject("token", "Bitte einen Token zwischen 4 und 45 Zeichen eingeben!");
                    return ok(create.render(filledForm));
                }

                if (!Secured.createCourse()) {
                    flash("error", "Du darfst leider keinen Kurs erstellen");
                    return badRequest(create.render(filledForm));
                }
                break;

            default:
                filledForm.reject("Nicht möglich!");
                return ok(create.render(filledForm));
        }

        groupManager.createWithGroupAccount(group, Component.currentAccount());
        flash("success", successMsg + " erstellt!");
        return redirect(controllers.routes.GroupController.stream(group.id, PAGE, false));
    }
}
 
Example 18
Source File: Signup.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
public static Result doResetPassword() {
	com.feth.play.module.pa.controllers.Authenticate.noCache(response());
	final Form<PasswordReset> filledForm = PASSWORD_RESET_FORM
			.bindFromRequest();
	if (filledForm.hasErrors()) {
		return badRequest(password_reset.render(filledForm));
	} else {
		final String token = filledForm.get().token;
		final String newPassword = filledForm.get().password;

		final TokenAction ta = tokenIsValid(token, Type.PASSWORD_RESET);
		if (ta == null) {
			return badRequest(no_token_or_invalid.render());
		}
		final User u = ta.targetUser;
		try {
			// Pass true for the second parameter if you want to
			// automatically create a password and the exception never to
			// happen
			u.resetPassword(new GSNUsernamePasswordAuthUser(newPassword),
					false);
		} catch (final RuntimeException re) {
			flash(LocalAuthController.FLASH_MESSAGE_KEY,
					Messages.get("playauthenticate.reset_password.message.no_password_account"));
		}
		final boolean login = GSNUsernamePasswordAuthProvider.getProvider()
				.isLoginAfterPasswordReset();
		if (login) {
			// automatically log in
			flash(LocalAuthController.FLASH_MESSAGE_KEY,
					Messages.get("playauthenticate.reset_password.message.success.auto_login"));

			return PlayAuthenticate.loginAndRedirect(ctx(),
					new GSNLoginUsernamePasswordAuthUser(u.email));
		} else {
			// send the user to the login page
			flash(LocalAuthController.FLASH_MESSAGE_KEY,
					Messages.get("playauthenticate.reset_password.message.success.manual_login"));
		}
		return redirect(routes.LocalAuthController.login());
	}
}
 
Example 19
Source File: ProgrammingProblemPartnerController.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@Transactional
@RequireCSRFCheck
public Result postAddPartner(long problemId) throws ProblemNotFoundException {
    Problem problem = problemService.findProblemById(problemId);

    if (!ProblemControllerUtils.isAuthorOrAbove(problem)) {
        return notFound();
    }

    Form<ProblemPartnerUsernameForm> usernameForm = Form.form(ProblemPartnerUsernameForm.class).bindFromRequest();
    Form<ProblemPartnerUpsertForm> problemForm = Form.form(ProblemPartnerUpsertForm.class).bindFromRequest();
    Form<ProgrammingPartnerUpsertForm> programmingForm = Form.form(ProgrammingPartnerUpsertForm.class).bindFromRequest();

    if (formHasErrors(usernameForm) || formHasErrors(problemForm) || formHasErrors(programmingForm)) {
        return showAddPartner(usernameForm, problemForm, programmingForm, problem);
    }

    String username = usernameForm.get().username;
    ProblemPartnerUpsertForm problemData = problemForm.get();
    ProgrammingPartnerUpsertForm programmingData = programmingForm.get();

    Map<String, String> usernameToJidMap = userSearchService.translateUsernamesToJids(ImmutableSet.of(username));

    if (!usernameToJidMap.containsKey(username)) {
        usernameForm.reject("username", Messages.get("problem.partner.usernameNotFound"));
        return showAddPartner(usernameForm, problemForm, programmingForm, problem);
    }

    String userJid = usernameToJidMap.get(username);

    JidCacheServiceImpl.getInstance().putDisplayName(userJid, JudgelsPlayUtils.getUserDisplayName(username), IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    if (problemService.isUserPartnerForProblem(problem.getJid(), userJid)) {
        usernameForm.reject("username", Messages.get("problem.partner.already"));
        return showAddPartner(usernameForm, problemForm, programmingForm, problem);
    }

    ProblemPartnerConfig problemConfig = new ProblemPartnerConfigBuilder()
          .setIsAllowedToUpdateProblem(problemData.isAllowedToUpdateProblem)
          .setIsAllowedToUpdateStatement(problemData.isAllowedToUpdateStatement)
          .setIsAllowedToUploadStatementResources(problemData.isAllowedToUploadStatementResources)
          .setAllowedStatementLanguagesToView(PartnerControllerUtils.splitByComma(problemData.allowedStatementLanguagesToView))
          .setAllowedStatementLanguagesToUpdate(PartnerControllerUtils.splitByComma(problemData.allowedStatementLanguagesToUpdate))
          .setIsAllowedToManageStatementLanguages(problemData.isAllowedToManageStatementLanguages)
          .setIsAllowedToViewVersionHistory(problemData.isAllowedToViewVersionHistory)
          .setIsAllowedToRestoreVersionHistory(problemData.isAllowedToRestoreVersionHistory)
          .setIsAllowedToManageProblemClients(problemData.isAllowedToManageProblemClients)
          .build();

    ProgrammingProblemPartnerConfig programmingConfig = new ProgrammingProblemPartnerConfigBuilder()
          .setIsAllowedToSubmit(programmingData.isAllowedToSubmit)
          .setIsAllowedToManageGrading(programmingData.isAllowedToManageGrading)
          .build();

    problemService.createProblemPartner(problem.getJid(), userJid, problemConfig, programmingConfig, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());

    return redirect(org.iatoki.judgels.sandalphon.problem.base.partner.routes.ProblemPartnerController.viewPartners(problem.getId()));
}
 
Example 20
Source File: Signup.java    From gsn with GNU General Public License v3.0 4 votes vote down vote up
public static Result doForgotPassword() {
	com.feth.play.module.pa.controllers.Authenticate.noCache(response());
	final Form<GSNIdentity> filledForm = FORGOT_PASSWORD_FORM
			.bindFromRequest();
	if (filledForm.hasErrors()) {
		// User did not fill in his/her email
		return badRequest(password_forgot.render(filledForm));
	} else {
		// The email address given *BY AN UNKNWON PERSON* to the form - we
		// should find out if we actually have a user with this email
		// address and whether password login is enabled for him/her. Also
		// only send if the email address of the user has been verified.
		final String email = filledForm.get().email;

		// We don't want to expose whether a given email address is signed
		// up, so just say an email has been sent, even though it might not
		// be true - that's protecting our user privacy.
		flash(LocalAuthController.FLASH_MESSAGE_KEY,
				Messages.get(
						"playauthenticate.reset_password.message.instructions_sent",
						email));

		final User user = User.findByEmail(email);
		if (user != null) {
			// yep, we have a user with this email that is active - we do
			// not know if the user owning that account has requested this
			// reset, though.
			final GSNUsernamePasswordAuthProvider provider = GSNUsernamePasswordAuthProvider
					.getProvider();
			// User exists
			if (user.emailValidated) {
				provider.sendPasswordResetMailing(user, ctx());
				// In case you actually want to let (the unknown person)
				// know whether a user was found/an email was sent, use,
				// change the flash message
			} else {
				// We need to change the message here, otherwise the user
				// does not understand whats going on - we should not verify
				// with the password reset, as a "bad" user could then sign
				// up with a fake email via OAuth and get it verified by an
				// a unsuspecting user that clicks the link.
				flash(LocalAuthController.FLASH_MESSAGE_KEY,
						Messages.get("playauthenticate.reset_password.message.email_not_verified"));

				// You might want to re-send the verification email here...
				provider.sendVerifyEmailMailingAfterSignup(user, ctx());
			}
		}

		return redirect(routes.LocalAuthController.index());
	}
}