コード例 #1
0
ファイル: UserSession.cs プロジェクト: Artak11111/SSCC
        public void EndSession()
        {
            IsSessionStarted = false;

            UserId         = DepartmentId = null;
            DepartmentName = Name = Email = null;

            AuthenticationStateChanged?.Invoke(IsSessionStarted);
        }
コード例 #2
0
        /// <summary>
        /// Raises the <see cref="AuthenticationStateChanged"/> event.
        /// </summary>
        /// <param name="task">A <see cref="Task"/> that supplies the updated <see cref="AuthenticationState"/>.</param>
        protected void NotifyAuthenticationStateChanged(Task <AuthenticationState> task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            AuthenticationStateChanged?.Invoke(task);
        }
コード例 #3
0
ファイル: UserSession.cs プロジェクト: Artak11111/SSCC
        public void StartSession(SignInResult signInResult)
        {
            UserId         = signInResult.UserId;
            Name           = signInResult.Name;
            Email          = signInResult.Email;
            DepartmentId   = signInResult.DepartmentId;
            DepartmentName = signInResult.DepartmentName;

            IsSessionStarted = true;

            AuthenticationStateChanged?.Invoke(IsSessionStarted);
        }
コード例 #4
0
        public async Task Logout()
        {
            using var scope = serviceProvider.CreateScope();
            var localStorage      = scope.ServiceProvider.GetRequiredService <ILocalStorageService>();
            var authStateProvider = scope.ServiceProvider.GetRequiredService <AuthenticationStateProvider>();

            await localStorage.RemoveItemAsync(StorageAuthTokenKey);

            if (authStateProvider is ApiAuthenticationStateProvider apiAuthenticationStateProvider)
            {
                apiAuthenticationStateProvider.UpdateAuthenticationState();
            }

            AuthenticationStateChanged?.Invoke(this, new EventArgs());
        }
コード例 #5
0
        private async Task UpdateToken(IServiceScope scope, ApiResponse <AuthResponse> result, HttpResponseMessage httpResponse, string username = null)
        {
            var localStorage      = scope.ServiceProvider.GetRequiredService <ILocalStorageService>();
            var authStateProvider = scope.ServiceProvider.GetRequiredService <AuthenticationStateProvider>();

            if (httpResponse.IsSuccessStatusCode)
            {
                await localStorage.SetItemAsync(StorageAuthTokenKey, result.Data.Token);

                if (username != null)
                {
                    await localStorage.SetItemAsync(StorageAuthUsernameKey, username);
                }

                if (authStateProvider is ApiAuthenticationStateProvider apiAuthenticationStateProvider)
                {
                    apiAuthenticationStateProvider.UpdateAuthenticationState();
                }

                AuthenticationStateChanged?.Invoke(this, new EventArgs());
            }
        }
コード例 #6
0
 protected virtual void OnAuthenticationStateChanged()
 {
     AuthenticationStateChanged?.Invoke(this, EventArgs.Empty);
 }
コード例 #7
0
 protected virtual void OnAuthenticationChanged()
 {
     AuthenticationStateChanged.Invoke(_authenticationState);
 }
コード例 #8
0
 protected virtual void OnAuthenticationStateChanged()
 {
     AuthenticationStateChanged?.Invoke();
 }