public async Task<ActionResult> HandleRegisterMember([Bind(Prefix = "registerModel")]RegisterModel model) { if (ModelState.IsValid == false) { return CurrentUmbracoPage(); } var user = new UmbracoApplicationMember() { UserName = model.UsernameIsEmail || model.Username == null ? model.Email : model.Username, Email = model.Email, MemberProperties = model.MemberProperties, MemberTypeAlias = model.MemberTypeAlias }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, isPersistent: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // 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, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); TempData["FormSuccess"] = true; //if there is a specified path to redirect to then use it if (model.RedirectUrl.IsNullOrWhiteSpace() == false) { return Redirect(model.RedirectUrl); } //redirect to current page by default return RedirectToCurrentUmbracoPage(); } else { AddModelErrors(result, "registerModel"); } return CurrentUmbracoPage(); }
private async Task SignInAsync(UmbracoApplicationMember member, bool isPersistent) { OwinContext.Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); OwinContext.Authentication.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, await member.GenerateUserIdentityAsync(UserManager)); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { //go home, already authenticated return RedirectToLocal(returnUrl); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await OwinContext.Authentication.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new UmbracoApplicationMember() { Name = info.ExternalIdentity.Name, UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInAsync(user, isPersistent: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // 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, "Confirm your account", "Please confirm your account by clicking this link"); return RedirectToLocal(returnUrl); } } AddModelErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }