public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await AplicationUserService.CreateAsync(user, model.Password); if (result.Succeeded) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : 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>"); //Assign Role to user Here await AplicationUserService.AddToRoleAsync(user.Id, model.UserRole); //Ends Here return(RedirectToAction("Index", "Home")); } //ViewBag.Name = new SelectList(context.Roles.Where(u => !u.Name.Contains("Admin")) // .ToList(), "Name", "Name"); AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> DisableTwoFactorAuthentication() { await AplicationUserService.SetTwoFactorEnabledAsync(User.Identity.GetUserId(), false); var user = await AplicationUserService.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", "Manage")); }
// // GET: /Manage/RemovePhoneNumber public async Task <ActionResult> RemovePhoneNumber() { var result = await AplicationUserService.SetPhoneNumberAsync(User.Identity.GetUserId(), null); if (!result.Succeeded) { return(RedirectToAction("Index", new { Message = ManageMessageId.Error })); } var user = await AplicationUserService.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.RemovePhoneSuccess })); }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = await AplicationUserService.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = await AplicationUserService.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess })); } AddErrors(result); return(View(model)); }
public async Task <ActionResult> RemoveLogin(string loginProvider, string providerKey) { ManageMessageId?message; var result = await AplicationUserService.RemoveLoginAsync(User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey)); if (result.Succeeded) { var user = await AplicationUserService.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); } message = ManageMessageId.RemoveLoginSuccess; } else { message = ManageMessageId.Error; } return(RedirectToAction("ManageLogins", new { Message = message })); }
public async Task <ActionResult> SetPassword(SetPasswordViewModel model) { if (ModelState.IsValid) { var result = await AplicationUserService.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword); if (result.Succeeded) { var user = await AplicationUserService.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess })); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = await AplicationUserService.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code); if (result.Succeeded) { var user = await AplicationUserService.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess })); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "Failed to verify phone"); return(View(model)); }
public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Manage")); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return(View("ExternalLoginFailure")); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await AplicationUserService.CreateAsync(user); if (result.Succeeded) { result = await AplicationUserService.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await AplicationSignInService.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToLocal(returnUrl)); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return(View(model)); }