public async Task <IActionResult> Index() { ViewBag.Title = "Security"; var securityViewModel = new SecurityViewModel(); try { var user = await UserManager.GetUserAsync(HttpContext.User); if (user != null) { securityViewModel = await CreateNewData(user); securityViewModel.ChangePassModel.IsTabSelected = true; securityViewModel.ChangePassModel.TabShow = "active show"; securityViewModel.ChangePassModel.Status = SecurityViewModel.StatusDefault; } else { return(RedirectToAction(nameof(AccountController.Login), "Account")); } } catch (Exception e) { Logger.LogError("HttpGet SendSms: " + e.Message); ModelState.AddModelError(string.Empty, "Security"); } return(View(securityViewModel)); }
private async Task <SecurityViewModel> CreateNewData(ApplicationUser user) { try { var securityViewModel = new SecurityViewModel { Email = user.Email, PhoneNumber = user.PhoneNumber, TwoFactorEnable = user.TwoFactorEnabled, IsGoogleAuthenticator = user.IsGoogleAuthenticator, ChangePassModel = new ChangePassModel(), MobileModel = new MobileModel(), LockScreenModel = new LockScreenModel(), DeactiveModel = new DeactiveModel() }; var authenticator = new EnableAuthenticatorViewModel(); await LoadSharedKeyAndQrCodeUriAsync(user, authenticator); securityViewModel.Authenticator = authenticator; var countryCode = await GetCurrentCountryCode(); securityViewModel.MobileModel.CountryCode = countryCode; securityViewModel.MobileModel.Confirmed = user.PhoneNumberConfirmed; securityViewModel.MobileModel.IsTwoFaSms = user.TwoFactorEnabled && !user.IsGoogleAuthenticator; securityViewModel.MobileModel.IsTwoFaGoogle = user.TwoFactorEnabled && user.IsGoogleAuthenticator; if (user.CountryCode != null) { securityViewModel.MobileModel.CallingCode = user.CountryCode; } else { foreach (var item in Const.ListCountryModels) { if (string.Equals(item.Code, countryCode)) { securityViewModel.MobileModel.CallingCode = item.CallingCode; } } } securityViewModel.MobileModel.PhoneHide = SendSmsController.GetPhoneHide(user.CountryCode, user.PhoneNational); securityViewModel.MobileModel.Confirmed = user.PhoneNumberConfirmed; return(securityViewModel); } catch (Exception) { return(new SecurityViewModel()); } }
public async Task <IActionResult> Index(SecurityViewModel model) { var securityTempModel = new SecurityViewModel(); try { var user = await UserManager.GetUserAsync(HttpContext.User); if (user == null) { return(RedirectToAction(nameof(AccountController.Login), "Account")); } securityTempModel = await CreateNewData(user); if (model.ChangePassModel != null) { securityTempModel.ChangePassModel = await HandleChangePassword(model.ChangePassModel, user); } else if (model.MobileModel != null) { securityTempModel.MobileModel = await HandleMobile(model.MobileModel, user); securityTempModel.MobileModel.Code = ""; if (securityTempModel.MobileModel.Status == SecurityViewModel.StatusSuccess) { if (securityTempModel.MobileModel.Type.Equals(MobileModel.TypeAddPhoneNumber) || securityTempModel.MobileModel.Type.Equals(MobileModel.TypeChangePhoneNumber) || securityTempModel.MobileModel.Type.Equals(MobileModel.TypeConfirmPhoneNumber)) { securityTempModel.PhoneNumber = securityTempModel.MobileModel.CallingCode + securityTempModel.MobileModel.PhoneNational; securityTempModel.MobileModel.Confirmed = true; securityTempModel.MobileModel.PhoneHide = SendSmsController.GetPhoneHide(user.CountryCode, user.PhoneNational); securityTempModel.MobileModel.IsTwoFaSms = user.TwoFactorEnabled && !user.IsGoogleAuthenticator; securityTempModel.MobileModel.IsTwoFaGoogle = user.TwoFactorEnabled && user.IsGoogleAuthenticator; } else if (securityTempModel.MobileModel.Type.Equals(MobileModel.TypeEnableTwoFaSms) || securityTempModel.MobileModel.Type.Equals(MobileModel.TypeChangeTwoFaGoogleToSms)) { securityTempModel.TwoFactorEnable = true; securityTempModel.MobileModel.IsTwoFaSms = true; securityTempModel.MobileModel.IsTwoFaGoogle = false; securityTempModel.MobileModel.Confirmed = true; securityTempModel.MobileModel.PhoneHide = SendSmsController.GetPhoneHide(user.CountryCode, user.PhoneNational); } else if (securityTempModel.MobileModel.Type.Equals(MobileModel.TypeEnableTwoFaGoogle)) { securityTempModel.TwoFactorEnable = true; securityTempModel.IsGoogleAuthenticator = true; securityTempModel.MobileModel.IsTwoFaSms = false; securityTempModel.MobileModel.IsTwoFaGoogle = true; securityTempModel.MobileModel.Confirmed = true; securityTempModel.MobileModel.PhoneHide = SendSmsController.GetPhoneHide(user.CountryCode, user.PhoneNational); } else if (securityTempModel.MobileModel.Type.Equals(MobileModel.TypeDisableTwoFa)) { securityTempModel.TwoFactorEnable = false; securityTempModel.IsGoogleAuthenticator = false; securityTempModel.MobileModel.IsTwoFaSms = false; securityTempModel.MobileModel.IsTwoFaGoogle = false; securityTempModel.MobileModel.Confirmed = true; securityTempModel.MobileModel.PhoneHide = SendSmsController.GetPhoneHide(user.CountryCode, user.PhoneNational); } } else { securityTempModel.MobileModel.Confirmed = true; securityTempModel.MobileModel.PhoneHide = SendSmsController.GetPhoneHide(user.CountryCode, user.PhoneNational); } } else if (model.DeactiveModel != null) { securityTempModel.DeactiveModel = await HandleDeActiveAccount(model.DeactiveModel, user); if (securityTempModel.DeactiveModel.Status == SecurityViewModel.StatusSuccess) { return(RedirectToAction(nameof(AccountController.Login), "Account")); } } else { return(View(securityTempModel)); } } catch (Exception e) { Logger.LogError("Security Error: " + e.Message); } ViewBag.Title = "Security"; return(View(securityTempModel)); }