Example #1
0
        public async Task <SignInResult> PasswordSignInAsync(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException(nameof(userName));
            }

            if (password is null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (!_systemSetting.UserName.Equals(userName) || !_systemSetting.Password.Equals(password))
            {
                return(SignInResult.Failed);
            }

            try
            {
                var token = _jsonWebTokenService.GetJsonWebToken();



                await _localStorageService.SetItemAsync(STORAGE_KEY, token);

                NotifyAuthenticationStateChanged(Task.FromResult(new AuthenticationState(new ClaimsPrincipal())));
                return(SignInResult.Success);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(SignInResult.Failed);
            }
        }