public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // 从外部登入提供者处取得用户信息 var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new AspNet.Identity.IdentityUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInAsync(user, isPersistent : 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); // SendEmail(user.Email, callbackUrl, "确认您的账户", "请单击此连结确认您的账户"); return(RedirectToLocal(returnUrl)); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new AspNet.Identity.IdentityUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, isPersistent : 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>"); if (ServerProfile.GetInstance().Debugger == "0") { return(RedirectToAction("Index", "Home")); } else { Response.Redirect(ServerProfile.GetInstance().WebFormUrl, false); return(null); } } else { AddErrors(result); } } // 如果執行到這裡,發生某項失敗,則重新顯示表單 return(View(model)); }