Church.Net.API/Church.Net/Account/PasswordReset.cshtml
2022-09-08 08:04:32 -07:00

95 lines
3.8 KiB
Plaintext

@* 若您在使用組合,請移除此區段 *@
@section Scripts {
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
}
@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "密碼重設";
var passwordResetToken = Request.Form["resetToken"] ?? Request.QueryString["resetToken"];
bool tokenExpired = false;
bool isSuccess = false;
// 設定驗證
Validation.RequireField("newPassword", "新密碼欄位為必填。");
Validation.Add("confirmPassword",
Validator.EqualsTo("newPassword", "新密碼和確認密碼不相符。"));
Validation.RequireField("passwordResetToken", "密碼重設語彙基元欄位為必填。");
Validation.Add("newPassword",
Validator.StringLength(
maxLength: Int32.MaxValue,
minLength: 6,
errorMessage: "新密碼必須至少有 6 個字元"));
if (IsPost && Validation.IsValid()) {
AntiForgery.Validate();
var newPassword = Request["newPassword"];
var confirmPassword = Request["confirmPassword"];
if (WebSecurity.ResetPassword(passwordResetToken, newPassword)) {
isSuccess = true;
} else {
ModelState.AddError("passwordResetToken", "密碼重設語彙基元無效。");
tokenExpired = true;
}
}
}
<hgroup class="title">
<h1>@Page.Title.</h1>
<h2>使用下列表格來重設您的密碼。</h2>
</hgroup>
@if (!WebMail.SmtpServer.IsEmpty()) {
if (!Validation.IsValid()) {
<p class="validation-summary-errors">
@if (tokenExpired) {
<text>密碼重設語彙基元不正確或可能已經到期。造訪<a href="~/Account/ForgotPassword">忘記密碼頁面</a>
以產生新密碼。</text>
} else {
<text>無法重設密碼。請更正錯誤並再試一次。</text>
}
</p>
}
if (isSuccess) {
<p class="message-success">
密碼已變更!按一下<a href="~/Account/Login" title="登入">這裡</a>以登入。
</p>
}
<form method="post">
@AntiForgery.GetHtml()
<fieldset>
<legend>密碼變更表單</legend>
<ol>
<li class="new-password">
<label for="newPassword" @if (!ModelState.IsValidField("newPassword")) {<text>class="error-label"</text>}>新密碼</label>
<input type="password" id="newPassword" name="newPassword" disabled="@isSuccess" @Validation.For("newPassword") />
@Html.ValidationMessage("newPassword")
</li>
<li class="confirm-password">
<label for="confirmPassword" @if (!ModelState.IsValidField("confirmPassword")) {<text>class="error-label"</text>}>確認密碼</label>
<input type="password" id="confirmPassword" name="confirmPassword" disabled="@isSuccess" @Validation.For("confirmPassword") />
@Html.ValidationMessage("confirmPassword")
</li>
<li class="reset-token">
<label for="resetToken" @if (!ModelState.IsValidField("resetToken")) {<text>class="error-label"</text>}>Password reset token</label>
<input type="text" id="resetToken" name="resetToken" value="@passwordResetToken" disabled="@isSuccess" @Validation.For("resetToken") />
@Html.ValidationMessage("resetToken")
</li>
</ol>
<input type="submit" value="重設密碼" disabled="@isSuccess"/>
</fieldset>
</form>
} else {
<p class="message-info">
已停用此網站的密碼復原,因為 SMTP 伺服器
not configured correctly.請連絡網站的擁有者以重設
您密碼。
</p>
}