Ejemplo n.º 1
0
        /// <summary>
        /// This method Removed Local Store Items
        /// </summary>
        public async Task <bool> RemovedLocalStoreItems()
        {
            // initial value
            bool removed = false;

            try
            {
                // if the ProtectedLocalStore exists
                if (ProtectedLocalStore != null)
                {
                    // delete doesn't seem to work, so I am setting to false
                    await ProtectedLocalStore.SetAsync("RememberLogin", false);

                    // Remove all items
                    await ProtectedLocalStore.DeleteAsync("RememberPassword");

                    await ProtectedLocalStore.DeleteAsync("EmailAddress");

                    await ProtectedLocalStore.DeleteAsync("PasswordHash");
                }

                // set to true
                removed = true;
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("RemoveLocalStoreItems", "Login.cs", error);
            }

            // return value
            return(removed);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method Store Local Store Items
        /// </summary>
        public async Task <bool> StoreLocalStoreItems(string emailAddress, string passwordHash)
        {
            // initial value
            bool saved = false;

            try
            {
                // try saving
                await ProtectedLocalStore.SetAsync("RememberLogin", true);

                await ProtectedLocalStore.SetAsync("EmailAddress", emailAddress);

                await ProtectedLocalStore.SetAsync("PasswordHash", passwordHash);

                // presumption
                saved = true;
            }
            catch (Exception error)
            {
                // for debugging only for now
                DebugHelper.WriteDebugError("StoreLocalStoreItems", "Index.razor.cs", error);
            }

            // return value
            return(saved);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method is used to restored values stored in local storage
        /// </summary>
        protected override async Task OnInitializedAsync()
        {
            try
            {
                // get the values from local storage if present
                RememberLogin = await ProtectedLocalStore.GetAsync <bool>("RememberLogin");

                // if RememberLogin is true
                if (RememberLogin)
                {
                    emailAddress = await ProtectedLocalStore.GetAsync <string>("ArtistEmailAddress");

                    storedPasswordHash = await ProtectedLocalStore.GetAsync <string>("ArtistPasswordHash");

                    password = "******";
                }
                else
                {
                    // erase
                    emailAddress       = "";
                    storedPasswordHash = "";
                    password           = "";
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("OnInitializedAsync", "Login.cs", error);
            }
            finally
            {
                // Always call this
                Init();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method Handle Remember Password
        /// </summary>
        public async void HandleRememberPassword()
        {
            // if remember login details is true
            if ((HasLoginResponse) && (RememberLogin) && (LoginResponse.HasArtist))
            {
                // Set the artist
                artist = LoginResponse.Artist;

                await ProtectedLocalStore.SetAsync("RememberLogin", rememberLogin);

                await ProtectedLocalStore.SetAsync("ArtistEmailAddress", artist.EmailAddress);

                await ProtectedLocalStore.SetAsync("ArtistPasswordHash", artist.PasswordHash);
            }
            else
            {
                // Remove any locally stored items
                RemovedLocalStoreItems();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method Removed Local Store Items
        /// </summary>
        public async void RemovedLocalStoreItems()
        {
            try
            {
                // if the ProtectedLocalStore exists
                if (ProtectedLocalStore != null)
                {
                    // delete doesn't seem to work, so I am setting to false
                    await ProtectedLocalStore.SetAsync("RememberLogin", false);

                    // Remove all items
                    //await ProtectedLocalStore.DeleteAsync("RememberPassword");
                    //await ProtectedLocalStore.DeleteAsync("ArtistEmailAddress");
                    //await ProtectedLocalStore.DeleteAsync("ArtistPasswordHash");
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("RemoveLocalStoreItems", "Login.cs", error);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method Load Local Private Data
        /// </summary>
        public async Task LoadLocalPrivateData()
        {
            // get the values from local storage if present
            RememberLogin = await ProtectedLocalStore.GetAsync <bool>("RememberLogin");

            // if RememberLogin is true
            if (RememberLogin)
            {
                emailAddress = await ProtectedLocalStore.GetAsync <string>("ArtistEmailAddress");

                storedPasswordHash = await ProtectedLocalStore.GetAsync <string>("ArtistPasswordHash");

                password = "******";
            }
            else
            {
                // erase
                emailAddress       = "";
                storedPasswordHash = "";
                password           = "";
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This method is used to verify a user
        /// </summary>
        /// <param name="firstRender"></param>
        /// <returns></returns>
        protected async override Task OnAfterRenderAsync(bool firstRender)
        {
            // if there is not a logged in user
            if (!HasLoggedInUser)
            {
                // locals
                string emailAddress       = "";
                string storedPasswordHash = "";

                try
                {
                    // get the values from local storage if present
                    bool rememberLogin = await ProtectedLocalStore.GetAsync <bool>("RememberLogin");

                    // if rememberLogin is true
                    if (rememberLogin)
                    {
                        emailAddress = await ProtectedLocalStore.GetAsync <string>("EmailAddress");

                        storedPasswordHash = await ProtectedLocalStore.GetAsync <string>("PasswordHash");

                        // If the emailAddress string exists
                        if (TextHelper.Exists(emailAddress))
                        {
                            // Attempt to find this user
                            User user = await UserService.FindUserByEmailAddress(emailAddress);

                            // If the user object exists
                            if (NullHelper.Exists(user))
                            {
                                // get the key
                                string key = EnvironmentVariableHelper.GetEnvironmentVariableValue("BlazorChat");

                                // if the key was found
                                if (TextHelper.Exists(key))
                                {
                                    // can this artist be verified
                                    bool isVerified = CryptographyHelper.VerifyHash(storedPasswordHash, key, user.PasswordHash, true);

                                    // if the value for isVerified is true
                                    if (isVerified)
                                    {
                                        // Set the LoggedInuser
                                        LoggedInUser = user;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception error)
                {
                    // for debugging only
                    DebugHelper.WriteDebugError("OnAfterRenderAsync", "Login.cs", error);
                }
            }

            // call the base
            await base.OnAfterRenderAsync(firstRender);

            // if the value for HasLoggedInUser is true
            if ((HasLoggedInUser) && (firstRender))
            {
                // Refresh the UI
                Refresh();
            }
        }