public virtual async Task <ActionResult> ResendCode() { var accountBL = ServiceLocator.Current.GetInstance <IAccountBL>(); var userId = await CustomSignIn.GetVerifiedUserIdAsync().WithCurrentCulture(); string phoneCode = await CustomUser.GenerateTwoFactorTokenAsync(userId, "Phone Code"); await accountBL.SaveMobileGeneratedVerificationCode(Convert.ToInt32(userId), Convert.ToInt32(phoneCode)); return(Json(new { })); }
public virtual async Task <ActionResult> Roles(int roleId) { var user = await CustomUser.FindByIdAsync(User.Identity.GetUserId()); await CustomUser.AddToRoleAsync(user.Id, Enum.GetName(typeof(DTO.Constants.RolesEnum), roleId)); await CustomUser.AddClaimAsync(user.Id, new Claim(ClaimTypes.Role, roleId.ToString())); await CustomSignIn.SignInAsync(user, false, false); return(RedirectToAction(Mvc.Manage.Roles())); }
public async virtual Task <ActionResult> Login(LoginViewModel model, string returnUrl) { // var token = await CustomUser.GenerateTwoFactorTokenAsync("1024", "Phone Code"); // ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie); // identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "1020")); // AuthenticationManager.SignIn(identity); //return RedirectToAction(Mvc.Account.VerifyCode("EmailTokenProvider", Url.Action(Mvc.Customers.Customer.Default()), false)); if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var user = await CustomUser.FindByNameAsync(model.Email.ToLower().Trim()); if (user == null) { ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } if (!await CustomUser.IsEmailConfirmedAsync(user.Id)) { ModelState.AddModelError("", "You need to confirm your email."); return(View(model)); } var result = await CustomSignIn.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction(Mvc.Account.VerifyCode("Phone Code", Url.Action(Mvc.Home.Index()), false))); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public async virtual Task <ActionResult> VerifyCode(string provider, string returnUrl, bool rememberMe) { // Require that the user has already logged in via username/ password or external login if (!await CustomSignIn.HasBeenVerifiedAsync()) { return(View("Error")); } //if (User.Identity.GetUserId() == null) //{ // return View("Error"); //} return(View(new VerifyCodeViewModel { Provider = provider, ReturnUrl = returnUrl, RememberMe = rememberMe })); }
public virtual async Task <ActionResult> SendCode(string returnUrl, bool rememberMe) { var userId = await CustomSignIn.GetVerifiedUserIdAsync(); if (userId == null) { return(View("Error")); } var userFactors = await CustomUser.GetValidTwoFactorProvidersAsync(userId); var factorOptions = userFactors.Select(purpose => new SelectListItem { Text = purpose, Value = purpose }).ToList(); return(View(new SendCodeViewModel { Providers = factorOptions, ReturnUrl = returnUrl, RememberMe = rememberMe })); }
public virtual async Task <ActionResult> ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var result = await CustomUser.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = await CustomUser.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await CustomSignIn.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess })); } AddErrors(result); return(View(model)); }
public virtual async Task <ActionResult> VerifyCode(VerifyCodeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } // The following code protects for brute force attacks against the two factor codes. // If a user enters incorrect codes for a specified amount of time then the user account // will be locked out for a specified amount of time. // You can configure the account lockout settings in IdentityConfig var result = await CustomSignIn.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent : model.RememberMe, rememberBrowser : model.RememberBrowser); switch (result) { case SignInStatus.Success: var userId = await CustomSignIn.GetVerifiedUserIdAsync().WithCurrentCulture(); var accountBL = ServiceLocator.Current.GetInstance <IAccountBL>(); await accountBL.ApproveVerification(Convert.ToInt32(userId)); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); var user = await CustomUser.FindByIdAsync(userId); await CustomSignIn.SignInAsync(user, model.RememberMe, model.RememberBrowser); return(RedirectToLocal(model.ReturnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid code."); return(View(model)); } }