|
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.Username,
Password = model.Password,
Email = model.Email
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
// 有關如何啟用帳戶確認和密碼重設的詳細資料,請訪問 http://go.microsoft.com/fwlink/?LinkID=320771
// 發送包含此連結的電子郵件
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "確認你的帳戶", "請通過單擊 <a href=\"" + callbackUrl + "\">這裏</a>來確認你的帳戶");
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
// 如果我們進行到這一步時某個地方出錯,則重新顯示表單
return View(model);
} |