Search in sources :

Example 66 with PostMapping

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";
}
Also used : ObjectError(org.springframework.validation.ObjectError) User(me.zbl.fullstack.entity.User) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 67 with PostMapping

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";
}
Also used : UserNotFoundException(amu.zhcet.data.user.UserNotFoundException) User(amu.zhcet.data.user.User) PasswordValidationException(amu.zhcet.auth.password.PasswordValidationException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 68 with PostMapping

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";
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) User(amu.zhcet.data.user.User) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 69 with PostMapping

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";
}
Also used : RealTimeStatus(amu.zhcet.common.realtime.RealTimeStatus) IOException(java.io.IOException) IOException(java.io.IOException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 70 with PostMapping

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";
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) User(amu.zhcet.data.user.User) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)83 ApiOperation (io.swagger.annotations.ApiOperation)21 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 Example (tk.mybatis.mapper.entity.Example)8 HashMap (java.util.HashMap)7 Service (org.apereo.cas.authentication.principal.Service)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 RegisteredService (org.apereo.cas.services.RegisteredService)5 User (amu.zhcet.data.user.User)4 Report (com.erudika.scoold.core.Report)4 IOException (java.io.IOException)4 Map (java.util.Map)4 Credential (org.apereo.cas.authentication.Credential)4 Reply (com.erudika.scoold.core.Reply)3 Log (io.github.tesla.ops.common.Log)3 LinkedHashMap (java.util.LinkedHashMap)3