public async Task <IActionResult> GetNoteById(string encrypted_id)
        {
            var noteId = Int32.Parse(dataProtectionHelper.Decrypt(encrypted_id, "QueryStringsEncryptions"));


            var notes = await _cacheService.GetOrCreateCachedResponse <Note>(CacheKeys.Note + AuthUserId, () => _apiService.GetAllUserData <Note>(Int32.Parse(AuthUserId)));

            var note = notes.FirstOrDefault(x => x.Id == noteId);

            return(PartialView("Views/Forms/DetailsNote.cshtml", DecryptModel(note)));
        }
        public async Task <IActionResult> GetLoginDataById(string encrypted_id)
        {
            var loginDataId = Int32.Parse(dataProtectionHelper.Decrypt(encrypted_id, _config["QueryStringsEncryptions"]));
            var logins      = await _cacheService.GetOrCreateCachedResponse <LoginData>(CacheKeys.LoginData + AuthUserId, () => _apiService.GetAllUserData <LoginData>(Int32.Parse(AuthUserId)));

            var loginData          = logins.FirstOrDefault(x => x.Id == loginDataId);
            var decryptedLoginData = DecryptModel(loginData);

            OnDataView(new LoginData {
                Name = loginData.Name, Password = decryptedLoginData.Password, UserId = loginData.UserId
            });
            return(PartialView("Views/Forms/DetailsLoginData.cshtml", decryptedLoginData));
        }
Esempio n. 3
0
        public async Task <IActionResult> TwoFactorLogIn(string id, TwoFactorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("Error", "Code can not be null.");
                ViewBag.AuthUserId = id;
                return(View(new TwoFactorViewModel()));
            }



            int idUser = Int32.Parse(dataProtectionHelper.Decrypt(id, "QueryStringsEncryptions"));


            ApiTwoFactorResponse apiResponse = await _apiService.TwoFactorLogIn(idUser, model.Token);


            if (apiResponse.VerificationStatus != 1)
            {
                if (apiResponse.VerificationStatus == 0)
                {
                    ViewBag.AuthUserId = id;
                    ModelState.AddModelError("Error", apiResponse.Messages.First());

                    return(View(new TwoFactorViewModel()));
                }
                else
                {
                    TempData["logoutMessage"] = "Your code has expired. Try log in again.";
                    _encryptionService.RemoveEncryptionKey(idUser.ToString());
                    return(RedirectToAction(controllerName: "Home", actionName: "Index"));
                }
            }


            ClaimsPrincipal          claimsPrincipal;
            AuthenticationProperties authProperties;
            var isSuccess = _jwtHelper.ValidateToken(apiResponse.AccessToken, out claimsPrincipal, out authProperties);

            if (!isSuccess)
            {
                ViewBag.AuthUserId = id;
                ModelState.AddModelError("Error", "Token is invalid.");

                return(View(new TwoFactorViewModel()));
            }
            await _logInHandler.LogInUser(claimsPrincipal, authProperties);

            return(RedirectToAction("Index", "Wallet"));
        }
        public bool ValidateToken(string token, string password)
        {
            var authUserId = _httpContextAccessor.
                             HttpContext.User.Identity.Name;
            User   authUser       = GetById(Int32.Parse(authUserId));
            string decryptedToken = "";

            try
            {
                decryptedToken = dataProtectionHelper.Decrypt(token, password);
            }
            catch (CryptographicException)
            {
                return(false);
            }
            var tokenArray = decryptedToken.Split("|");

            if (tokenArray[0].Equals(authUserId) && tokenArray[1].Equals(authUser.Email))
            {
                DateTime expiredDate = DateTime.Parse(tokenArray[2]);
                if (DateTime.Compare(DateTime.UtcNow, expiredDate) < 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        public async Task <IActionResult> AddOrEditPhone(string encrypted_id)
        {
            if (encrypted_id is null)
            {
                ViewBag.Id = 0;
                return(PartialView("Views/Forms/AddOrEditPhone.cshtml", new PhoneNumber()));
            }
            else
            {
                int decrypted_id = Int32.Parse(dataProtectionHelper.Decrypt(encrypted_id, _config["QueryStringsEncryptions"]));

                var phones = await _cacheService.GetOrCreateCachedResponse <PhoneNumber>(CacheKeys.PhoneNumber + AuthUserId, () => _apiService.GetAllUserData <PhoneNumber>(Int32.Parse(AuthUserId)));

                var phone = phones.FirstOrDefault(x => x.Id == decrypted_id);


                ViewBag.Id = encrypted_id;
                return(PartialView("Views/Forms/AddOrEditPhone.cshtml", phone));
            }
        }
Esempio n. 6
0
    static void Main(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("Provide encrypted password value from the config file.");
            return;
        }
        DataProtectionHelper helper = new DataProtectionHelper();

        Console.WriteLine(helper.Decrypt(args[0]));
    }
Esempio n. 7
0
        public async Task <IActionResult> AddOrEditAddress(string?encrypted_id)
        {
            if (encrypted_id is null)
            {
                ViewBag.Id = 0;
                return(PartialView("Views/Forms/AddOrEditAddress.cshtml", new Address()));
            }
            else
            {
                int decrypted_id = Int32.Parse(dataProtectionHelper.Decrypt(encrypted_id, "QueryStringsEncryptions"));



                var adressess = await _cacheService.GetOrCreateCachedResponse <Address>(CacheKeys.Address + AuthUserId, () => _apiService.GetAllUserData <Address>(Int32.Parse(AuthUserId)));

                var address = adressess.FirstOrDefault(x => x.Id == decrypted_id);



                ViewBag.Id = encrypted_id;
                return(PartialView("Views/Forms/AddOrEditAddress.cshtml", DecryptModel(address)));
            }
        }
Esempio n. 8
0
        public async Task <IActionResult> AddOrEditPersonal(string?encrypted_id)
        {
            if (encrypted_id is null)
            {
                ViewBag.Id = 0;
                return(PartialView("Views/Forms/AddOrEditPersonal.cshtml", new PersonalInfo()));
            }
            else
            {
                int decrypted_id = Int32.Parse(dataProtectionHelper.Decrypt(encrypted_id, "QueryStringsEncryptions"));



                var personalinfos = await _cacheService.GetOrCreateCachedResponse <PersonalInfo>(CacheKeys.PersonalInfo + AuthUserId, () => _apiService.GetAllUserData <PersonalInfo>(Int32.Parse(AuthUserId)));

                var personalinfo = personalinfos.FirstOrDefault(x => x.Id == decrypted_id);



                ViewBag.Id = encrypted_id;
                return(PartialView("Views/Forms/AddOrEditPersonal.cshtml", personalinfo));
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> AddOrEditPayPal(string encrypted_id)
        {
            if (encrypted_id is null)
            {
                ViewBag.Id = 0;
                return(PartialView("Views/Forms/AddOrEditPayPal.cshtml", new PaypalAccount()));
            }
            else
            {
                int decrypted_id = Int32.Parse(dataProtectionHelper.Decrypt(encrypted_id, "QueryStringsEncryptions"));

                var paypals = await _cacheService.GetOrCreateCachedResponse <PaypalAccount>(CacheKeys.CreditCard + AuthUserId, () => _apiService.GetAllUserData <PaypalAccount>(Int32.Parse(AuthUserId)));

                var paypal = paypals.FirstOrDefault(x => x.Id == decrypted_id);
                ViewBag.Id = encrypted_id;
                return(PartialView("Views/Forms/AddOrEditPayPal.cshtml", DecryptModelPay(paypal)));
            }
        }