public async Task <IActionResult> EnterPassword(EnterPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                string username = HttpContext.Session.GetString(AuthenticationChallengeConstants.SessionKeyUsername);
                if (username != null)
                {
                    int?            answeredChallengeQuestions = HttpContext.Session.GetInt32(AuthenticationChallengeConstants.SessionKeyAnsweredChallengeQuestions);
                    ApplicationUser user = _userManager.Users.SingleOrDefault(u => u.UserName == username);
                    if (user.TotpEnabled)
                    {
                        ModelState.AddModelError(string.Empty, "Cannot log in here. User is set up for TOTP login.");
                        return(View(model));
                    }
                    if (!user.HasSetupChallengeQuestions() || answeredChallengeQuestions == 1)
                    {
                        Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(username, model.Password, false, false);

                        if (result.Succeeded)
                        {
                            user = _userManager.Users.SingleOrDefault(u => u.UserName == username);
                            if (!user.HasSetupChallengeQuestions())
                            {
                                return(RedirectToAction(nameof(SetupChallengeQuestions)));
                            }
                            else
                            {
                                return(RedirectToAction(nameof(ManageController.Index), nameof(ManageController).Replace("Controller", "")));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                            model.Password = "";
                            model.Username = username;
                            return(View(model));
                        }
                    }
                }
            }
            return(RedirectToAction(nameof(Login), new { Message = AuthenticationChallengeConstants.LoginPageMessageFailure }));
        }
Exemple #2
0
        public AddWalletPageViewModel(NavigationStateViewModel navigationState, WalletManager walletManager,
                                      BitcoinStore store, Network network) : base(navigationState, NavigationTarget.DialogScreen)
        {
            Title = "Add Wallet";

            this.WhenAnyValue(x => x.WalletName)
            .Select(x => !string.IsNullOrWhiteSpace(x))
            .Subscribe(x => OptionsEnabled = x && !Validations.Any);

            RecoverWalletCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                NavigateTo(new RecoverWalletViewModel(navigationState, WalletName, network, walletManager), NavigationTarget.DialogScreen);
            });

            CreateWalletCommand = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var enterPassword = new EnterPasswordViewModel(
                    navigationState,
                    NavigationTarget.DialogScreen,
                    "Type the password of the wallet and click Continue.");

                NavigateTo(enterPassword, NavigationTarget.DialogScreen);

                var result = await enterPassword.GetDialogResultAsync();

                if (result is { } password)
                {
                    var(km, mnemonic) = await Task.Run(
                        () =>
                    {
                        var walletGenerator = new WalletGenerator(
                            walletManager.WalletDirectories.WalletsDir,
                            network)
                        {
                            TipHeight = store.SmartHeaderChain.TipHeight
                        };
                        return(walletGenerator.GenerateWallet(WalletName, password));
                    });

                    NavigateTo(new RecoveryWordsViewModel(navigationState, km, mnemonic, walletManager), NavigationTarget.DialogScreen, true);
                }
        public async Task <IActionResult> EnterPassword()
        {
            string username = HttpContext.Session.GetString(AuthenticationChallengeConstants.SessionKeyUsername);

            if (username != null)
            {
                EnterPasswordViewModel model = new EnterPasswordViewModel
                {
                    Username = username
                };
                ApplicationUser user = _userManager.Users.SingleOrDefault(u => u.UserName == username);
                int?            answeredChallengeQuestions = HttpContext.Session.GetInt32(AuthenticationChallengeConstants.SessionKeyAnsweredChallengeQuestions);
                if (!user.HasSetupChallengeQuestions() || answeredChallengeQuestions == 1)
                {
                    return(await Task.FromResult(View(model)));
                }
            }

            return(await Task.FromResult(RedirectToAction(nameof(Login), new { Message = AuthenticationChallengeConstants.LoginPageMessageFailure })));
        }