use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class SecurityConfigurationTest method testLogin.
/**
* Test of login method, of class SecurityConfiguration.
*
* @see SecurityConfiguration#configure(HttpSecurity)
*/
@Test
public void testLogin() throws Exception {
log.info("login");
String url = "/test";
User user = mockDataService.user();
MvcResult result = mvc.perform(post("/login").param("user_id1", user.getId()).param("password1", user.getPassword()).param("url", url)).andExpect(status().isFound()).andExpect(redirectedUrl(url)).andReturn();
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class MockDataService method user.
@Nonnull
public User user(boolean create) {
String userId = idGenerator.apply("user");
User user = User.builder().id(userId).password(userId).school("").nick(userId).build();
if (create) {
accountService.save(user);
}
return user;
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class ModifyUserController method updatePage.
@GetMapping({ "/modifyuserpage", "/modifyuser" })
public String updatePage(Model model, Authentication authentication) {
String userId = authentication != null ? authentication.getName() : null;
User user = accountService.findOne(userId);
model.addAttribute("user", user);
return "users/edit";
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class RegisterController method register.
@PostMapping("/register")
@SuppressWarnings("AssignmentToMethodParameter")
public String register(HttpServletRequest request, @RequestParam("user_id") String userId, @RequestParam("school") String school, @RequestParam("nick") String nick, @RequestParam("password") String password, @RequestParam("email") String email, @RequestParam("rptPassword") String rptPassword) {
contestOnlyService.checkRegister();
ValueCheck.checkUserId(userId);
ValueCheck.checkPassword(password);
ValueCheck.checkEmail(email);
if (!Objects.equals(password, rptPassword)) {
throw new MessageException("Passwords are not match");
}
if (StringUtils.hasText(nick)) {
nick = nick.trim();
} else {
nick = userId;
}
ValueCheck.checkNick(nick);
if (userMapper.findOne(userId) != null) {
throw new MessageException("The ID( " + userId + ") existed");
}
User user = User.builder().id(userId).password(passwordEncoder.encode(password)).email(StringUtils.isEmpty(email) ? null : email).nick(nick).school(school).ip(request.getRemoteAddr()).build();
userMapper.save(user);
log.info("{}", user);
request.setAttribute("user", user);
return "register";
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class ResetPasswordController method doPost.
@PostMapping("/resetPassword")
public void doPost(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "action", required = false) String action, @RequestParam(value = "verify", required = false) String verify, @RequestParam(value = "username", required = false) String username, Locale locale) throws IOException {
response.setContentType("text/javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(false);
String word = null;
if (session != null) {
word = (String) session.getAttribute("word");
session.removeAttribute("word");
}
if (word == null || !word.equalsIgnoreCase(verify)) {
out.print("alert('验证码错误');");
return;
}
User user = userMapper.findOne(username);
if (user == null) {
out.print("alert('用户不存在');");
return;
}
String email = user.getEmail();
if (email == null || !email.toLowerCase().matches(ValueCheck.EMAIL_PATTERN)) {
out.print("alert('该用户未设置邮箱或邮箱格式不对,如需重置密码,请联系管理员!');");
return;
}
try {
String vc = resetPasswordService.getOrCreate(user.getId());
String url = getPath(request, "/resetPassword.html?vc=", vc + "&u=", user.getId());
String title = systemService.getResetPasswordTitle();
Map<String, Object> map = ImmutableMap.of("url", url, "title", Objects.toString(title, ""));
String content = templateEngine.process("users/password", new Context(locale, map));
emailService.send(email, title, content);
} catch (MailException | MessagingException ex) {
log.error("fail to send email", ex);
out.print("alert('邮件发送失败,请稍后再试')");
return;
}
out.print("alert('已经将邮件发送到" + user.getEmail() + ",请点击链接重设密码');");
}
Aggregations