org.springframework.web.servlet.mvc.support.RedirectAttributes

Here are the examples of the java api org.springframework.web.servlet.mvc.support.RedirectAttributes taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

629 Examples 7

19 Source : LoginCol.java
with Apache License 2.0
from ztgreat

// 登录
@RequestMapping(value = "/api/login", method = RequestMethod.POST)
@ResponseBody
public ResponseEnreplacedy<SysUserInfo> doLogin(@RequestBody SysUser user, Boolean rememberMe, String captcha, HttpServletRequest request, RedirectAttributes redirect) {
    ResponseEnreplacedy<SysUserInfo> res = new ResponseEnreplacedy<SysUserInfo>();
    try {
        TokenManager.login(user, rememberMe);
        UserToken token = TokenManager.getToken();
        SysUserInfo su = new SysUserInfo(token);
        try {
            sysUserService.updateLoginTime(token.getId());
        } catch (Exception e) {
            LoggerUtils.error(getClreplaced(), "更新 系统用户登录时间失败:" + e.getMessage());
        }
        res.setData(su).success("登录成功");
    } catch (DisabledAccountException e) {
        res.failure("账号被禁用");
    } catch (Exception e) {
        e.printStackTrace();
        res.failure("用户名或密码错误");
    }
    return res;
}

19 Source : NotificationController.java
with Apache License 2.0
from zhcet-amu

@GetMapping("/mark/read")
public String markRead(@RequestParam(required = false) Integer page, RedirectAttributes redirectAttributes) {
    int currentPage = NotificationUtils.normalizePage(page);
    notificationReadingService.markRead();
    redirectAttributes.addFlashAttribute("notification_success", "Marked all notifications as read");
    return "redirect:/notifications?page=" + currentPage;
}

19 Source : NotificationController.java
with Apache License 2.0
from zhcet-amu

@GetMapping("/{notification}/unmark/favorite")
public String unmarkFavorite(@RequestParam(required = false) Integer page, @PathVariable NotificationRecipient notification, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullNotification(notification);
    int currentPage = NotificationUtils.normalizePage(page);
    notificationReadingService.unmarkFavorite(notification);
    redirectAttributes.addFlashAttribute("notification_success", "Unmarked the notification as favorite");
    return "redirect:/notifications?page=" + currentPage;
}

19 Source : NotificationController.java
with Apache License 2.0
from zhcet-amu

@GetMapping("/{notification}/mark/favorite")
public String markFavorite(@RequestParam(required = false) Integer page, @PathVariable NotificationRecipient notification, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullNotification(notification);
    int currentPage = NotificationUtils.normalizePage(page);
    notificationReadingService.markFavorite(notification);
    redirectAttributes.addFlashAttribute("notification_success", "Marked the notification as favorite");
    return "redirect:/notifications?page=" + currentPage;
}

19 Source : NotificationManagementController.java
with Apache License 2.0
from zhcet-amu

@GetMapping("/{notification}/delete")
public String deleteNotification(@RequestParam(required = false) Integer page, @PathVariable Notification notification, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullNotification(notification);
    int currentPage = NotificationUtils.normalizePage(page);
    notificationManagementService.deleteNotification(notification);
    redirectAttributes.addFlashAttribute("notification_success", "Notification Deleted");
    return "redirect:/management/notifications?page=" + currentPage;
}

19 Source : NotificationEditController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String saveEditNotification(@RequestParam(required = false) Integer page, @PathVariable Notification notification, @Valid Notification edited, BindingResult result, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullNotification(notification);
    int currentPage = NotificationUtils.normalizePage(page);
    String redirectUrl = String.format("redirect:/management/notifications/%d/edit?page=%d", notification.getId(), currentPage);
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("notification", edited);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.notification", result);
        return redirectUrl;
    }
    notification.setreplacedle(edited.getreplacedle());
    notification.setMessage(edited.getMessage());
    notificationManagementService.saveNotification(notification);
    redirectAttributes.addFlashAttribute("notification_success", "Notification Edited");
    return "redirect:/management/notifications?page=" + currentPage;
}

19 Source : CourseRegistrationUploadService.java
with Apache License 2.0
from zhcet-amu

public void register(Course course, RedirectAttributes attributes, Confirmation<CourseRegistration> registrations) {
    try {
        List<CourseRegistration> courseRegistrations = registerStudents(course, registrations);
        sendRegistrationEvents(courseRegistrations);
        attributes.addFlashAttribute("registered", true);
    } catch (Exception e) {
        log.error("Error confirming student registrations", e);
        attributes.addFlashAttribute("unknown_error", true);
    }
}

19 Source : CourseRegistrationUploadService.java
with Apache License 2.0
from zhcet-amu

public void upload(Course course, MultipartFile file, RedirectAttributes attributes, HttpSession session) {
    try {
        UploadResult<RegistrationUpload> result = handleUpload(file);
        if (!result.getErrors().isEmpty()) {
            attributes.addFlashAttribute("errors", result.getErrors());
        } else {
            attributes.addFlashAttribute("success", true);
            Confirmation<CourseRegistration> confirmation = confirmUpload(course, result);
            session.setAttribute("confirmRegistration", confirmation);
        }
    } catch (IOException ioe) {
        log.error("Error registering students", ioe);
    }
}

19 Source : AvatarController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String handleFileUpload(@AuthenticationPrincipal UserAuth userAuth, @RequestParam MultipartFile file, RedirectAttributes redirectAttributes) {
    try {
        avatarService.uploadImage(userAuth, file);
        redirectAttributes.addFlashAttribute("avatar_success", Collections.singletonList("Profile Picture Updated"));
    } catch (IllegalStateException ise) {
        redirectAttributes.addFlashAttribute("avatar_errors", Collections.singletonList(ise.getMessage()));
    } catch (RuntimeException re) {
        redirectAttributes.addFlashAttribute("flash_messages", Flash.error("Failed to upload avatar"));
    }
    return "redirect:/profile/settings";
}

19 Source : AttendanceUploadController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/confirm")
public String uploadAttendance(RedirectAttributes attributes, @PathVariable String code, @Valid @ModelAttribute AttendanceModel attendanceModel, BindingResult bindingResult) {
    CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
    if (bindingResult.hasErrors()) {
        attributes.addFlashAttribute("attendanceModel", attendanceModel);
        attributes.addFlashAttribute("org.springframework.validation.BindingResult.attendanceModel", bindingResult);
    } else {
        try {
            attendanceUploadService.updateAttendance(courseInCharge, attendanceModel.getUploadList());
            attributes.addFlashAttribute("updated", true);
        } catch (Exception e) {
            log.error("Attendance Confirm", e);
            attributes.addFlashAttribute("attendanceModel", attendanceModel);
            attributes.addFlashAttribute("unknown_error", true);
        }
    }
    return "redirect:/admin/faculty/courses/{code}/attendance";
}

19 Source : AttendanceUploadController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String uploadFile(RedirectAttributes attributes, @PathVariable String code, @RequestParam MultipartFile file) {
    CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
    try {
        UploadResult<AttendanceUpload> result = attendanceUploadService.handleUpload(file);
        if (!result.getErrors().isEmpty()) {
            attributes.addFlashAttribute("errors", result.getErrors());
        } else {
            attributes.addFlashAttribute("success", true);
            Confirmation<AttendanceUpload> confirmation = attendanceUploadService.confirmUpload(courseInCharge, result);
            if (confirmation.getErrors().isEmpty()) {
                AttendanceModel attendanceModel = new AttendanceModel();
                List<AttendanceUpload> attendanceUploads = new ArrayList<>(confirmation.getData());
                SortUtils.sortAttendanceUpload(attendanceUploads);
                attendanceModel.setUploadList(attendanceUploads);
                attributes.addFlashAttribute("attendanceModel", attendanceModel);
            } else {
                attributes.addFlashAttribute("confirmAttendanceErrors", confirmation);
            }
        }
    } catch (IOException ioe) {
        log.error("Attendance Upload", ioe);
    }
    return "redirect:/admin/faculty/courses/{code}/attendance";
}

19 Source : AttendanceUploadController.java
with Apache License 2.0
from zhcet-amu

@GetMapping
public String edit(RedirectAttributes attributes, @PathVariable String code) {
    CourseInCharge courseInCharge = courseInChargeService.getCourseInCharge(code).orElseThrow(CourseInChargeNotFoundException::new);
    AttendanceModel attendanceModel = new AttendanceModel();
    List<AttendanceUpload> attendanceUploads = courseInChargeService.getCourseRegistrations(courseInCharge).stream().map(attendanceMapper::fromCourseRegistration).collect(Collectors.toList());
    SortUtils.sortAttendanceUpload(attendanceUploads);
    attendanceModel.setUploadList(attendanceUploads);
    attributes.addFlashAttribute("attendanceModel", attendanceModel);
    return "redirect:/admin/faculty/courses/{code}/attendance";
}

19 Source : DepartmentCourseRegistrationController.java
with Apache License 2.0
from zhcet-amu

/**
 * Confirms the student registration information stored in HttpSession after asking the admin.
 * Feature is present in Floated Course Manage Page of Department Panel
 * @param attributes RedirectAttributes to be set
 * @param course Course to which the students need to be registered
 * @param registrations Course registration confirmation
 * @return Layout to be rendered
 */
@PostMapping("/confirm")
public String confirmRegistration(RedirectAttributes attributes, @PathVariable Course course, @SessionAttribute("confirmRegistration") Confirmation<CourseRegistration> registrations) {
    ErrorUtils.requireNonNullCourse(course);
    courseRegistrationUploadService.register(course, attributes, registrations);
    return "redirect:/admin/department/floated/{course}";
}

19 Source : DepartmentCourseRegistrationController.java
with Apache License 2.0
from zhcet-amu

/**
 * Handles the uploaded CSV in Department Panel.
 * Feature is presented in Floated Course Manage Page of Department Panel
 * @param attributes RedirectAttributes to be set
 * @param course Course to which the students need to be registered
 * @param file MultipartFile containing CSV listing students to be registered
 * @param session HttpSession for storing intermediate information
 * @return Layout to be rendered
 */
@PostMapping
public String uploadFile(RedirectAttributes attributes, @PathVariable Course course, @RequestParam MultipartFile file, HttpSession session) {
    ErrorUtils.requireNonNullCourse(course);
    courseRegistrationUploadService.upload(course, file, attributes, session);
    return "redirect:/admin/department/floated/{course}";
}

19 Source : InChargeManagementController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/in_charge")
public String changeInCharge(RedirectAttributes redirectAttributes, @PathVariable Course course, @RequestParam(required = false) List<FacultyMember> facultyId, @RequestParam(required = false) List<String> section) {
    FloatedCourse floatedCourse = floatedCourseService.getFloatedCourse(course).orElseThrow(FloatedCourseNotFoundException::new);
    inChargeManagementService.saveInCharge(floatedCourse, facultyId, section);
    redirectAttributes.addFlashAttribute("incharge_success", "Course In-Charge saved successfully");
    return "redirect:/admin/department/floated/{course}";
}

19 Source : FloatingController.java
with Apache License 2.0
from zhcet-amu

@GetMapping
public String floatCourse(@PathVariable Course course, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullCourse(course);
    redirectAttributes.addAttribute("department", course.getDepartment());
    if (floatedCourseService.isFloated(course)) {
        log.warn("Course is already floated {}", course.getCode());
        redirectAttributes.addFlashAttribute("float_error", "Course is already floated");
    } else {
        redirectAttributes.addFlashAttribute("courses", Collections.singletonList(course));
    }
    return "redirect:/admin/department/{department}/float";
}

19 Source : FloatCourseController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String floatCourses(RedirectAttributes redirectAttributes, @PathVariable Department department, @RequestParam("code") List<Course> courseList) {
    ErrorUtils.requireNonNullDepartment(department);
    for (Course course : courseList) floatedCourseService.floatCourse(course);
    redirectAttributes.addFlashAttribute("float_success", "Courses floated successfully!");
    if (courseList.size() == 1)
        return String.format("redirect:/admin/department/floated/%s", courseList.get(0).getCode());
    return "redirect:/admin/department/{department}/float";
}

19 Source : CourseEditController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/edit")
public String postCourse(@PathVariable Course course, @ModelAttribute("course") @Valid Course newCourse, BindingResult result, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullCourse(course);
    Department department = course.getDepartment();
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("course", newCourse);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.course", result);
    } else {
        try {
            newCourse.setDepartment(department);
            courseService.updateCourse(course, newCourse);
            redirectAttributes.addFlashAttribute("course_success", "Course saved successfully!");
        } catch (UpdateException e) {
            log.warn("Course Save Error", e);
            newCourse.setCode(course.getCode());
            redirectAttributes.addFlashAttribute("course", newCourse);
            redirectAttributes.addFlashAttribute("course_errors", e.getMessage());
        }
    }
    return "redirect:/admin/department/courses/{course}/edit";
}

19 Source : CourseEditController.java
with Apache License 2.0
from zhcet-amu

@GetMapping("/delete")
public String deleteCourse(@PathVariable Course course, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullCourse(course);
    courseService.deleteCourse(course);
    redirectAttributes.addFlashAttribute("course_success", "Course " + course.getCode() + " deleted successfully!");
    redirectAttributes.addAttribute("department", course.getDepartment());
    return "redirect:/admin/department/{department}/courses?active=true";
}

19 Source : CourseCreationController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String postCourse(@PathVariable Department department, @Valid Course course, BindingResult result, RedirectAttributes redirectAttributes) {
    ErrorUtils.requireNonNullDepartment(department);
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("course", course);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.course", result);
    } else {
        try {
            course.setDepartment(department);
            courseService.addCourse(course);
            redirectAttributes.addFlashAttribute("course_success", "Course created successfully!");
            return "redirect:/admin/department/{department}/courses?active=true";
        } catch (DuplicateException e) {
            log.warn("Duplicate Course", e);
            redirectAttributes.addFlashAttribute("course", course);
            redirectAttributes.addFlashAttribute("course_errors", e.getMessage());
        }
    }
    return "redirect:/admin/department/{department}/course/add";
}

19 Source : StudentRegistrationController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/confirm")
public String uploadStudents(RedirectAttributes attributes, @SessionAttribute(KEY_STUDENT_REGISTRATION) Confirmation<Student> confirmation, WebRequest webRequest) {
    if (confirmation == null || !confirmation.getErrors().isEmpty()) {
        attributes.addFlashAttribute("errors", Collections.singletonList("Unknown Error"));
    } else {
        try {
            RealTimeStatus status = realTimeStatusService.install();
            studentUploadService.registerStudents(confirmation, status);
            attributes.addFlashAttribute("task_id_student", status.getId());
            attributes.addFlashAttribute("students_registered", true);
        } catch (Exception e) {
            log.error("Error registering students", e);
            attributes.addFlashAttribute("student_unknown_error", true);
        }
        webRequest.removeAttribute(KEY_STUDENT_REGISTRATION, RequestAttributes.SCOPE_SESSION);
    }
    return "redirect:/admin/dean";
}

19 Source : StudentRegistrationController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String uploadFile(RedirectAttributes attributes, @RequestParam MultipartFile file, HttpSession session, WebRequest webRequest) {
    try {
        UploadResult<StudentUpload> result = studentUploadService.handleUpload(file);
        if (!result.getErrors().isEmpty()) {
            webRequest.removeAttribute(KEY_STUDENT_REGISTRATION, RequestAttributes.SCOPE_SESSION);
            attributes.addFlashAttribute("students_errors", result.getErrors());
        } else {
            attributes.addFlashAttribute("students_success", true);
            Confirmation<Student> confirmation = studentUploadService.confirmUpload(result);
            session.setAttribute(KEY_STUDENT_REGISTRATION, confirmation);
        }
    } catch (IOException ioe) {
        log.error("Error registering students", ioe);
    }
    return "redirect:/admin/dean";
}

19 Source : FacultyRegistrationController.java
with Apache License 2.0
from zhcet-amu

@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 preplacedwordFileLocation = facultyUploadService.savePreplacedwordFile(confirmation);
            RealTimeStatus status = realTimeStatusService.install();
            facultyUploadService.registerFaculty(confirmation, status);
            attributes.addFlashAttribute("task_id_faculty", status.getId());
            attributes.addFlashAttribute("file_saved", preplacedwordFileLocation);
            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";
}

19 Source : FacultyRegistrationController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String uploadFacultyFile(RedirectAttributes attributes, @RequestParam MultipartFile file, HttpSession session, WebRequest webRequest) throws IOException {
    try {
        UploadResult<FacultyUpload> result = facultyUploadService.handleUpload(file);
        if (!result.getErrors().isEmpty()) {
            webRequest.removeAttribute(KEY_FACULTY_REGISTRATION, RequestAttributes.SCOPE_SESSION);
            attributes.addFlashAttribute("faculty_errors", result.getErrors());
        } else {
            attributes.addFlashAttribute("faculty_success", true);
            Confirmation<FacultyMember> confirmation = facultyUploadService.confirmUpload(result);
            session.setAttribute(KEY_FACULTY_REGISTRATION, confirmation);
        }
    } catch (IOException ioe) {
        log.error("Error registering faculty", ioe);
    }
    return "redirect:/admin/dean";
}

19 Source : DeanCourseRegistrationController.java
with Apache License 2.0
from zhcet-amu

/**
 * Handles the uploaded CSV in Department Panel.
 * Feature is presented in Floated Course Manage Page of Dean Admin Panel
 * @param attributes RedirectAttributes to be set
 * @param course Course to which the students need to be registered
 * @param file MultipartFile containing CSV listing students to be registered
 * @param session HttpSession for storing intermediate information
 * @return Layout to be rendered
 */
@PostMapping
public String uploadFile(RedirectAttributes attributes, @PathVariable Course course, @RequestParam MultipartFile file, HttpSession session) {
    ErrorUtils.requireNonNullCourse(course);
    courseRegistrationUploadService.upload(course, file, attributes, session);
    return "redirect:/admin/dean/floated/{course}";
}

19 Source : DeanCourseRegistrationController.java
with Apache License 2.0
from zhcet-amu

/**
 * Confirms the student registration information stored in HttpSession after asking the admin.
 * Feature is present in Floated Course Manage Page of Dean Admin Panel
 * @param attributes RedirectAttributes to be set
 * @param course Course to which the students need to be registered
 * @param registrations Course registration confirmation
 * @return Layout to be rendered
 */
@PostMapping("/confirm")
public String confirmRegistration(RedirectAttributes attributes, @PathVariable Course course, @SessionAttribute("confirmRegistration") Confirmation<CourseRegistration> registrations) {
    ErrorUtils.requireNonNullCourse(course);
    courseRegistrationUploadService.register(course, attributes, registrations);
    return "redirect:/admin/dean/floated/{course}";
}

19 Source : StudentEditController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("{student}")
public String studentPost(RedirectAttributes redirectAttributes, @PathVariable Student student, @Valid StudentEditModel studentEditModel, BindingResult result) {
    ErrorUtils.requireNonNullStudent(student);
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.studentModel", result);
        redirectAttributes.addFlashAttribute("studentModel", studentEditModel);
    } else {
        try {
            studentEditService.saveStudent(student, studentEditModel);
            redirectAttributes.addFlashAttribute("success", Collections.singletonList("Student successfully updated"));
        } catch (RuntimeException re) {
            log.warn("Error saving student", re);
            redirectAttributes.addFlashAttribute("errors", Collections.singletonList(re.getMessage()));
            redirectAttributes.addFlashAttribute("studentModel", studentEditModel);
        }
    }
    return "redirect:/admin/dean/students/{student}";
}

19 Source : StudentBatchEditController.java
with Apache License 2.0
from zhcet-amu

// We use 'student' instead of 'students' so that it does not clash with 'studentPost' method above
@PostMapping("/status")
public String studentStatus(RedirectAttributes redirectAttributes, @RequestParam List<String> enrolments, @RequestParam String status) {
    if (Strings.isNullOrEmpty(status)) {
        redirectAttributes.addFlashAttribute("section_error", "Status was unchanged");
        return "redirect:/admin/dean/students";
    }
    try {
        studentEditService.changeStatuses(enrolments, status);
        redirectAttributes.addFlashAttribute("section_success", "Statuses changed successfully");
    } catch (Exception e) {
        log.error("Error changing statuses", e);
        redirectAttributes.addFlashAttribute("section_error", "Unknown error while changing statuses");
    }
    return "redirect:/admin/dean/students";
}

19 Source : StudentBatchEditController.java
with Apache License 2.0
from zhcet-amu

// We use 'student' instead of 'students' so that it does not clash with 'studentPost' method above
@PostMapping("/section")
public String studentSection(RedirectAttributes redirectAttributes, @RequestParam List<String> enrolments, @RequestParam String section) {
    if (Strings.isNullOrEmpty(section)) {
        redirectAttributes.addFlashAttribute("section_error", "Section must not be empty");
        return "redirect:/admin/dean/students";
    }
    try {
        studentEditService.changeSections(enrolments, section);
        redirectAttributes.addFlashAttribute("section_success", "Sections changed successfully");
    } catch (Exception e) {
        log.error("Error changing sections", e);
        redirectAttributes.addFlashAttribute("section_error", "Unknown error while changing sections");
    }
    return "redirect:/admin/dean/students";
}

19 Source : FloatedCourseEditController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/{course}/unregister")
public String removeStudent(RedirectAttributes attributes, @PathVariable Course course, @RequestParam Student student) {
    // TODO: Extract to shared package
    ErrorUtils.requireNonNullCourse(course);
    ErrorUtils.requireNonNullStudent(student);
    FloatedCourse floatedCourse = floatedCourseService.getFloatedCourse(course).orElseThrow(FloatedCourseNotFoundException::new);
    courseRegistrationService.removeRegistration(floatedCourse, student);
    attributes.addFlashAttribute("flash_messages", Flash.success("Student removed from course"));
    return "redirect:/admin/dean/floated/{course}";
}

19 Source : FacultyEditController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("{faculty}")
public String facultyPost(RedirectAttributes redirectAttributes, @PathVariable FacultyMember faculty, @Valid FacultyEditModel facultyEditModel, BindingResult result) {
    ErrorUtils.requireNonNullFacultyMember(faculty);
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.facultyModel", result);
        redirectAttributes.addFlashAttribute("facultyModel", facultyEditModel);
    } else {
        try {
            facultyEditService.saveFacultyMember(faculty, facultyEditModel);
            redirectAttributes.addFlashAttribute("success", Collections.singletonList("Faculty successfully updated"));
        } catch (RuntimeException re) {
            log.warn("Error saving faculty", re);
            redirectAttributes.addFlashAttribute("errors", Collections.singletonList(re.getMessage()));
            redirectAttributes.addFlashAttribute("facultyModel", facultyEditModel);
        }
    }
    return "redirect:/admin/dean/faculty/{faculty}";
}

19 Source : DeanController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/departments/add")
public String addDepartment(@Valid Department department, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.department", bindingResult);
        redirectAttributes.addFlashAttribute("department", department);
    } else {
        try {
            departmentService.addDepartment(department);
            redirectAttributes.addFlashAttribute("dept_success", true);
        } catch (DuplicateException de) {
            log.warn("Duplicate Department", de);
            List<String> errors = new ArrayList<>();
            errors.add(de.getMessage());
            redirectAttributes.addFlashAttribute("department", department);
            redirectAttributes.addFlashAttribute("dept_errors", errors);
        }
    }
    return "redirect:/admin/dean";
}

19 Source : ConfigurationController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String configurationPost(RedirectAttributes redirectAttributes, @Valid Config config, BindingResult result) {
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("config", config);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.config", result);
    } else {
        List<String> errors = new ArrayList<>();
        if (config.getTerm() != 'A' && config.getTerm() != 'W')
            errors.add("Term can only be Autumn or Winter");
        if (!errors.isEmpty()) {
            redirectAttributes.addFlashAttribute("config", config);
            redirectAttributes.addFlashAttribute("errors", errors);
        } else {
            configurationService.save(toConfigModel(config));
            redirectAttributes.addFlashAttribute("success", Collections.singletonList("Configuration successfully saved!"));
        }
    }
    return "redirect:/admin/dean/configuration";
}

19 Source : EmailVerificationController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/profile/email/register")
public String registerEmail(RedirectAttributes redirectAttributes, @RequestParam String email) {
    User user = userService.getLoggedInUser().orElseThrow(() -> new AccessDeniedException("403"));
    if (user.getEmail() != null && user.getEmail().equals(email)) {
        redirectAttributes.addFlashAttribute("email_error", "New email is same as previous one");
    } else if (Utils.isValidEmail(email)) {
        sendVerificationLink(email, redirectAttributes);
    } else {
        log.warn("Invalid Email", email);
        redirectAttributes.addFlashAttribute("email", email);
        redirectAttributes.addFlashAttribute("email_error", "The provided email is invalid!");
    }
    return "redirect:/profile/settings#account";
}

19 Source : EmailVerificationController.java
with Apache License 2.0
from zhcet-amu

private void sendVerificationLink(String email, RedirectAttributes redirectAttributes) {
    try {
        emailVerificationService.generate(email);
        redirectAttributes.addFlashAttribute("email_success", "Verification link sent to '" + email + "'!");
    } catch (DuplicateEmailException de) {
        log.warn("Duplicate Email", de);
        redirectAttributes.addFlashAttribute("email_error", de.getMessage());
    } catch (RecentVerificationException re) {
        log.warn("Recently Sent Email", re);
        redirectAttributes.addFlashAttribute("email_error", RecentVerificationException.MESSAGE);
    } catch (RuntimeException re) {
        log.warn("Error sending verification link", re);
        redirectAttributes.addFlashAttribute("email_error", "There was some error sending the email");
    }
}

19 Source : EmailVerificationController.java
with Apache License 2.0
from zhcet-amu

@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";
}

19 Source : TwoFAController.java
with Apache License 2.0
from zhcet-amu

@RequestMapping("/enable")
public String enableGet(Model model, RedirectAttributes redirectAttributes, @RequestParam(required = false) Boolean retain) {
    if (retain != null && retain) {
        twoFAService.enable2FA();
        redirectAttributes.addFlashAttribute("flash_messages", Flash.success(TWO_FACTOR_ENABLED_MESSAGE));
        return "redirect:/profile/settings#security";
    }
    TwoFAService.TwoFASecret secret = twoFAService.generate2FASecret();
    model.addAttribute("secret", secret);
    return "user/2fa_enable";
}

19 Source : TwoFAController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/disable")
public String disable(RedirectAttributes redirectAttributes) {
    twoFAService.disable2FA();
    redirectAttributes.addFlashAttribute("flash_messages", Flash.success("Disabled 2 Factor Authentication"));
    return "redirect:/profile/settings#security";
}

19 Source : TwoFAController.java
with Apache License 2.0
from zhcet-amu

@PostMapping("/confirm")
public String enablePost(RedirectAttributes redirectAttributes, @RequestParam String secret, @RequestParam String code) {
    try {
        twoFAService.enable2FA(secret, code);
        redirectAttributes.addFlashAttribute("flash_messages", Flash.success(TWO_FACTOR_ENABLED_MESSAGE));
    } catch (RuntimeException re) {
        redirectAttributes.addFlashAttribute("flash_messages", Flash.error(re.getMessage()));
        return "redirect:/profile/2fa/enable";
    }
    return "redirect:/profile/settings#security";
}

19 Source : PasswordResetController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
@PreAuthorize("hasAuthority('PreplacedWORD_CHANGE_PRIVILEGE')")
public String savePreplacedword(@Valid PreplacedwordReset preplacedwordReset, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
    Optional<User> optionalUser = Auditor.getLoggedInAuthentication().map(Authentication::getPrincipal).filter(principal -> !principal.getClreplaced().isreplacedignableFrom(User.clreplaced)).map(principal -> ((User) principal).getUserId()).flatMap(userService::findById);
    if (!optionalUser.isPresent()) {
        redirectAttributes.addAttribute("error", "Unknown Error");
    } else {
        User user = optionalUser.get();
        if (bindingResult.hasErrors()) {
            redirectAttributes.addFlashAttribute("preplacedword", preplacedwordReset);
            redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.preplacedword", bindingResult);
        } else {
            try {
                preplacedwordResetService.resetPreplacedword(user, preplacedwordReset);
                redirectAttributes.addFlashAttribute("reset_success", true);
                return "redirect:/login";
            } catch (TokenValidationException tve) {
                log.warn("Token Verification : Preplacedword Reset : {}", tve.getMessage());
                redirectAttributes.addAttribute("error", tve.getMessage());
            } catch (PreplacedwordValidationException pve) {
                log.debug("Preplacedword Verification Exception", pve);
                redirectAttributes.addFlashAttribute("preplaced_errors", pve.getMessage());
            }
        }
    }
    return String.format("redirect:/login/preplacedword/reset?hash=%s&auth=%s", preplacedwordReset.getHash(), preplacedwordReset.getToken());
}

19 Source : ForgotPasswordController.java
with Apache License 2.0
from zhcet-amu

@PostMapping
public String sendEmailLink(RedirectAttributes redirectAttributes, @RequestParam String email) {
    try {
        resetTokenSender.sendResetToken(email);
        redirectAttributes.addFlashAttribute("reset_link_sent", true);
    } catch (UsernameNotFoundException e) {
        log.warn("User not found : Preplacedword Forgot : {}", e);
        redirectAttributes.addFlashAttribute("error", e.getMessage());
        return "redirect:/login/preplacedword/forgot";
    }
    return "redirect:/login";
}

19 Source : PassportController.java
with MIT License
from zhangyd-c

/**
 * 使用权限管理工具进行用户的退出,跳出登录,给出提示信息
 *
 * @param redirectAttributes
 * @return
 */
@GetMapping("/logout")
public ModelAndView logout(RedirectAttributes redirectAttributes) {
    // http://www.oschina.net/question/99751_91561
    // 此处有坑: 退出登录,其实不用实现任何东西,只需要保留这个接口即可,也不可能通过下方的代码进行退出
    // SecurityUtils.getSubject().logout();
    // 因为退出操作是由Shiro控制的
    redirectAttributes.addFlashAttribute("message", "您已安全退出");
    return ResultUtil.redirect("index");
}

19 Source : MessageController.java
with Apache License 2.0
from yuanmabiji

@PostMapping
public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) {
    if (result.hasErrors()) {
        return new ModelAndView("messages/form", "formErrors", result.getAllErrors());
    }
    message = this.messageRepository.save(message);
    redirect.addFlashAttribute("globalMessage", "view.success");
    return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
}

19 Source : MessageController.java
with Apache License 2.0
from yuanmabiji

@PostMapping
public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) {
    if (result.hasErrors()) {
        ModelAndView mav = new ModelAndView("messages/form");
        mav.addObject("formErrors", result.getAllErrors());
        mav.addObject("fieldErrors", getFieldErrors(result));
        return mav;
    }
    message = this.messageRepository.save(message);
    redirect.addFlashAttribute("globalMessage", "Successfully created a new message");
    return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
}

19 Source : PostsController.java
with Apache License 2.0
from yifengMusic

/**
 * 保存文章
 *
 * @param tbPostsPost
 * @return
 */
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(TbPostsPost tbPostsPost, HttpServletRequest request, RedirectAttributes redirectAttributes) throws Exception {
    // 初始化
    tbPostsPost.setTimePublished(new Date());
    tbPostsPost.setStatus("0");
    TbSysUser admin = (TbSysUser) request.getSession().getAttribute(WebConstants.SESSION_USER);
    String tbPostsPostJson = MapperUtils.obj2json(tbPostsPost);
    String json = postsService.save(tbPostsPostJson, admin.getUserCode());
    BaseResult baseResult = MapperUtils.json2pojo(json, BaseResult.clreplaced);
    redirectAttributes.addFlashAttribute("baseResult", baseResult);
    if (baseResult.getSuccess().endsWith("成功")) {
        return "redirect:/index";
    }
    return "redirect:/form";
}

19 Source : AdminController.java
with Apache License 2.0
from yifengMusic

/**
 * 保存管理员
 *
 * @param tbSysUser
 * @return
 */
@RequestMapping(value = "save", method = RequestMethod.POST)
public String save(TbSysUser tbSysUser, HttpServletRequest request, RedirectAttributes redirectAttributes) throws Exception {
    // 初始化数据
    tbSysUser.setUserType("1");
    tbSysUser.setMgrType("1");
    tbSysUser.setStatus("0");
    tbSysUser.setCorpCode("0");
    tbSysUser.setCorpName("YFToken");
    TbSysUser admin = (TbSysUser) request.getSession().getAttribute("admin");
    String json = adminService.save(MapperUtils.obj2json(tbSysUser), admin.getUserCode());
    try {
        BaseResult baseResult = MapperUtils.json2pojo(json, BaseResult.clreplaced);
        redirectAttributes.addFlashAttribute("baseResult", baseResult);
        // 保存成功
        if (baseResult.getSuccess().endsWith("成功")) {
            return "redirect:/index";
        } else // 保存失败
        {
            return "redirect:/form";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

19 Source : LoginController.java
with Apache License 2.0
from yifengMusic

/**
 * 登录业务
 *
 * @param loginCode
 * @param preplacedword
 * @return
 */
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(@RequestParam(required = true) String loginCode, @RequestParam(required = true) String preplacedword, @RequestParam(required = false) String url, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
    TbSysUser tbSysUser = loginService.login(loginCode, preplacedword);
    // 登录失败
    if (tbSysUser == null) {
        redirectAttributes.addFlashAttribute("message", "用户名或密码错误,请重新输入");
    } else // 登录成功
    {
        String token = UUID.randomUUID().toString();
        // 将 Token 放入缓存
        String result = redisService.put(token, loginCode, 60 * 60 * 24);
        if (StringUtils.isNotBlank(result) && "ok".equals(result)) {
            CookieUtils.setCookie(request, response, "token", token, 60 * 60 * 24);
            if (StringUtils.isNotBlank(url)) {
                return "redirect:" + url;
            }
        } else // 熔断处理
        {
            redirectAttributes.addFlashAttribute("message", "服务器异常,请稍后再试");
        }
    }
    return "redirect:/login";
}

19 Source : TestValidator.java
with Apache License 2.0
from xiuhuai

@PostMapping("/test")
public String checkUser(@Valid User user, BindingResult bindingResult, RedirectAttributes attr) {
    // 特别注意实体中的属性必须都验证过了,不然不会成功
    if (bindingResult.hasErrors()) {
        return "form";
    }
    /**
     * @Description:
     * 1.使用RedirectAttributes的addAttribute方法传递参数会跟随在URL后面 ,如上代码即为?name=long&age=45
     * 2.使用addFlashAttribute不会跟随在URL后面,会把该参数值暂时保存于session,待重定向url获取该参数后从session中移除,
     * 这里的redirect必须是方法映射路径。你会发现redirect后的值只会出现一次,刷新后不会出现了,对于重复提交可以使用此来完成。
     */
    attr.addFlashAttribute("user", user);
    return "redirect:/results";
}

19 Source : LendController.java
with Apache License 2.0
from withstars

@RequestMapping("/lendbookdo.html")
public String bookLendDo(HttpServletRequest request, RedirectAttributes redirectAttributes, int readerId) {
    long bookId = Integer.parseInt(request.getParameter("id"));
    boolean lendsucc = lendService.bookLend(bookId, readerId);
    if (lendsucc) {
        redirectAttributes.addFlashAttribute("succ", "图书借阅成功!");
        return "redirect:/allbooks.html";
    } else {
        redirectAttributes.addFlashAttribute("succ", "图书借阅成功!");
        return "redirect:/allbooks.html";
    }
}

19 Source : LendController.java
with Apache License 2.0
from withstars

@RequestMapping("/returnbook.html")
public String bookReturn(HttpServletRequest request, RedirectAttributes redirectAttributes) {
    long bookId = Integer.parseInt(request.getParameter("bookId"));
    boolean retSucc = lendService.bookReturn(bookId);
    if (retSucc) {
        redirectAttributes.addFlashAttribute("succ", "图书归还成功!");
        return "redirect:/allbooks.html";
    } else {
        redirectAttributes.addFlashAttribute("error", "图书归还失败!");
        return "redirect:/allbooks.html";
    }
}

See More Examples