本文整理汇总了Java中org.iatoki.judgels.play.JudgelsPlayUtils类的典型用法代码示例。如果您正苦于以下问题:Java JudgelsPlayUtils类的具体用法?Java JudgelsPlayUtils怎么用?Java JudgelsPlayUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JudgelsPlayUtils类属于org.iatoki.judgels.play包,在下文中一共展示了JudgelsPlayUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerUser
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public String registerUser(String username, String name, String email, String password) throws IllegalStateException {
try {
UserModel userModel = new UserModel();
userModel.username = username;
userModel.name = name;
userModel.password = PasswordHash.createHash(password);
userModel.profilePictureImageName = "avatar-default.png";
userModel.roles = "user";
userDao.persist(userModel, "guest", IdentityUtils.getIpAddress());
String emailCode = JudgelsPlayUtils.hashMD5(UUID.randomUUID().toString());
UserEmailModel emailModel = new UserEmailModel(email, emailCode);
emailModel.userJid = userModel.jid;
userEmailDao.persist(emailModel, "guest", IdentityUtils.getIpAddress());
return emailCode;
} catch (ConstraintViolationException | NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new IllegalStateException(e);
}
}
示例2: createClient
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public void createClient(String name, String applicationType, List<String> scopes, List<String> redirectURIs) {
ClientModel clientModel = new ClientModel();
clientModel.name = name;
clientModel.secret = JudgelsPlayUtils.generateNewSecret();
clientModel.applicationType = applicationType;
List<String> scopeList = scopes.stream().filter(s -> ((s != null) && (Scope.valueOf(s) != null))).collect(Collectors.toList());
clientModel.scopes = StringUtils.join(scopeList, ",");
clientDao.persist(clientModel, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
for (String redirectURI : redirectURIs) {
RedirectURIModel redirectURIModel = new RedirectURIModel();
redirectURIModel.redirectURI = redirectURI;
redirectURIModel.clientJid = clientModel.jid;
redirectURIDao.persist(redirectURIModel, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
}
}
示例3: login_ValidUserUnverifiedEmail_ThrowsEmailNotVerifiedException
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Test(expectedExceptions = EmailNotVerifiedException.class)
public void login_ValidUserUnverifiedEmail_ThrowsEmailNotVerifiedException() throws UserNotFoundException, EmailNotVerifiedException {
String username = "alice123";
String password = "alicepassword";
UserModel userModel = new UserModel();
userModel.jid = "JIDU0101";
userModel.username = username;
userModel.password = JudgelsPlayUtils.hashSHA256(password);
Mockito.when(userDao.existByUsername(username)).thenReturn(true);
Mockito.when(userDao.findByUsername(username)).thenReturn(userModel);
UserEmailModel userEmailModel = new UserEmailModel();
userEmailModel.userJid = userModel.jid;
userEmailModel.emailVerified = false;
Mockito.when(userEmailDao.findByUserJid(userEmailModel.userJid)).thenReturn(userEmailModel);
UserInfo user = userAccountService.login(username, password);
Assert.fail("Unreachable");
}
示例4: login_ValidUsernameInvalidPassword_ReturnsNull
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Test
public void login_ValidUsernameInvalidPassword_ReturnsNull() throws UserNotFoundException, EmailNotVerifiedException {
String username = "alice123";
String password = "bobpassword";
String validPassword = "alicepassword";
UserModel userModel = new UserModel();
userModel.jid = "JIDU0101";
userModel.username = username;
userModel.password = JudgelsPlayUtils.hashSHA256(validPassword);
Mockito.when(userDao.existByUsername(username)).thenReturn(true);
Mockito.when(userDao.findByUsername(username)).thenReturn(userModel);
UserEmailModel userEmailModel = new UserEmailModel();
userEmailModel.userJid = userModel.jid;
Mockito.when(userEmailDao.findByUserJid(userEmailModel.userJid)).thenReturn(userEmailModel);
UserInfo user = userAccountService.login(username, password);
Assert.assertNull(user, "UserInfo not null");
}
示例5: createContestTeam
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public ContestTeam createContestTeam(String contestJid, String name, File teamImage, String extension, String userJid, String userIpAddress) throws IOException {
ContestModel contestModel = contestDao.findByJid(contestJid);
ContestTeamModel contestTeamModel = new ContestTeamModel();
contestTeamModel.contestJid = contestModel.jid;
contestTeamModel.name = name;
contestTeamModel.teamImageName = "team-default.png";
contestTeamDao.persist(contestTeamModel, userJid, userIpAddress);
String newImageName = contestTeamModel.jid + "-" + JudgelsPlayUtils.hashMD5(UUID.randomUUID().toString()) + "." + extension;
teamAvatarFileSystemProvider.uploadFile(ImmutableList.of(), teamImage, newImageName);
teamAvatarFileSystemProvider.makeFilePublic(ImmutableList.of(newImageName));
contestTeamModel.teamImageName = newImageName;
contestTeamDao.edit(contestTeamModel, userJid, userIpAddress);
contestDao.edit(contestModel, userJid, userIpAddress);
return createContestTeamFromModel(contestTeamModel, ImmutableList.of(), ImmutableList.of());
}
示例6: updateContestTeam
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public void updateContestTeam(String contestTeamJid, String name, File teamImage, String extension, String userJid, String userIpAddress) throws IOException {
ContestTeamModel contestTeamModel = contestTeamDao.findByJid(contestTeamJid);
String newImageName = contestTeamModel.jid + "-" + JudgelsPlayUtils.hashMD5(UUID.randomUUID().toString()) + "." + extension;
teamAvatarFileSystemProvider.uploadFile(ImmutableList.of(), teamImage, newImageName);
teamAvatarFileSystemProvider.makeFilePublic(ImmutableList.of(newImageName));
contestTeamModel.name = name;
contestTeamModel.teamImageName = newImageName;
contestTeamDao.edit(contestTeamModel, userJid, userIpAddress);
ContestModel contestModel = contestDao.findByJid(contestTeamModel.contestJid);
contestDao.edit(contestModel, userJid, userIpAddress);
}
示例7: postCreateAnnouncement
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Transactional
@RequireCSRFCheck
public Result postCreateAnnouncement(long contestId) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (contest.isLocked() || !isAllowedToSuperviseAnnouncements(contest)) {
return ContestControllerUtils.getInstance().tryEnteringContest(contest, IdentityUtils.getUserJid());
}
Form<ContestAnnouncementUpsertForm> contestAnnouncementUpsertForm = Form.form(ContestAnnouncementUpsertForm.class).bindFromRequest();
if (formHasErrors(contestAnnouncementUpsertForm)) {
return showCreateAnnouncement(contestAnnouncementUpsertForm, contest);
}
ContestAnnouncementUpsertForm contestAnnouncementUpsertData = contestAnnouncementUpsertForm.get();
ContestAnnouncement contestAnnouncement = contestAnnouncementService.createContestAnnouncement(contest.getJid(), contestAnnouncementUpsertData.title, JudgelsPlayUtils.toSafeHtml(contestAnnouncementUpsertData.content), ContestAnnouncementStatus.valueOf(contestAnnouncementUpsertData.status), IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
UrielControllerUtils.getInstance().addActivityLog(BasicActivityKeys.ADD_IN.construct(CONTEST, contest.getJid(), contest.getName(), ANNOUNCEMENT, contestAnnouncement.getJid(), contestAnnouncement.getTitle()));
return redirect(routes.ContestAnnouncementController.viewAnnouncements(contest.getId()));
}
示例8: postEditAnnouncement
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Transactional
@RequireCSRFCheck
public Result postEditAnnouncement(long contestId, long contestAnnouncementId) throws ContestNotFoundException, ContestAnnouncementNotFoundException {
Contest contest = contestService.findContestById(contestId);
ContestAnnouncement contestAnnouncement = contestAnnouncementService.findContestAnnouncementById(contestAnnouncementId);
if (contest.isLocked() || !isAllowedToSuperviseAnnouncements(contest) || !contestAnnouncement.getContestJid().equals(contest.getJid())) {
return ContestControllerUtils.getInstance().tryEnteringContest(contest, IdentityUtils.getUserJid());
}
Form<ContestAnnouncementUpsertForm> contestAnnouncementUpsertForm = Form.form(ContestAnnouncementUpsertForm.class).bindFromRequest();
if (formHasErrors(contestAnnouncementUpsertForm)) {
return showEditAnnouncement(contestAnnouncementUpsertForm, contest, contestAnnouncement);
}
ContestAnnouncementUpsertForm contestAnnouncementUpsertData = contestAnnouncementUpsertForm.get();
contestAnnouncementService.updateContestAnnouncement(contestAnnouncement.getJid(), contestAnnouncementUpsertData.title, JudgelsPlayUtils.toSafeHtml(contestAnnouncementUpsertData.content), ContestAnnouncementStatus.valueOf(contestAnnouncementUpsertData.status), IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
if (!contestAnnouncement.getTitle().equals(contestAnnouncementUpsertData.title)) {
UrielControllerUtils.getInstance().addActivityLog(BasicActivityKeys.RENAME_IN.construct(CONTEST, contest.getJid(), contest.getName(), ANNOUNCEMENT, contestAnnouncement.getJid(), contestAnnouncement.getTitle(), contestAnnouncementUpsertData.title));
}
UrielControllerUtils.getInstance().addActivityLog(BasicActivityKeys.EDIT_IN.construct(CONTEST, contest.getJid(), contest.getName(), ANNOUNCEMENT, contestAnnouncement.getJid(), contestAnnouncementUpsertData.title));
return redirect(routes.ContestAnnouncementController.viewAnnouncements(contest.getId()));
}
示例9: postCreateContest
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Authorized(value = "admin")
@Transactional
@RequireCSRFCheck
public Result postCreateContest() {
Form<ContestUpsertForm> contestUpsertForm = Form.form(ContestUpsertForm.class).bindFromRequest();
if (formHasErrors(contestUpsertForm)) {
return showCreateContest(contestUpsertForm);
}
ContestUpsertForm contestUpsertData = contestUpsertForm.get();
Contest contest = contestService.createContest(contestUpsertData.name, JudgelsPlayUtils.toSafeHtml(contestUpsertData.description), ContestStyle.valueOf(contestUpsertData.style), IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
UrielControllerUtils.getInstance().addActivityLog(BasicActivityKeys.CREATE.construct(CONTEST, contest.getJid(), contest.getName()));
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.editContestSpecificConfig(contest.getId()));
}
示例10: postEditContestGeneralConfig
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Transactional
@RequireCSRFCheck
public Result postEditContestGeneralConfig(long contestId) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (contest.isLocked() || !ContestControllerUtils.getInstance().isAllowedToManageContest(contest, IdentityUtils.getUserJid())) {
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.editContestGeneralConfig(contestId));
}
Form<ContestUpsertForm> contestUpsertForm = Form.form(ContestUpsertForm.class).bindFromRequest();
if (formHasErrors(contestUpsertForm)) {
return showEditContestGeneralConfig(contestUpsertForm, contest);
}
ContestUpsertForm contestUpsertData = contestUpsertForm.get();
contestService.updateContest(contest.getJid(), contestUpsertData.name, JudgelsPlayUtils.toSafeHtml(contestUpsertData.description), ContestStyle.valueOf(contestUpsertData.style), IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
if (!contest.getName().equals(contestUpsertData.name)) {
UrielControllerUtils.getInstance().addActivityLog(BasicActivityKeys.RENAME.construct(CONTEST, contest.getJid(), contest.getName(), contestUpsertData.name));
}
UrielControllerUtils.getInstance().addActivityLog(BasicActivityKeys.EDIT.construct(CONTEST, contest.getJid(), contestUpsertData.name));
return redirect(org.iatoki.judgels.uriel.contest.routes.ContestController.editContestGeneralConfig(contestId));
}
示例11: afterLogin
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Transactional
public Result afterLogin(String returnUri) {
if (!session().containsKey("role")) {
String newReturnUri = routes.ApplicationController.afterLogin(returnUri).absoluteURL(request(), request().secure());
return redirect(routes.ApplicationController.authRole(newReturnUri));
}
JudgelsPlayUtils.updateUserJidCache(JidCacheServiceImpl.getInstance());
JophielClientControllerUtils.updateUserAvatarCache(AvatarCacheServiceImpl.getInstance());
if (JudgelsPlayUtils.hasViewPoint()) {
try {
UrielUtils.backupSession();
UrielUtils.setUserSession(jophielPublicAPI.findUserByJid(JudgelsPlayUtils.getViewPoint()), userService.findUserByJid(JudgelsPlayUtils.getViewPoint()));
} catch (JudgelsAPIClientException e) {
JudgelsPlayUtils.removeViewPoint();
UrielUtils.restoreSession();
}
}
return redirect(returnUri);
}
示例12: postViewAs
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Transactional
public Result postViewAs() {
Form<ViewpointForm> viewpointForm = Form.form(ViewpointForm.class).bindFromRequest();
if (!formHasErrors(viewpointForm) && UrielUtils.trullyHasRole("admin")) {
ViewpointForm viewpointData = viewpointForm.get();
try {
JophielUser jophielUser = jophielPublicAPI.findUserByUsername(viewpointData.username);
if (jophielUser != null) {
userService.upsertUserFromJophielUser(jophielUser, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
if (!JudgelsPlayUtils.hasViewPoint()) {
UrielUtils.backupSession();
}
JudgelsPlayUtils.setViewPointInSession(jophielUser.getJid());
UrielUtils.setUserSession(jophielUser, userService.findUserByJid(jophielUser.getJid()));
}
} catch (JudgelsAPIClientException e) {
// do nothing
e.printStackTrace();
}
}
return redirectToReferer();
}
示例13: forgotPassword
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public String forgotPassword(String username, String email) {
UserModel userModel = userDao.findByUsername(username);
String code = JudgelsPlayUtils.hashMD5(UUID.randomUUID().toString());
UserForgotPasswordModel forgotPasswordModel = new UserForgotPasswordModel();
forgotPasswordModel.userJid = userModel.jid;
forgotPasswordModel.code = code;
forgotPasswordModel.used = false;
userForgotPasswordDao.persist(forgotPasswordModel, "guest", IdentityUtils.getIpAddress());
return code;
}
示例14: login
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public UserInfo login(String usernameOrEmail, String password) throws UserNotFoundException, EmailNotVerifiedException {
try {
UserModel userModel;
UserEmailModel emailModel;
if (userDao.existByUsername(usernameOrEmail)) {
userModel = userDao.findByUsername(usernameOrEmail);
emailModel = userEmailDao.findByUserJid(userModel.jid);
} else if (userEmailDao.isExistByEmail(usernameOrEmail)) {
emailModel = userEmailDao.findByEmail(usernameOrEmail);
userModel = userDao.findByJid(emailModel.userJid);
} else {
throw new UserNotFoundException();
}
if ((userModel.password.contains(":")) && (PasswordHash.validatePassword(password, userModel.password))) {
if (emailModel.emailVerified) {
return createUserFromModels(userModel, emailModel);
} else {
throw new EmailNotVerifiedException();
}
} else if (userModel.password.equals(JudgelsPlayUtils.hashSHA256(password))) {
userModel.password = PasswordHash.createHash(password);
userDao.edit(userModel, "guest", IdentityUtils.getIpAddress());
if (emailModel.emailVerified) {
return createUserFromModels(userModel, emailModel);
} else {
throw new EmailNotVerifiedException();
}
} else {
return null;
}
} catch (NoResultException | NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new UserNotFoundException();
}
}
示例15: updateProfile
import org.iatoki.judgels.play.JudgelsPlayUtils; //导入依赖的package包/类
@Override
public void updateProfile(String userJid, String name, String password) {
UserModel userModel = userDao.findByJid(userJid);
userModel.name = name;
userModel.password = JudgelsPlayUtils.hashSHA256(password);
userDao.edit(userModel, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress());
Http.Context.current().session().put("name", userModel.name);
}