public async Task <IActionResult> GetLoggedInUserDetails() { LoggedInUserDetailsViewModel loggedInUserDetailsViewModel = await GetUserDetailsFromCookies(); UserAccountModel userAccountModel = _mapper.Map <UserAccountModel>(loggedInUserDetailsViewModel); var userLoginDetails = this._IUserAccountService.GetUserDetailsForLastLogin(userAccountModel); loggedInUserDetailsViewModel.LastLoggedInUserDetailsViewModel = new LoggedInUserDetailsViewModel(); loggedInUserDetailsViewModel.CurrentLoggedInUserDetailsViewModel = new LoggedInUserDetailsViewModel(); IpPropertiesModal ipPropertiesModal = new IpPropertiesModal(); string ipAddress = this._IHttpContextAccessor .HttpContext.Connection.RemoteIpAddress .ToString(); ipPropertiesModal = this._IAppAnalyticsService.GetIpAddressDetails(ipAddress); loggedInUserDetailsViewModel.LastLoggedInUserDetailsViewModel = _mapper.Map <LoggedInUserDetailsViewModel>(userLoginDetails.LastSessionDetails); loggedInUserDetailsViewModel.CurrentLoggedInUserDetailsViewModel = _mapper.Map <LoggedInUserDetailsViewModel>(userLoginDetails.CurrentSessionDetails); string partialViewHtml = await this.RenderViewAsync("_LoggedInUserDetails", loggedInUserDetailsViewModel, true); return(Json(partialViewHtml)); }
public override async Task OnDisconnectedAsync(Exception exception) { string userName = Context.User.Identity.Name; string connectionId = Context.ConnectionId; ActiveConnections.ActiveUsers.Remove(userName); ActiveConnections.ActiveSessions.Remove(Context.ConnectionId); ActiveSessions activeSessions = new ActiveSessions(); activeSessions = ActiveConnections.ActiveSessionsList.Where(x => x.ConnectionId == Context.ConnectionId).FirstOrDefault(); ActiveConnections.ActiveSessionsList.Remove(activeSessions); if (!ActiveConnections.ActiveSessionsList.Any(w => w.UserId == activeSessions.UserId) && activeSessions.UserId > 0) { IpPropertiesModal ipAddressDetails = new IpPropertiesModal(); ipAddressDetails.UserId = activeSessions.UserId; ipAddressDetails.IpAddress = activeSessions.IpAddress; ipAddressDetails.SessionDisconnectedOn = DateTime.Now; ipAddressDetails.CookieUniqueId = activeSessions.CookieUniqueId; _IAppAnalyticsService.UpdatedUserDisConnectionTracking(ipAddressDetails); } await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users"); await base.OnDisconnectedAsync(exception); }
public IpPropertiesModal GetCountryDetailsByIP(string ipAddress) { IpPropertiesModal ipProperties = new IpPropertiesModal(); try { string ipResponse = IPRequestHelper("http://ip-api.com/xml/" + ipAddress); using (TextReader sr = new StringReader(ipResponse)) { using (System.Data.DataSet dataBase = new System.Data.DataSet()) { dataBase.ReadXml(sr); ipProperties.Status = dataBase.Tables[0].Rows[0][0].ToString(); ipProperties.Country = dataBase.Tables[0].Rows[0][1].ToString(); ipProperties.CountryCode = dataBase.Tables[0].Rows[0][2].ToString(); ipProperties.Region = dataBase.Tables[0].Rows[0][3].ToString(); ipProperties.RegionName = dataBase.Tables[0].Rows[0][4].ToString(); ipProperties.City = dataBase.Tables[0].Rows[0][5].ToString(); ipProperties.Zip = dataBase.Tables[0].Rows[0][6].ToString(); ipProperties.Lat = dataBase.Tables[0].Rows[0][7].ToString(); ipProperties.Lon = dataBase.Tables[0].Rows[0][8].ToString(); ipProperties.TimeZone = dataBase.Tables[0].Rows[0][9].ToString(); ipProperties.ISP = dataBase.Tables[0].Rows[0][10].ToString(); ipProperties.ORG = dataBase.Tables[0].Rows[0][11].ToString(); ipProperties.ISPDetails = dataBase.Tables[0].Rows[0][12].ToString(); ipProperties.Query = dataBase.Tables[0].Rows[0][13].ToString(); } } } catch (Exception) { } return(ipProperties); }
public (IpPropertiesModal LastSessionDetails, IpPropertiesModal CurrentSessionDetails) GetUserDetailsForLastLogin(UserAccountModel userAccountModel) { var resultSet = this._IUserAccountRepository.GetUserDetailsForLastLogin(userAccountModel); IpPropertiesModal lastSessionDetails = new IpPropertiesModal(); lastSessionDetails = (IpPropertiesModal)resultSet.Set1.FirstOrDefault(); IpPropertiesModal currentSessionDetails = (IpPropertiesModal)resultSet.Set2.FirstOrDefault(); return(lastSessionDetails, currentSessionDetails); }
public Task <WeatherModel> GetCurrectWeatherDetails(string userIpAddress) { IpPropertiesModal ipPropertiesModal = new IpPropertiesModal(); WeatherModel weatherModel = new WeatherModel(); ipPropertiesModal = _IIPRequestDetails.GetCountryDetailsByIP(userIpAddress); var getdashBoardRow1DetailsTask = Task.Run(() => _IWeatherForecast.GetWeatherForecastByCoOrdinates( ipPropertiesModal.Lat , ipPropertiesModal.Lon) ); getdashBoardRow1DetailsTask.Wait(); getdashBoardRow1DetailsTask.Result.CurrentCityName = ipPropertiesModal.City; getdashBoardRow1DetailsTask.Result.CurrentCountryName = ipPropertiesModal.CountryCode + ", " + ipPropertiesModal.Country; return(getdashBoardRow1DetailsTask); }
public (UserAccountModel UserAccount, List <UserRolesModel> UserRoles) ValidateUserLoginAndCredential(UserAccountModel userAccountModel) { bool isValidUser = false; Guid cookieUniqueId; cookieUniqueId = Guid.NewGuid(); UserAccountModel getUserAccount = new UserAccountModel(); List <UserRolesModel> userRoles = new List <UserRolesModel>(); IpPropertiesModal ipPropertiesModal = new IpPropertiesModal(); getUserAccount.CookieUniqueId = cookieUniqueId; if (userAccountModel.UserIpAddress == "::1") { userAccountModel.UserIpAddress = Faker.Internet.IPv4(); } try { var resultSet = this._IUserAccountRepository.GetUserDetailsForLogin(userAccountModel); ipPropertiesModal = _IIPRequestDetails.GetCountryDetailsByIP(userAccountModel.UserIpAddress); ipPropertiesModal.IpAddress = userAccountModel.UserIpAddress; ipPropertiesModal.CreatedByUserName = userAccountModel.UserName; ipPropertiesModal.ModifiedByUserName = userAccountModel.UserName; ipPropertiesModal.UserName = userAccountModel.UserName; ipPropertiesModal.CreatedOn = DateTime.Now; ipPropertiesModal.ModifiedOn = DateTime.Now; ipPropertiesModal.CookieUniqueId = cookieUniqueId; if (resultSet.Set1 == null) { isValidUser = false; } else { getUserAccount = (UserAccountModel)resultSet.Set1.FirstOrDefault(); userRoles = resultSet.Set2.ToList(); userAccountModel.Password = DecryptStringAES(userAccountModel.CryptLoginPassword); string passwordConcated = userAccountModel.Password + getUserAccount.PasswordSalt; string generatedHashFromPassAndSalt = Hash.Create(HashType.SHA512, passwordConcated, string.Empty, false); if (String.Compare(generatedHashFromPassAndSalt, getUserAccount.PasswordHash) == 0) { isValidUser = true; } userAccountModel = getUserAccount; ipPropertiesModal.UserId = userAccountModel.UserId; ipPropertiesModal.CreatedBy = userAccountModel.UserId; } getUserAccount.IsLoginSuccess = isValidUser; ipPropertiesModal.IsLoginSuccess = isValidUser; var dbUpdateResult = _IAppAnalyticsRepository.SaveIpAddressDetailsOnLogin(ipPropertiesModal); } catch (Exception Ex) { var dbUpdateResult = _IAppAnalyticsRepository.SaveIpAddressDetailsOnLogin(ipPropertiesModal); } userAccountModel.CookieUniqueId = cookieUniqueId; return(userAccountModel, userRoles); }
public Int32 UpdatedUserDisConnectionTracking(IpPropertiesModal ipAddressDetails) { return(this._IAppAnalyticsRepository.UpdatedUserDisConnectionTracking(ipAddressDetails)); }