protected void CopyLanguageToNationalityOfNewUsers() { string roleName = "Registered Users"; Security.Roles.RoleController roleCtlr = new Security.Roles.RoleController(); ArrayList objUserRoles = roleCtlr.GetUsersByRoleName(0, roleName); foreach (Entities.Users.UserInfo user in objUserRoles) { string nat = user.Profile.GetPropertyValue("OurSpaceNationality"); if (user.Profile.GetPropertyValue("OurSpaceNationality") == null) { string lang = user.Profile.GetPropertyValue("PreferredLocale"); user.Profile.SetProfileProperty("OurSpaceNationality", lang); ProfileController.UpdateUserProfile(user); } } }
protected void SetNationalityFromIP() { string roleName = "Registered Users"; Security.Roles.RoleController roleCtlr = new Security.Roles.RoleController(); ArrayList objUserRoles = roleCtlr.GetUsersByRoleName(PortalId, roleName); foreach (Entities.Users.UserInfo user in objUserRoles) { string CONNECTION_STRING = DotNetNuke.Common.Utilities.Config.GetConnectionString(); SqlConnection conn = new SqlConnection(CONNECTION_STRING); // Checking if nationality has been set from IP before conn.Open(); SqlDataReader readerUserAlreadyDone = SqlHelper.ExecuteReader(conn, CommandType.Text, "SELECT * FROM OURSPACE_LOG WHERE userId = " + user.UserID); if (!readerUserAlreadyDone.HasRows) { SqlConnection conn2 = new SqlConnection(CONNECTION_STRING); conn2.Open(); SqlDataReader reader = SqlHelper.ExecuteReader(conn2, CommandType.Text, "SELECT * FROM Users WHERE Userid = " + user.UserID); if (reader.Read()) { string ip = reader["LastIPAddress"].ToString(); Ourspace_Utilities.View.LocationInfo location = Ourspace_Utilities.View.GeoLocationService.GetLocationInfo(ip); if (location != null) { string countryCode = GetCountryFromCountryName(location.CountryName); if (countryCode != "UNKNOWN") { user.Profile.SetProfileProperty("OurSpaceNationality", countryCode); ProfileController.UpdateUserProfile(user); } lblCountry.Text += user.UserID + " " + ip + " " + location.CountryName + " " + countryCode + "<br/>"; SqlConnection conn3 = new SqlConnection(CONNECTION_STRING); conn3.Open(); SqlHelper.ExecuteNonQuery(conn3, CommandType.Text, "INSERT INTO OURSPACE_LOG VALUES ('" + user.UserID + " " + ip + " " + location.CountryName + " " + countryCode + "', " + user.UserID + ")"); conn3.Close(); } } conn2.Close(); } conn.Close(); } }