PageRenderTime 179ms CodeModel.GetById 23ms app.highlight 148ms RepoModel.GetById 1ms app.codeStats 0ms

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