Exemple #1
0
        public async Task <IActionResult> ResetWallet(ChangeWalletViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            _context.Entry(user).Reference(s => s.Wallet).Load();
            var wallet = user.Wallet;

            if (model.NewWalletKey != model.ConfirmWalletKey)
            {
                ModelState.AddModelError(string.Empty, "Wallet Keys Entered were not Equal.");
                return(View());
            }

            wallet.Currency  = model.NewCurrency;
            wallet.WalletKey = model.NewWalletKey;
            await _context.SaveChangesAsync();

            _logger.LogInformation("User changed their wallet public key successfully.");
            StatusMessage = "Your wallet has been successfully changed.";
            // add View to accomodate for what resetWallet view will look like, update wallet DB
            //return View("ChangeWallet", model);
            return(RedirectToAction(nameof(Index)));
        }
Exemple #2
0
        //[Authorize]
        public async Task <IActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(RedirectToAction(nameof(HomeController.MiningShop), "Home"));
            }
            HttpContext.Session.SetString("userid", userId);
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{userId}'.");
            }
            var result = await _userManager.ConfirmEmailAsync(user, code);

            _context.Entry(user).Reference(s => s.Wallet).Load();
            var wallet = user.Wallet;
            var model  = new ChangeWalletViewModel
            {
                WalletKey = wallet.WalletKey,
                Currency  = wallet.Currency
            };

            if (result.Succeeded)
            {
                //return View(model);
                //return RedirectToAction(nameof(ManageController.ResetWallet), model);
                return(View("ResetWallet", model));
            }

            return(View());
        }
Exemple #3
0
        public async Task <IActionResult> ChangeWallet(ChangeWalletViewModel model)
        {
            //if (!ModelState.IsValid)
            //{
            //    return View();
            //}

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            _context.Entry(user).Reference(s => s.Wallet).Load();
            var wallet = user.Wallet;

            // case: user creating Wallet for 1st time
            if (!model.DoesWalletExist)
            {
                if (model.WalletKey != model.ConfirmWalletKey)
                {
                    ModelState.AddModelError(string.Empty, "Wallet Keys Entered were not Equal.");
                    return(View(model));
                    //return RedirectToAction(nameof(Index));
                }

                user.Wallet = new UserWallet
                {
                    Currency  = model.Currency,
                    WalletKey = model.WalletKey
                };
                await _context.SaveChangesAsync();

                _logger.LogInformation("User created their wallet public key successfully.");
                StatusMessage = "Your wallet has been created.";
            }
            //else if (model.ChangeWalletRequest)
            //{
            //    wallet.Currency = model.Currency;
            //    wallet.WalletKey = model.WalletKey;
            //}

            //await _context.SaveChangesAsync();

            //_logger.LogInformation("User changed their wallet public key successfully.");
            //StatusMessage = "Your wallet has been created.";

            return(RedirectToAction(nameof(Index)));
            //return View();
        }