Пример #1
0
        public async Task <bool> Login(UserLoginModel idata)
        {
            Message    = null;
            isLoggedIn = false;
            var response = await _api.PostCustom <UserInfoModel>($"core/Authorize", idata);

            if (response != null)
            {
                if (response.Status == 200)
                {
                    if (response.Data != null && response.Data.id != Guid.Empty && response.Data.Token != null && !response.Data.Token.token.isNOEOW())
                    {
                        await _sessionStorage.SetItemAsync(storageKey, response.Data);

                        ((ApiAuthenticationStateProvider)_authenStateProvider).MarkUserAsAuthenticated(response.Data.Token.token);
                        _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", response.Data.Token.token);
                        isLoggedIn = true;
                        KeepSession();
                    }
                    else
                    {
                        Message = response.Message.isNOEOW() ? "Cannot retrive data" : response.Message;
                    }
                }
                else
                {
                    Message = response.Message;
                }
            }
            else
            {
                Message = "Cannot provide login data";
            }
            return(isLoggedIn);
        }