コード例 #1
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();
            }
        }
コード例 #2
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           = "";
            }
        }
コード例 #3
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();
            }
        }