Exemplo n.º 1
0
 @RequestMapping("/{id}/{userId}/answers")
 public String answers(@PathVariable Long id, Integer page, Model model) throws Exception {
   page = revisedPage(page);
   model.addAttribute(
       "answers",
       qnaService.findsAnswerByWriter(
           id, createPageableByAnswerCreatedDate(page, DEFAULT_PAGE_SIZE)));
   model.addAttribute("socialUser", userService.findById(id));
   return "users/answers";
 }
Exemplo n.º 2
0
  @RequestMapping("{id}/changepassword")
  public String changePasswordForm(
      @LoginUser SocialUser loginUser, @PathVariable Long id, Model model) throws Exception {
    SocialUser socialUser = userService.findById(id);
    if (!loginUser.isSameUser(socialUser)) {
      throw new IllegalArgumentException("You cann't change another user!");
    }

    model.addAttribute("socialUser", socialUser);
    model.addAttribute("password", new PasswordDto(id));
    return "users/changepassword";
  }
Exemplo n.º 3
0
  @RequestMapping(value = "{id}", method = RequestMethod.PUT)
  public String update(@LoginUser SocialUser loginUser, @PathVariable Long id, UserForm userForm)
      throws Exception {
    SocialUser socialUser = userService.findById(id);
    if (!loginUser.isSameUser(socialUser)) {
      throw new IllegalArgumentException("You cann't change another user!");
    }

    userService.updateSlippUser(loginUser, userForm.getEmail(), userForm.getUserId());

    return "redirect:/users/logout";
  }
Exemplo n.º 4
0
  @RequestMapping("{id}/form")
  public String updateForm(@LoginUser SocialUser loginUser, @PathVariable Long id, Model model)
      throws Exception {
    SocialUser socialUser = userService.findById(id);
    if (!loginUser.isSameUser(socialUser)) {
      throw new IllegalArgumentException("You cann't change another user!");
    }

    model.addAttribute("user", new UserForm(socialUser.getUserId(), socialUser.getEmail()));
    model.addAttribute("socialUser", socialUser);
    return "users/form";
  }
Exemplo n.º 5
0
 @RequestMapping("/{id}/{userId}")
 public String profile(@PathVariable Long id, @PathVariable String userId, Model model)
     throws Exception {
   model.addAttribute(
       "questions",
       qnaService.findsQuestionByWriter(
           id, createPageableByQuestionUpdatedDate(DEFAULT_PAGE_NO, DEFAULT_SUMMARY_PAGE_SIZE)));
   model.addAttribute(
       "answers",
       qnaService.findsAnswerByWriter(
           id, createPageableByAnswerCreatedDate(DEFAULT_PAGE_NO, DEFAULT_SUMMARY_PAGE_SIZE)));
   model.addAttribute("socialUser", userService.findById(id));
   return "users/profile";
 }
Exemplo n.º 6
0
  @RequestMapping(value = "{id}/changepassword", method = RequestMethod.POST)
  public String changePassword(
      @LoginUser SocialUser loginUser, @PathVariable Long id, PasswordDto password, Model model)
      throws Exception {
    SocialUser socialUser = userService.findById(id);

    if (!loginUser.isSameUser(socialUser)) {
      throw new IllegalArgumentException("You cann't change another user!");
    }

    try {
      userService.changePassword(loginUser, password);
      return "redirect:/users/logout";
    } catch (BadCredentialsException e) {
      model.addAttribute("errorMessage", e.getMessage());
      model.addAttribute("socialUser", socialUser);
      model.addAttribute("password", new PasswordDto(id));
      return "users/changepassword";
    }
  }
Exemplo n.º 7
0
 @RequestMapping("/{id}")
 public String profileById(@PathVariable Long id) throws Exception {
   SocialUser socialUser = userService.findById(id);
   return String.format(
       "redirect:/users/%d/%s", id, URLEncoder.encode(socialUser.getUserId(), "UTF-8"));
 }