83 lines
3.0 KiB
Plaintext
83 lines
3.0 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 = "忘記您的密碼";
|
|
|
|
bool passwordSent = false;
|
|
var resetToken = "";
|
|
var email = Request.Form["email"] ?? Request.QueryString["email"];
|
|
|
|
// 設定驗證
|
|
Validation.RequireField("email", "電子郵件地址欄位為必填。");
|
|
|
|
if (IsPost) {
|
|
AntiForgery.Validate();
|
|
// 驗證電子郵件
|
|
bool isValid = true;
|
|
if (Validation.IsValid()) {
|
|
if (WebSecurity.GetUserId(email) > -1 && WebSecurity.IsConfirmed(email)) {
|
|
resetToken = WebSecurity.GeneratePasswordResetToken(email); // (選擇性)為語彙基元指定到期日期
|
|
} else {
|
|
passwordSent = true; // 我們不想透露使用者不存在。
|
|
isValid = false;
|
|
}
|
|
}
|
|
if (isValid) {
|
|
var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
|
|
var resetUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/PasswordReset?resetToken=" + HttpUtility.UrlEncode(resetToken));
|
|
WebMail.Send(
|
|
to: email,
|
|
subject: "請重設您的密碼",
|
|
body: "使用此密碼重設語彙基元來重設您的密碼。語彙基元為:" + resetToken + @"。造訪 <a href=""" + HttpUtility.HtmlAttributeEncode(resetUrl) + @""">" + resetUrl + "</a> 以重設您的密碼。"
|
|
);
|
|
passwordSent = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
<hgroup class="title">
|
|
<h1>@Page.Title.</h1>
|
|
<h2>使用下列表格來重設您的密碼。</h2>
|
|
</hgroup>
|
|
|
|
@if (!WebMail.SmtpServer.IsEmpty()) {
|
|
<p>
|
|
我們會將密碼重設指示傳送至與您的帳號關聯的電子郵件地址。
|
|
</p>
|
|
|
|
if (passwordSent) {
|
|
<p class="message-success">
|
|
密碼重設指示已經傳送至指定的電子郵件地址。
|
|
</p>
|
|
}
|
|
|
|
<form method="post">
|
|
@AntiForgery.GetHtml()
|
|
@Html.ValidationSummary(excludeFieldErrors: true)
|
|
|
|
<fieldset>
|
|
<legend>密碼重設指示表單</legend>
|
|
<ol>
|
|
<li class="email">
|
|
<label for="email" @if (!ModelState.IsValidField("email")) {<text>class="error-label"</text>}>電子郵件地址</label>
|
|
<input type="text" id="email" name="email" value="@email" disabled="@passwordSent" @Validation.For("email") />
|
|
@Html.ValidationMessage("email")
|
|
</li>
|
|
</ol>
|
|
<p class="form-actions">
|
|
<input type="submit" value="傳送指示" disabled="@passwordSent" />
|
|
</p>
|
|
</fieldset>
|
|
</form>
|
|
} else {
|
|
<p class="message-info">
|
|
已停用此網站的密碼復原,因為 SMTP 伺服器
|
|
未正確設定。請連絡網站的擁有者以重設
|
|
您密碼。
|
|
</p>
|
|
} |