Esempio n. 1
0
        public IActionResult Logout()
        {
            var storage = new LocalStorage();

            storage.Clear();
            return(Ok());
        }
Esempio n. 2
0
 /// <summary>
 /// Removes all login credentials stored in the data store
 /// </summary>
 /// <returns></returns>
 public void ClearAllLoginCredentials()
 {
     using (var storage = new LocalStorage())
     {
         storage.Clear();
     }
 }
Esempio n. 3
0
        public void LocalStorage_Should_Perform_Decently_With_Large_Collections()
        {
            // arrange - create a larger collection (100K records)
            var stopwatch = Stopwatch.StartNew();
            var storage   = new LocalStorage();

            for (var i = 0; i < 100000; i++)
            {
                storage.Store(Guid.NewGuid().ToString(), i);
            }

            storage.Persist();

            // act - create new instance (e.g. load the larger collection from disk)
            var target = new LocalStorage();

            target.Clear();
            stopwatch.Stop();

            // cleanup - delete the (large!) persisted file
            target.Destroy();

            // assert - make sure the entire operation is done in < 1sec. (psychological boundry, if you will)
            stopwatch.ElapsedMilliseconds.Should().BeLessOrEqualTo(1000);
        }
Esempio n. 4
0
 public IActionResult LogOff(LoginViewModel model, string returnUrl = null)
 {
     using (var storage = new LocalStorage())
     {
         storage.Clear();
     }
     return(RedirectToAction(nameof(Index)));
 }
        public async Task ResetApplication()
        {
            _logger.LogInformation($"Reseting the Application.");

            await _localStorage.Clear();

            await _httpClient.DeleteAsync($"{_serviceBaseUrlProvider.GetServiceBaseUrl()}/api/entire-database");

            await JSRuntime.Current.InvokeAsync <bool>("Refresh");
        }
Esempio n. 6
0
        /// <summary>
        /// Stores the given login credentials to the backing data store
        /// </summary>
        /// <param name="userId">The login credentials to save</param>
        /// <returns>Returns a task that will finish once the save is complete</returns>
        public void SaveLoginCredentials(Guid userId)
        {
            using (var storage = new LocalStorage())
            {
                // Clear all entries
                storage.Clear();

                // Add new one
                storage.Store(Key, userId);
                storage.Persist();
            }
        }
Esempio n. 7
0
        public IActionResult Index()
        {
            localStorage.Clear();

            Users = new UserModel()
            {
                FirstName = "Kishor",
                LastName  = "Naik"
            };

            Data.GetOrSet(localStorage, "mykey", JsonConvert.SerializeObject(Users));

            return(View(Users));
        }
Esempio n. 8
0
        private async Task LogOut()
        {
            try
            {
                // Obteniendo usuario Logiado
                var usLogged = LocalStorage.Get <Usuario>("usuario");
                if (usLogged != null)
                {
                    usLogged.Status = 0;
                    var isSuccess = await usuariosProvider.UpdateAsync(usLogged.UID, usLogged);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error al salir");
            }

            // Clears the in-memory contents of the LocalStorage, but leaves any persisted state on disk intact.
            LocalStorage.Clear();

            // Deletes the persisted file on disk, if it exists, but keeps the in-memory data intact.
            LocalStorage.Destroy();
        }
Esempio n. 9
0
        public void LocalStorage_Clear_Should_Clear_All_Content()
        {
            // arrange - make sure something is stored in the LocalStorage
            var storage  = new LocalStorage();
            var filepath = FileHelpers.GetLocalStoreFilePath(".localstorage");
            var key      = Guid.NewGuid().ToString();
            var value    = Guid.NewGuid();

            storage.Store(key, value);
            storage.Persist();

            // act - clear the store
            storage.Clear();

            // assert - open the file here and make sure the contents are empty
            storage.Count.Should().Be(0);
        }
        public static string Clear()
        {
            string response = string.Empty;

            try
            {
                using (var storage = new LocalStorage())
                {
                    storage.Clear();
                    storage.Destroy();
                }
            }
            catch (Exception ex)
            {
                response = ex.Message;
            }
            return(response);
        }
Esempio n. 11
0
        public void LocalStorageListItems()
        {
            var ls = new LocalStorage();

            ls.Clear <SampleItem>();

            const int itemCount = 100;

            // create 100 dummy items
            for (int i = 0; i < itemCount; i++)
            {
                ls.CreateItemAsync(new SampleItem()
                {
                    FirstName = $"someone{i}", LastName = "anyone"
                }).Wait();
            }

            // now query all these items, iterating over all the page
            Dictionary <string, SampleItem> results = new Dictionary <string, SampleItem>();
            int page = 0;

            do
            {
                var items = ls.QueryItemsAsync <SampleItem>(page).Result;
                foreach (var item in items)
                {
                    results.Add(item.Key, item.Value);
                }
                if (!items.Any())
                {
                    break;
                }
                page++;
            } while (true);

            // the number of results should equal what we started with
            Assert.IsTrue(results.Count == itemCount);
        }
Esempio n. 12
0
 public static void Clear()
 {
     storage.Clear();
     storage.Destroy();
 }
Esempio n. 13
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            // TODO: Figure out how to make this happen when the Session restarts as well. When browser closes a long time the fields are not populated
            //      and I think this is because the ApiToken Cookie is stale

            // ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(
                    model.Username,
                    model.Password,
                    model.RememberMe,
                    lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        // Get API Token with valid credentials
                        var request = new HttpRequestMessage(HttpMethod.Post, "/token");

                        var postData = new List <KeyValuePair <string, string> >
                        {
                            new KeyValuePair <string, string>(GrantType, GrantTypeValue),
                            new KeyValuePair <string, string>(UsernameKey, model.Username),
                            new KeyValuePair <string, string>(PasswordKey, model.Password)
                        };

                        request.Content = new FormUrlEncodedContent(postData);
                        var response = await _httpClient.SendAsync(request);

                        if (response.IsSuccessStatusCode)
                        {
                            var      info     = response.Content.ReadAsStringAsync().Result;
                            ApiToken apiToken = JsonConvert.DeserializeObject <ApiToken>(info);
                            var      token    = apiToken.Access_Token;

                            // Create Session with API Access Token
                            HttpContext.Session.Clear(); // Clear any persisting session data
                            HttpContext.Session.SetString(SessionKeyName, token);

                            // Add Token to LocalStorage
                            using (var storage = new LocalStorage())
                            {
                                // TODO - create update scheme
                                storage.Clear(); // First clear storage
                                storage.Store("ApiTokenStorage", token);
                                storage.Persist();
                            }
                        }

                        var user = await _userManager.FindByNameAsync(model.Username);

                        if (await _userManager.IsInRoleAsync(user, "Sales"))
                        {
                            return(RedirectToAction(nameof(SalesController.Index), "Sales"));
                        }
                        else if (await _userManager.IsInRoleAsync(user, "Executive"))
                        {
                            return(RedirectToAction(nameof(ExecutiveController.Index), "Executive"));
                        }
                        else if (await _userManager.IsInRoleAsync(user, "Administrator"))
                        {
                            return(RedirectToAction(nameof(AdministratorController.Index), "Administrator"));
                        }
                        else if (await _userManager.IsInRoleAsync(user, "SignShop"))
                        {
                            return(RedirectToAction(nameof(SignShopController.Index), "SignShop"));
                        }
                        else
                        {
                            return(RedirectToAction(nameof(HomeController.Index), "Home"));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 14
0
 public async Task ClearLocalStorage()
 {
     await LocalStorage.Clear();
 }
Esempio n. 15
0
 public void Dispose()
 {
     localStorage.Clear();
 }
Esempio n. 16
0
 public void Clear()
 {
     storage.Clear();
 }
 public void RemoveToken()
 {
     loc.Clear();
 }
Esempio n. 18
0
        public IActionResult Index()
        {
            var token            = string.Empty;
            var loggedInUserInfo = new LoggedInUserInfo();

            using (var storage = new LocalStorage())
            {
                if (storage.Exists("userInfo"))
                {
                    loggedInUserInfo = JsonConvert.DeserializeObject <LoggedInUserInfo>(storage.Get("userInfo").ToString());
                    token            = storage.Get("jwtToken").ToString();
                }
            }

            if (string.IsNullOrEmpty(token))
            {
                using (var storage = new LocalStorage())
                {
                    storage.Clear();
                }
                return(View());
            }

            PayloadResponse response = new PayloadResponse();

            using (var repository = new WebApiClientRepository <PayloadResponse>())
            {
                try
                {
                    response = repository.GlobalApiCallPost(null, "api/Auth/KeepAlive");

                    if (response == null || !response.Success)
                    {
                        using (var storage = new LocalStorage())
                        {
                            storage.Clear();
                        }
                        return(View());
                    }
                }
                catch (Exception)
                {
                    return(View());
                }
            }

            if (loggedInUserInfo != null && loggedInUserInfo.UserID > 0)
            {
                switch (loggedInUserInfo.Role)
                {
                case "Coach": return(RedirectToAction(nameof(CoachController.Index), "Coach"));

                case "Athlete":
                    return(RedirectToAction(nameof(AthleteController.Index), "Athlete"));

                default:
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Esempio n. 19
0
 public void Clear()
 {
     localStorage.Clear();
 }
Esempio n. 20
0
 public void ClearToken()
 {
     _storage.Clear();
 }