use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class ResetPasswordController method changePassword.
@PostMapping(value = "/resetPassword", params = "action=changePassword")
public void changePassword(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "u", required = false) String userId, @RequestParam(value = "vc", required = false) String vcode) throws IOException {
response.setContentType("text/javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
Optional<User> optional = resetPasswordService.checkVcode(userId, vcode);
if (!optional.isPresent()) {
out.print("alert(\"效链接已失效,请重新获取链接\");");
return;
}
String newPassword = request.getParameter("newPassword");
ValueCheck.checkPassword(newPassword);
User user = optional.get();
userMapper.updateSelective(user.getId(), User.builder().password(passwordEncoder.encode(newPassword)).build());
resetPasswordService.remove(userId);
out.print("alert(\"密码修改成功!\");");
out.print("document.location='" + request.getContextPath() + "'");
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class SearchUserController method searchuser.
@GetMapping("/searchuser")
public String searchuser(Model model, @RequestParam(value = "user_id", defaultValue = "") String keyword, @RequestParam(value = "position", required = false) String position, @PageableDefault(1000) Pageable pageable) {
if (keyword.replace("%", "").length() < 2) {
throw new BusinessException(BusinessCode.USER_SEARCH_KEYWORD_SHORT);
}
String like = keyword;
if (position == null) {
like = "%" + like + "%";
} else if (position.equalsIgnoreCase("begin")) {
like += "%";
} else {
like = "%" + like;
}
Pageable t = pageable;
if (t.getSort() == null) {
t = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), new Sort(new Sort.Order("solved").with(Sort.Direction.DESC), new Sort.Order("submit")));
}
Page<User> users = accountService.findAll(AccountForm.builder().disabled(Boolean.FALSE).query(like).build(), t);
model.addAttribute("query", keyword);
model.addAttribute("users", users);
return "users/search";
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class UserDetailsServiceImpl method loadUserByUsername.
@Nonnull
@Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
User user = userMapper.findOne(userId);
if (user == null) {
throw new UsernameNotFoundException(userId);
}
int role = 0;
for (String rightstr : userRoleMapper.findAllByUserId(user.getId())) {
if (rightstr != null) {
switch(rightstr.toLowerCase()) {
case "administrator":
role = 2;
break;
case "source_browser":
role = Math.max(role, 1);
break;
case "news_publisher":
// TODO
break;
default:
break;
}
}
}
return org.springframework.security.core.userdetails.User.withUsername(userId).password(user.getPassword()).authorities(ROLES.get(role)).build();
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class ModifyUserController method update.
@PostMapping("/modifyuser")
@SuppressWarnings("AssignmentToMethodParameter")
public String update(Model model, @RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword, @RequestParam("rptPassword") String rptPassword, @RequestParam("email") String email, @RequestParam("nick") String nick, @RequestParam("school") String school, Authentication authentication) {
if (!Objects.equals(newPassword, rptPassword)) {
throw new MessageException("Passwords are not match");
}
String userId = authentication.getName();
User user = accountService.findOne(userId);
String password = user.getPassword();
if (!passwordEncoder.matches(oldPassword, password)) {
throw new MessageException("password is not correct");
}
if (StringUtils.isEmpty(nick)) {
nick = userId;
}
if (StringUtils.isEmpty(newPassword)) {
newPassword = oldPassword;
} else {
ValueCheck.checkPassword(newPassword);
}
if (StringUtils.hasText(email)) {
ValueCheck.checkEmail(email);
} else {
email = "";
}
ValueCheck.checkNick(nick);
user = User.builder().id(userId).email(email).nick(nick).password(newPassword).school(school).build();
accountService.updateSelective(userId, user);
model.addAttribute("user", user);
return "modifyusersuccess";
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class UserStatusController method userStatus.
@GetMapping("/userstatus")
@SuppressWarnings("AssignmentToMethodParameter")
public String userStatus(Model model, @RequestParam(value = "size", defaultValue = "3") int display, @RequestParam(value = "user_id", required = false) String userId) {
User user = accountService.findOne(userId);
display = Math.max(Math.min(display, 9), 1);
userId = user.getId();
long rank = userMapper.rank(userId) + 1;
long rankFirst = Math.max(rank - display, 1);
List<User> neighbours = userMapper.neighbours(userId, display);
List<Long> solvedProblems = userProblemMapper.findAllSolvedByUserId(userId);
model.addAttribute("neighbours", neighbours);
model.addAttribute("solvedProblems", solvedProblems);
model.addAttribute("rankFirst", rankFirst);
model.addAttribute("user", user);
model.addAttribute("rank", rank);
log.debug("rankFirst = {}", rankFirst);
return "users/status";
}
Aggregations