/Aurora/Modules/Web/html/webprofile/index.cs

https://bitbucket.org/VirtualReality/software-testing · C# · 180 lines · 159 code · 18 blank · 3 comment · 27 complexity · aaf7762fc913c23b64f96519c4be0e47 MD5 · raw file

  1. using Aurora.Framework;
  2. using Aurora.Framework.DatabaseInterfaces;
  3. using Aurora.Framework.Modules;
  4. using Aurora.Framework.Servers.HttpServer;
  5. using Aurora.Framework.Servers.HttpServer.Implementation;
  6. using Aurora.Framework.Services;
  7. using Aurora.Framework.Services.ClassHelpers.Profile;
  8. using Aurora.Framework.Utilities;
  9. using OpenMetaverse;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Linq;
  13. namespace Aurora.Modules.Web
  14. {
  15. public class AgentInfoPage : IWebInterfacePage
  16. {
  17. public string[] FilePath
  18. {
  19. get
  20. {
  21. return new[]
  22. {
  23. "html/webprofile/index.html",
  24. "html/webprofile/base.html",
  25. "html/webprofile/"
  26. };
  27. }
  28. }
  29. public bool RequiresAuthentication
  30. {
  31. get { return false; }
  32. }
  33. public bool RequiresAdminAuthentication
  34. {
  35. get { return false; }
  36. }
  37. public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
  38. OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
  39. ITranslator translator, out string response)
  40. {
  41. response = null;
  42. var vars = new Dictionary<string, object>();
  43. string username = filename.Split('/').LastOrDefault();
  44. UserAccount account = null;
  45. if (httpRequest.Query.ContainsKey("userid"))
  46. {
  47. string userid = httpRequest.Query["userid"].ToString();
  48. account = webInterface.Registry.RequestModuleInterface<IUserAccountService>().
  49. GetUserAccount(null, UUID.Parse(userid));
  50. }
  51. else if (httpRequest.Query.ContainsKey("name"))
  52. {
  53. string name = httpRequest.Query.ContainsKey("name") ? httpRequest.Query["name"].ToString() : username;
  54. name = name.Replace('.', ' ');
  55. name = name.Replace("%20", " ");
  56. account = webInterface.Registry.RequestModuleInterface<IUserAccountService>().
  57. GetUserAccount(null, name);
  58. }
  59. else
  60. {
  61. username = username.Replace("%20", " ");
  62. webInterface.Redirect(httpResponse, "/webprofile/?name=" + username);
  63. return vars;
  64. }
  65. if (account == null)
  66. return vars;
  67. vars.Add("UserName", account.Name);
  68. vars.Add("UserBorn", Util.ToDateTime(account.Created).ToShortDateString());
  69. vars.Add("UserType", account.UserTitle == "" ? "Resident" : account.UserTitle);
  70. IUserProfileInfo profile = Framework.Utilities.DataManager.RequestPlugin<IProfileConnector>().
  71. GetUserProfile(account.PrincipalID);
  72. if (profile != null)
  73. {
  74. if (profile.Partner != UUID.Zero)
  75. {
  76. account = webInterface.Registry.RequestModuleInterface<IUserAccountService>().
  77. GetUserAccount(null, profile.Partner);
  78. vars.Add("UserPartner", account.Name);
  79. }
  80. else
  81. vars.Add("UserPartner", "No partner");
  82. vars.Add("UserAboutMe", profile.AboutText == "" ? "Nothing here" : profile.AboutText);
  83. string url = "../images/icons/no_picture.jpg";
  84. IWebHttpTextureService webhttpService =
  85. webInterface.Registry.RequestModuleInterface<IWebHttpTextureService>();
  86. if (webhttpService != null && profile.Image != UUID.Zero)
  87. url = webhttpService.GetTextureURL(profile.Image);
  88. vars.Add("UserPictureURL", url);
  89. }
  90. UserAccount ourAccount = Authenticator.GetAuthentication(httpRequest);
  91. if (ourAccount != null)
  92. {
  93. IFriendsService friendsService = webInterface.Registry.RequestModuleInterface<IFriendsService>();
  94. var friends = friendsService.GetFriends(account.PrincipalID);
  95. UUID friendID = UUID.Zero;
  96. if (friends.Any(f => UUID.TryParse(f.Friend, out friendID) && friendID == ourAccount.PrincipalID))
  97. {
  98. IAgentInfoService agentInfoService =
  99. webInterface.Registry.RequestModuleInterface<IAgentInfoService>();
  100. IGridService gridService = webInterface.Registry.RequestModuleInterface<IGridService>();
  101. UserInfo ourInfo = agentInfoService.GetUserInfo(account.PrincipalID.ToString());
  102. if (ourInfo != null && ourInfo.IsOnline)
  103. vars.Add("OnlineLocation", gridService.GetRegionByUUID(null, ourInfo.CurrentRegionID).RegionName);
  104. vars.Add("UserIsOnline", ourInfo != null && ourInfo.IsOnline);
  105. vars.Add("IsOnline",
  106. ourInfo != null && ourInfo.IsOnline
  107. ? translator.GetTranslatedString("Online")
  108. : translator.GetTranslatedString("Offline"));
  109. }
  110. else
  111. {
  112. vars.Add("OnlineLocation", "");
  113. vars.Add("UserIsOnline", false);
  114. vars.Add("IsOnline", translator.GetTranslatedString("Offline"));
  115. }
  116. }
  117. else
  118. {
  119. vars.Add("OnlineLocation", "");
  120. vars.Add("UserIsOnline", false);
  121. vars.Add("IsOnline", translator.GetTranslatedString("Offline"));
  122. }
  123. // Menu Profile
  124. vars.Add("MenuProfileTitle", translator.GetTranslatedString("MenuProfileTitle"));
  125. vars.Add("MenuGroupTitle", translator.GetTranslatedString("MenuGroupTitle"));
  126. vars.Add("MenuPicksTitle", translator.GetTranslatedString("MenuPicksTitle"));
  127. vars.Add("UserProfileFor", translator.GetTranslatedString("UserProfileFor"));
  128. vars.Add("ResidentSince", translator.GetTranslatedString("ResidentSince"));
  129. vars.Add("AccountType", translator.GetTranslatedString("AccountType"));
  130. vars.Add("PartnersName", translator.GetTranslatedString("PartnersName"));
  131. vars.Add("AboutMe", translator.GetTranslatedString("AboutMe"));
  132. vars.Add("IsOnlineText", translator.GetTranslatedString("IsOnlineText"));
  133. vars.Add("OnlineLocationText", translator.GetTranslatedString("OnlineLocationText"));
  134. // Style Switcher
  135. vars.Add("styles1", translator.GetTranslatedString("styles1"));
  136. vars.Add("styles2", translator.GetTranslatedString("styles2"));
  137. vars.Add("styles3", translator.GetTranslatedString("styles3"));
  138. vars.Add("styles4", translator.GetTranslatedString("styles4"));
  139. vars.Add("styles5", translator.GetTranslatedString("styles5"));
  140. vars.Add("StyleSwitcherStylesText", translator.GetTranslatedString("StyleSwitcherStylesText"));
  141. vars.Add("StyleSwitcherLanguagesText", translator.GetTranslatedString("StyleSwitcherLanguagesText"));
  142. vars.Add("StyleSwitcherChoiceText", translator.GetTranslatedString("StyleSwitcherChoiceText"));
  143. // Language Switcher
  144. vars.Add("en", translator.GetTranslatedString("en"));
  145. vars.Add("fr", translator.GetTranslatedString("fr"));
  146. vars.Add("de", translator.GetTranslatedString("de"));
  147. vars.Add("it", translator.GetTranslatedString("it"));
  148. vars.Add("es", translator.GetTranslatedString("es"));
  149. IGenericsConnector generics = Framework.Utilities.DataManager.RequestPlugin<IGenericsConnector>();
  150. var settings = generics.GetGeneric<GridSettings>(UUID.Zero, "WebSettings", "Settings");
  151. vars.Add("ShowLanguageTranslatorBar", !settings.HideLanguageTranslatorBar);
  152. vars.Add("ShowStyleBar", !settings.HideStyleBar);
  153. return vars;
  154. }
  155. public bool AttemptFindPage(string filename, ref OSHttpResponse httpResponse, out string text)
  156. {
  157. httpResponse.ContentType = "text/html";
  158. text = File.ReadAllText("html/webprofile/index.html");
  159. return true;
  160. }
  161. }
  162. }