html
{% extends "_base.html" %} {% block main %} {% if error != null %} <div class="form-group"> <p id="error" class="text-danger">{{ error }}</p> </div> {% endif %} <form method="post" action="/changePassword"> <div class="form-group"> <label>OldPassword</label> <input name="oldpassword" type="password" class="form-control" placeholder="Password" minlength="6" maxlength="20"> </div> <div class="form-group"> <label>Password</label> <input name="password" type="password" class="form-control" placeholder="Password" minlength="6" maxlength="20"> </div> <div class="form-group"> <button type="submit" class="btn btn-outline-primary">Submit</button> </div> </form> {% endblock %}
api
@GetMapping("/changePassword") public ModelAndView changePassword() {return new ModelAndView("changePassword.html");} @PostMapping("/changePassword") public ModelAndView dochangePassword(@RequestParam("oldpassword") String oldpassword, @RequestParam("password") String password, HttpSession sesstion) { User user = (User) sesstion.getAttribute(KEY_USER); if (user.getPassword().equals(oldpassword)) { user.setPassword(password); } else { return new ModelAndView("changePassword.html", Map.of("error", "Wrong password")); } return new ModelAndView("redirect:/profile"); }
感觉调用的方法是不是太底层了,这种情况是否需要在userservice里写一个相应的changepassword方法,并抛出错误呢
Sign in to make a reply
alienation
html
api
感觉调用的方法是不是太底层了,这种情况是否需要在userservice里写一个相应的changepassword方法,并抛出错误呢