public async Task <CurrentLoginInformations> GetUserInfo() { try { var response = await _httpClient.GetAsync($"{BaseUrl}/api/services/app/Session/GetCurrentLoginInformations"); if (response.IsSuccessStatusCode) { string data = await response.Content.ReadAsStringAsync(); var currentInfo = JsonConvert.DeserializeObject <AjaxResponse <CurrentLoginInformations> >(data); if (currentInfo != null && currentInfo.Success) { CurrentLoginInformations info = currentInfo.Result; if (info != null) { var jUser = info.User; if (jUser != null) { currentUserInfo.Email = jUser.EmailAddress; currentUserInfo.Username = jUser.UserName; } } currentUserInfo.Info = info; return(info); } } } catch { } await Task.CompletedTask; return(default(CurrentLoginInformations)); }
public async Task <CurrentUserInfo> GetUserInfoAsync() { try { var response = await _httpClient.GetAsync($"{BaseUrl}/api/services/app/Session/GetCurrentLoginInformations"); if (response.IsSuccessStatusCode) { string data = await response.Content.ReadAsStringAsync(); var currentInfo = JsonConvert.DeserializeObject <AjaxResponse <CurrentLoginInformations> >(data); if (currentInfo != null && currentInfo.Success) { CurrentLoginInformations info = currentInfo.Result; if (info != null) { var jUser = info.User; if (jUser != null) { _appContext.CurrentUserInfo.Email = jUser.EmailAddress; _appContext.CurrentUserInfo.Username = jUser.UserName; } } _appContext.CurrentUserInfo.Info = info; } } //var roleResponse = await _httpClient.GetAsync($"{BaseUrl}/api/services/app/User/GetRoles"); //if (roleResponse.IsSuccessStatusCode) //{ // string data = await roleResponse.Content.ReadAsStringAsync(); // //var roleInfo = JsonConvert.DeserializeObject<AjaxResponse<ListResultDto<RoleDto>>>(data); // //if (roleInfo != null && roleInfo.Success) // //{ // // var roles = roleInfo.Result; // // currentUserInfo.Roles = new List<RoleDto>(); // // currentUserInfo.Roles.AddRange(roles.Items); // //} //} } catch (Exception e) { throw; } await Task.CompletedTask; return(_appContext.CurrentUserInfo); }
public CurrentUserInfo GetUserInfo() { try { var response = _httpClient.GetAsync($"{BaseUrl}/api/services/app/Session/GetCurrentLoginInformations").GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { string data = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); var currentInfo = JsonConvert.DeserializeObject <AjaxResponse <CurrentLoginInformations> >(data); if (currentInfo != null && currentInfo.Success) { CurrentLoginInformations info = currentInfo.Result; if (info != null) { var jUser = info.User; if (jUser != null) { _appContext.CurrentUserInfo.Email = jUser.EmailAddress; _appContext.CurrentUserInfo.Username = jUser.UserName; _appContext.CurrentUserInfo.Surname = jUser.Surname; _appContext.CurrentUserInfo.Name = jUser.Name; //currentUserInfo.Id = jUser.Id; } } _appContext.CurrentUserInfo.Info = info; } } var roleResponse = _httpClient.GetAsync($"{BaseUrl}/api/services/app/User/GetRoles").GetAwaiter().GetResult(); if (roleResponse.IsSuccessStatusCode) { string data = roleResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult(); var roleInfo = JsonConvert.DeserializeObject <AjaxResponse <ListResultDto <RoleDto> > >(data); if (roleInfo != null && roleInfo.Success) { var roles = roleInfo.Result; _appContext.CurrentUserInfo.Roles = new List <RoleDto>(); _appContext.CurrentUserInfo.Roles.AddRange(roles.Items); } } } catch (Exception e) { throw; } return(_appContext.CurrentUserInfo); }
protected virtual void LoadAppHeaders(CurrentLoginInformations loginInformations) { var referer = new StringValues(); var origin = new StringValues(); var host = new StringValues(); _httpContextAccessor.HttpContext.Request.Headers.TryGetValue("Referer", out referer); _httpContextAccessor.HttpContext.Request.Headers.TryGetValue("Origin", out origin); _httpContextAccessor.HttpContext.Request.Headers.TryGetValue("Host", out host); loginInformations.Headers = new AppHeaders() { Referer = referer, Origin = origin, Host = host, ClientRootAddress = _appSettings.Value.ClientRootAddress }; }
public async Task <CurrentLoginInformations> CurrentLoginInformations() { var output = new CurrentLoginInformations { Application = new ApplicationInfoDto { Version = AppVersionHelper.Version.ToString(), ReleaseDate = AppVersionHelper.ReleaseDate, Features = new Dictionary <string, bool> { { "SignalR", SignalRFeature.IsAvailable } } } }; LoadAppHeaders(output); if (_abpSession.UserId.HasValue) { output.User = await GetCurrentUserAsync(); } return(output); }