1

我正在尝试实施重置密码,但我遇到了错误,但我真的不明白,做错了什么。

这是更改密码的类:

public static class PasswordChange {

    @MinLength(6)
    @Required
    public String password;

    @MinLength(6)
    @Required
    public String repeatPasssword;

    public String getPassword() {
        return password;
    }

    public String getRepeatPasssword() {
        return repeatPasssword;
    }

    public void setRepeatPasssword(String repeatPasssword) {
        this.repeatPasssword = repeatPasssword;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String validate() {
        if (password == null || !password.equals(repeatPasssword)) {
            return Messages.get("auth.change_password.error.passwords_not_same");
        }
        return null;
    }
}

由类扩展以重置密码:

public static class PasswordReset extends Account.PasswordChange {

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String token;  

    public PasswordReset() {}

    public PasswordReset(final String token) {
        this.token = token;
    }

}

这是我的表格:

@(resetForm: Form[controllers.Signup.PasswordReset])

@import helper._
@import helper.twitterBootstrap._

@main(Messages("auth.password.forgot.title")){

<p>
@form(routes.Signup.doResetPassword()) {
    @if(resetForm.hasGlobalErrors) {
        <p class="error">
            <span class="label label-important">@resetForm.globalError.message</span>
        </p>
    }

    @views.html.auth.account.signup._passwordPartial(resetForm)

    <input type="hidden" name="token" id="token" value='@resetForm("token").value' />

    <input type="submit" value="@Messages("auth.change.password.cta")" class="btn btn-primary">
}
</p>

}{ }

提交后,我在控制器中获得表单:

final Form<PasswordReset> filledForm = PASSWORD_RESET_FORM.bindFromRequest(request());

PASSWORD_RESET_FORM 是在同一控制器中声明的字段:

private static final Form<PasswordReset> PASSWORD_RESET_FORM = form(PasswordReset.class);

这是结果:

Form(of=class controllers.Signup$PasswordReset,
    data={token=e2d48b70-9d00-4b8f-a8e4-ee17089c4e22,
    repeatPassword=1234567, password=1234567},
    value=None,
    errors={repeatPasssword=[ValidationError(repeatPasssword,error.required,[])]})

显然,filledForm.hasErrors() 返回 true,我什么也得不到(因为 value=None)。谁能指出我的错误?

UPD:@views.html.auth.account.signup._passwordPartial(resetForm) 是密码和密码确认字段的模板

@(f: Form[_])

@import helper._
@import helper.twitterBootstrap._

@inputPassword(
    f("password"),
    '_label -> Messages("auth.password.placeholder")
)

@inputPassword(
    f("repeatPassword"),
    '_label -> Messages("auth.password.repeat"),
    '_showConstraints -> false,
    '_error -> f.error("password")
)
4

1 回答 1

1

您需要决定密码中有多少个 s。您的表单使用两个,而您的班级使用三个。

于 2013-07-09T08:36:48.797 回答