Password reset using spring through mail

I have implemented, mailing feature through which a confirmation token is send to the user and on clicking the url provided, a page opens that fills the email id of the user to which the email is sent.

Then they can reset, however when i am trying to submit the form with the new password. It is not passing the value to the function i have provided.

@PostMapping("/resetUserPassword")
public String accountPasswordReset(@Valid @ModelAttribute("updateUserPassword") ResetPassword user, BindingResult theBindingResult, Model theModel){
 
//this line outputs null value
System.out.println("accountPasswordReset: email="+user.getEmail());
if(user.getEmail()!=null) {
    User tokenUser = userService.findByEmailIdIgnoreCase(user.getEmail());
    tokenUser.setPassword(passwordEncoder.encode(user.getPassword()));
    userService.save(tokenUser);
    return "successPasswordReset";
        }else {
        return "error";
        }
    }

<form:form action="${pageContext.request.contextPath}/register/resetUserPassword" modelAttribute="updateUserPassword" class="form-horizontal" method="POST">
    <!-- Email -->
    <div class="form-group">
    <label for="emailId">Email (*)</label>
    <form:input path="email" id="emailId" placeholder="email (*)"
        class="form-control" disabled="true" readonly="true" />
        <form:errors path="email" cssClass="error" />
        </div>
        
        <!-- Password -->
    <div class="form-group">
    <label for="password">Password (*)</label>
    <form:password path="password" id="password"
    placeholder="password (*)" class="form-control" />
    <form:errors path="password" cssClass="error" />
    </div>
 
    <!-- Reset Button -->
        <div style="margin-top: 10px" class="form-group">
    <div class="col-sm-6 controls">
    <button type="submit" class="btn btn-primary">Reset</button>
    </div>
    </div>
</form:form>

1 answer

  • answered 2020-10-16 04:46 Himanshu Kandpal

    I was missing smallest thing, in this line i just removed disabled="true" and it works

    <form:input path="email" id="emailId" placeholder="email (*)" class="form-control" disabled="true" readonly="true" />

    to

    <form:input path="email" id="emailId" placeholder="email (*)" class="form-control" readonly="true" />