java - How to validate single property of a bean at one time in Spring MVC using custom validator? -


I need to send a forgotten password link via e-mail, once the user has entered his email Must be valid only. I had the same pauso confirming the email, password and password.

Similarly, when the link sent by the user is clicked, his form has been shown to enter and now use these two attributes to be valid for confirming the password. I had only one custom validator to perform that recognition.

So is there any way to do this? My code below

User.java

  public class user {private string name; Private string password; Private string confirmation password; Public string getName () {return name; } Public Zero Setname (string name) {this.name = name; } Public string getPassword () {return password; } Public Zero Set Password (String Password) {this.password = password; } Public string getConfirmPassword () {confirm the return word; } Public Zero Set Configure Password (Confirm Confirm Password) {this.confirmPassword = confirmPassword; }  

MyController.java snippet

  @RequestMapping (value = "/ forget", method = RequestMethod.POST) public ModelAndView Forgotten Password Submit (@Walid @Model Attribute ("User") User, Binding Results Results, User, HTTPSVette Request) {ModelAndView Model = New ModelAndView ("PWD / Forgotten / Index"); // If there is an error to check the user (results.hasErrors ()) Return Model; Model.addObject (user); Boolean check = service. Validate (user); If (check == true) return model; String position = service.sendPasswordResetLink (account id, user, request); If (status.equals ("success")) {see new models and ("PWD / forget-rage / index"); } Return Model; }  

When the user clicks on the request

  @RequestMapping (value = "/ reset", method = RequestMethod.POST) Public ModelAndView resetPasswordSubmit (@ ModelAttribute ("linkId") string link id, @ walid @ model attribute ("user") user user, binding result, httpserve request) {string view = "pwd / reset-success / index"; If (results.hasErrors ()) return model; String position = the.service.updateUserPassword (linkId, user.getPassword), user.getConfirmPassword (), request); If (! Status.equals ("success")) new models and views back ("pwd / reset-unsuccessful / index"); // if reset failed // see = "pwd / reset-unsuccessful / index"; ModelAndView Model = New ModelAndView (see); Return model; }  

Confirm your form and password for the password link to look something like this

& lt; Form & gt; Password: & lt; Input type = "password" name = "password" /> Confirm Password: & lt; Input type = "password" name = "confirmation password" /> & Lt; Input type = "hidden" name = "email" value = "n / a" /> & lt; Input type = "submit" value = "submit" /> & Lt; / Form & gt;

and your verifier should look like the following, where you check the email attribute for hidden values ​​sent if you match it After clicking on that link, if you are in the form, if not, then you can verify on the basis of it is the first form.

  Public class UserValidator applicant {@Override supports public bullion (class ?; & Gt; clause) {return User.class.equals (clazz); } @ Override Public Validate (Object Target, Errors Errors) {User User = (User) Target; If (user.getEmail (.) Equals ("N / A")) {// Password reset form validation (Confirm password, password)} other {// password reset request form validation (Confirm email, password, and password }}}}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -