use of org.springframework.web.bind.annotation.PostMapping in project FS-Blog by JamesZBL.
the class UserController method fFrontUserLogin.
/**
* 前台用户登录
* 表单提交
*/
@PostMapping("/userlogin.f")
public String fFrontUserLogin(HttpServletRequest request, Model model, @Valid UserLoginForm loginForm, BindingResult bindingResult) throws Exception {
if (bindingResult.hasErrors()) {
List<ObjectError> errors = bindingResult.getAllErrors();
addModelAtt(model, VIEW_MSG, errors.get(0).getDefaultMessage());
return "userlogin";
}
User user = mUserService.loginAuthentication(loginForm);
if (null != user) {
mUserService.joinSession(request, user);
return "redirect:/";
}
addModelAtt(model, VIEW_MSG, "用户名或密码错误");
return "userlogin";
}
use of org.springframework.web.bind.annotation.PostMapping in project zhcet-web by zhcet-amu.
the class PasswordChangeController method savePassword.
@PostMapping
public String savePassword(@Valid PasswordChange passwordChange, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
User user = userService.getLoggedInUser().orElseThrow(UserNotFoundException::new);
if (bindingResult.hasErrors()) {
redirectAttributes.addFlashAttribute("password", passwordChange);
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.password", bindingResult);
} else {
try {
passwordChangeService.changePassword(user, passwordChange);
redirectAttributes.addFlashAttribute("flash_messages", Flash.success("Password was changed successfully"));
return "redirect:/profile/settings#account";
} catch (PasswordValidationException pve) {
redirectAttributes.addFlashAttribute("pass_errors", pve.getMessage());
}
}
return "redirect:/profile/password/change";
}
use of org.springframework.web.bind.annotation.PostMapping in project zhcet-web by zhcet-amu.
the class EmailVerificationController method resendLink.
@PostMapping("/profile/email/resend_link")
public String resendLink(RedirectAttributes redirectAttributes) {
User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
String email = user.getEmail();
if (Utils.isValidEmail(user.getEmail())) {
sendVerificationLink(email, redirectAttributes);
} else {
log.warn("Invalid Email", email);
redirectAttributes.addFlashAttribute("email_error", "The provided email is invalid!");
}
return "redirect:/profile/settings#account";
}
use of org.springframework.web.bind.annotation.PostMapping in project zhcet-web by zhcet-amu.
the class FacultyRegistrationController method uploadFaculty.
@PostMapping("/confirm")
public String uploadFaculty(RedirectAttributes attributes, @SessionAttribute(KEY_FACULTY_REGISTRATION) Confirmation<FacultyMember> confirmation, WebRequest webRequest) {
if (confirmation == null || !confirmation.getErrors().isEmpty()) {
attributes.addFlashAttribute("errors", Collections.singletonList("Unknown Error"));
} else {
try {
String passwordFileLocation = facultyUploadService.savePasswordFile(confirmation);
RealTimeStatus status = realTimeStatusService.install();
facultyUploadService.registerFaculty(confirmation, status);
attributes.addFlashAttribute("task_id_faculty", status.getId());
attributes.addFlashAttribute("file_saved", passwordFileLocation);
attributes.addFlashAttribute("faculty_registered", true);
} catch (IOException e) {
log.error("Error registering faculty", e);
attributes.addFlashAttribute("file_error", true);
} catch (Exception e) {
log.error("Error registering faculty", e);
attributes.addFlashAttribute("faculty_unknown_error", true);
}
webRequest.removeAttribute("confirmFacultyRegistration", RequestAttributes.SCOPE_SESSION);
}
return "redirect:/admin/dean";
}
use of org.springframework.web.bind.annotation.PostMapping in project zhcet-web by zhcet-amu.
the class ProfileController method saveProfile.
@PostMapping("/details")
@PreAuthorize("@authService.isFullyAuthenticated(principal)")
public String saveProfile(@ModelAttribute @Valid UserDetail userDetail, BindingResult result, RedirectAttributes redirectAttributes) {
User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
if (result.hasErrors()) {
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.user_details", result);
redirectAttributes.addFlashAttribute("user_details", userDetail);
} else {
userService.updateDetails(user, userDetail);
redirectAttributes.addFlashAttribute("success", true);
}
return "redirect:/profile/settings";
}
Aggregations