Exemplo n.º 1
0
        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
            OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
            ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();

            string error = "";
            UUID userID = httpRequest.Query.ContainsKey("userid")
                            ? UUID.Parse(httpRequest.Query["userid"].ToString())
                            : UUID.Parse(requestParameters["userid"].ToString());

            IUserAccountService userService = webInterface.Registry.RequestModuleInterface<IUserAccountService>();
            var agentService = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>();
            UserAccount account = userService.GetUserAccount(null, userID);
            IAgentInfo agent = agentService.GetAgent(userID);

            if (agent == null)
                error = "No agent information is available";

            // Set user type
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitSetUserType")
            {

                string UserType = requestParameters ["UserType"].ToString ();
                int UserFlags = webInterface.UserTypeToUserFlags (UserType);

                // set the user account type
                account.UserFlags = UserFlags;
                userService.StoreUserAccount (account);

                if (agent != null)
                {
                    agent.OtherAgentInformation ["UserFlags"] = UserFlags;
                    agentService.UpdateAgent (agent);
                    response = "User has been updated.";
                } else
                    response = "Agent information is not available! Has the user logged in yet?";

                IProfileConnector profileData =
                    Framework.Utilities.DataManager.RequestPlugin<IProfileConnector>();
                if (profileData != null)
                {
                    IUserProfileInfo profile = profileData.GetUserProfile (userID);
                    if (profile == null)
                    {
                        profileData.CreateNewProfile (userID);
                        profile = profileData.GetUserProfile (userID);
                    }

                    profile.MembershipGroup = webInterface.UserFlagToType (UserFlags, webInterface.EnglishTranslator);    // membership is english
                    profileData.UpdateUserProfile (profile);
                }

                response = "User has been updated.";
                return null;
            }

            // Password change
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitPasswordChange")
            {
                string password = requestParameters["password"].ToString();
                string passwordconf = requestParameters["passwordconf"].ToString();

                if (password != passwordconf)
                    response = "Passwords do not match";
                else
                {
                    IAuthenticationService authService =
                        webInterface.Registry.RequestModuleInterface<IAuthenticationService>();
                    if (authService != null)
                        response = authService.SetPassword(userID, "UserAccount", password)
                                       ? "Successfully set password"
                                       : "Failed to set your password, try again later";
                    else
                        response = "No authentication service was available to change your password";
                }
                return null;
            }

            // Email change
            if (requestParameters.ContainsKey("Submit") &&
                     requestParameters["Submit"].ToString() == "SubmitEmailChange")
            {
                string email = requestParameters["email"].ToString();

                if (userService != null)
                {
                    account.Email = email;
                    userService.StoreUserAccount(account);
                    response = "Successfully updated email";
                }
                else
                    response = "No authentication service was available to change your password";
                return null;
            }

            // Delete user
            if (requestParameters.ContainsKey("Submit") &&
                     requestParameters["Submit"].ToString() == "SubmitDeleteUser")
            {
                string username = requestParameters["username"].ToString();
                response = "Deleted user successfully";
                if (username == account.Name)
                    userService.DeleteUser(account.PrincipalID, account.Name, "", false, false);
                else
                    response = "The user name did not match";
                return null;
            }

            // Temp Ban user
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitTempBanUser")
            {
                int timeDays = int.Parse(requestParameters["TimeDays"].ToString());
                int timeHours = int.Parse(requestParameters["TimeHours"].ToString());
                int timeMinutes = int.Parse(requestParameters["TimeMinutes"].ToString());

                if (agent != null)
                {
                    agent.Flags |= IAgentFlags.TempBan;
                    DateTime until = DateTime.Now.AddDays (timeDays).AddHours (timeHours).AddMinutes (timeMinutes);
                    agent.OtherAgentInformation ["TemperaryBanInfo"] = until;
                    agentService.UpdateAgent (agent);
                    response = "User has been banned.";
                } else
                    response = "Agent information is not available! Has the user logged in yet?";

                return null;
            }

            // Ban user
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitBanUser")
            {
                if( agent != null)
                {
                    agent.Flags |= IAgentFlags.PermBan;
                    agentService.UpdateAgent(agent);
                    response = "User has been banned.";
                } else
                    response = "Agent information is not available! Has the user logged in yet?";

                return null;
            }

            //UnBan user
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitUnbanUser")
            {

                if (agent != null)
                {
                    agent.Flags &= ~IAgentFlags.TempBan;
                    agent.Flags &= ~IAgentFlags.PermBan;
                    agent.OtherAgentInformation.Remove("TemperaryBanInfo");
                    agentService.UpdateAgent(agent);
                    response = "User has been unbanned.";
                } else
                    response = "Agent information is not available! Has the user logged in yet?";

                return null;
            }

            // Login as user
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitLoginAsUser")
            {
                Authenticator.ChangeAuthentication(httpRequest, account);
                webInterface.Redirect(httpResponse, "/");
                return vars;
            }

            // Kick user
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitKickUser")
            {
                string message = requestParameters["KickMessage"].ToString();
                IGridWideMessageModule messageModule =
                    webInterface.Registry.RequestModuleInterface<IGridWideMessageModule>();
                if (messageModule != null)
                    messageModule.KickUser(account.PrincipalID, message);
                response = "User has been kicked.";
                return null;
            }

            // Message user
            if (requestParameters.ContainsKey("Submit") &&
                requestParameters["Submit"].ToString() == "SubmitMessageUser")
            {
                string message = requestParameters["Message"].ToString();
                IGridWideMessageModule messageModule =
                    webInterface.Registry.RequestModuleInterface<IGridWideMessageModule>();
                if (messageModule != null)
                    messageModule.MessageUser(account.PrincipalID, message);
                response = "User has been sent the message.";
                return null;
            }

            // page variables
            string bannedUntil = "";
            bool userBanned = agent == null
                                  ? false
                                  : ((agent.Flags & IAgentFlags.PermBan) == IAgentFlags.PermBan ||
                                     (agent.Flags & IAgentFlags.TempBan) == IAgentFlags.TempBan);
            bool TempUserBanned = false;
            if (userBanned)
            {
                if ((agent.Flags & IAgentFlags.TempBan) == IAgentFlags.TempBan &&
                    agent.OtherAgentInformation["TemperaryBanInfo"].AsDate() < DateTime.Now.ToUniversalTime())
                {
                    userBanned = false;
                    agent.Flags &= ~IAgentFlags.TempBan;
                    agent.Flags &= ~IAgentFlags.PermBan;
                    agent.OtherAgentInformation.Remove("TemperaryBanInfo");
                    agentService.UpdateAgent(agent);
                }
                else
                {
                    DateTime bannedTime = agent.OtherAgentInformation["TemperaryBanInfo"].AsDate();
                    TempUserBanned = bannedTime != Util.UnixEpoch;
                    bannedUntil = string.Format("{0} {1}", bannedTime.ToShortDateString(), bannedTime.ToLongTimeString());
                }
            }
            bool userOnline = false;
            IAgentInfoService agentInfoService = webInterface.Registry.RequestModuleInterface<IAgentInfoService>();
            if (agentInfoService != null)
            {
                UserInfo info = agentInfoService.GetUserInfo(account.PrincipalID.ToString());
                userOnline = info != null ? info.IsOnline : false;
            }
            vars.Add("UserOnline", userOnline);
            vars.Add("NotUserBanned", !userBanned);
            vars.Add("UserBanned", userBanned);
            vars.Add("TempUserBanned", TempUserBanned);
            vars.Add("BannedUntil", bannedUntil);
            vars.Add("EmailValue", account.Email);
            vars.Add("UserID", account.PrincipalID);
            vars.Add("UserName", account.Name);
            vars.Add("ErrorMessage", error);
            vars.Add("ChangeUserInformationText", translator.GetTranslatedString("ChangeUserInformationText"));
            vars.Add("ChangePasswordText", translator.GetTranslatedString("ChangePasswordText"));
            vars.Add("NewPasswordText", translator.GetTranslatedString("NewPasswordText"));
            vars.Add("NewPasswordConfirmationText", translator.GetTranslatedString("NewPasswordConfirmationText"));
            vars.Add("ChangeEmailText", translator.GetTranslatedString("ChangeEmailText"));
            vars.Add("NewEmailText", translator.GetTranslatedString("NewEmailText"));
            vars.Add("UserNameText", translator.GetTranslatedString("UserNameText"));
            vars.Add("PasswordText", translator.GetTranslatedString("PasswordText"));
            vars.Add("DeleteUserText", translator.GetTranslatedString("DeleteUserText"));
            vars.Add("DeleteText", translator.GetTranslatedString("DeleteText"));
            vars.Add("DeleteUserInfoText", translator.GetTranslatedString("DeleteUserInfoText"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));
            vars.Add("Login", translator.GetTranslatedString("Login"));
            vars.Add("TypeUserNameToConfirm", translator.GetTranslatedString("TypeUserNameToConfirm"));

            vars.Add("AdminUserTypeInfoText",translator.GetTranslatedString("AdminUserTypeInfoText"));
            vars.Add("AdminSetUserTypeText", translator.GetTranslatedString("UserTypeText"));

            vars.Add("AdminLoginInAsUserText", translator.GetTranslatedString("AdminLoginInAsUserText"));
            vars.Add("AdminLoginInAsUserInfoText", translator.GetTranslatedString("AdminLoginInAsUserInfoText"));
            vars.Add("AdminDeleteUserText", translator.GetTranslatedString("AdminDeleteUserText"));
            vars.Add("AdminDeleteUserInfoText", translator.GetTranslatedString("AdminDeleteUserInfoText"));
            vars.Add("AdminUnbanUserText", translator.GetTranslatedString("AdminUnbanUserText"));
            vars.Add("AdminTempBanUserText", translator.GetTranslatedString("AdminTempBanUserText"));
            vars.Add("AdminTempBanUserInfoText", translator.GetTranslatedString("AdminTempBanUserInfoText"));
            vars.Add("AdminBanUserText", translator.GetTranslatedString("AdminBanUserText"));
            vars.Add("AdminBanUserInfoText", translator.GetTranslatedString("AdminBanUserInfoText"));
            vars.Add("BanText", translator.GetTranslatedString("BanText"));
            vars.Add("UnbanText", translator.GetTranslatedString("UnbanText"));
            vars.Add("TimeUntilUnbannedText", translator.GetTranslatedString("TimeUntilUnbannedText"));
            vars.Add("EdittingText", translator.GetTranslatedString("EdittingText"));
            vars.Add("BannedUntilText", translator.GetTranslatedString("BannedUntilText"));

            vars.Add("KickAUserInfoText", translator.GetTranslatedString("KickAUserInfoText"));
            vars.Add("KickAUserText", translator.GetTranslatedString("KickAUserText"));
            vars.Add("KickMessageText", translator.GetTranslatedString("KickMessageText"));
            vars.Add("KickUserText", translator.GetTranslatedString("KickUserText"));

            vars.Add("MessageAUserText", translator.GetTranslatedString("MessageAUserText"));
            vars.Add("MessageAUserInfoText", translator.GetTranslatedString("MessageAUserInfoText"));
            vars.Add("MessageUserText", translator.GetTranslatedString("MessageUserText"));

            List<Dictionary<string, object>> daysArgs = new List<Dictionary<string, object>>();
            for (int i = 0; i <= 100; i++)
                daysArgs.Add(new Dictionary<string, object> {{"Value", i}});

            List<Dictionary<string, object>> hoursArgs = new List<Dictionary<string, object>>();
            for (int i = 0; i <= 23; i++)
                hoursArgs.Add(new Dictionary<string, object> {{"Value", i}});

            List<Dictionary<string, object>> minutesArgs = new List<Dictionary<string, object>>();
            for (int i = 0; i <= 59; i++)
                minutesArgs.Add(new Dictionary<string, object> {{"Value", i}});

            vars.Add("Days", daysArgs);
            vars.Add("Hours", hoursArgs);
            vars.Add("Minutes", minutesArgs);
            vars.Add("DaysText", translator.GetTranslatedString("DaysText"));
            vars.Add("HoursText", translator.GetTranslatedString("HoursText"));
            vars.Add("MinutesText", translator.GetTranslatedString("MinutesText"));

            vars.Add("UserType", webInterface.UserTypeArgs(translator));

            return vars;
        }
Exemplo n.º 2
0
        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
            OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
            ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();
            var settings = webInterface.GetWebUISettings();

            bool adminUser = Authenticator.CheckAdminAuthentication(httpRequest, Constants.USER_GOD_CUSTOMER_SERVICE);
            bool allowRegistration = settings.WebRegistration;
            bool anonymousLogins;

            // allow configuration to override the web settings
            IConfig config = webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs ["LoginService"];
            if (config != null)
            {
                anonymousLogins = config.GetBoolean ("AllowAnonymousLogin", allowRegistration);
                allowRegistration = (allowRegistration || anonymousLogins);
            }

            if (!adminUser && !allowRegistration)
            {
                vars.Add("ErrorMessage", "");
                vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
                vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
                vars.Add("Registrations", false);
                vars.Add("NoRegistrations", true);
                return vars;
             }

            if (requestParameters.ContainsKey("Submit"))
            {
                string AvatarName = requestParameters["AvatarName"].ToString();
                string AvatarPassword = requestParameters["AvatarPassword"].ToString();
                string AvatarPasswordCheck = requestParameters["AvatarPassword2"].ToString();
                string FirstName = requestParameters["FirstName"].ToString();
                string LastName = requestParameters["LastName"].ToString();
                //removed - greythane - deemed not used
                //string UserAddress = requestParameters["UserAddress"].ToString();
                //string UserZip = requestParameters["UserZip"].ToString();
                string UserCity = requestParameters["UserCity"].ToString();
                string UserEmail = requestParameters["UserEmail"].ToString();
                string UserHomeRegion = requestParameters["UserHomeRegion"].ToString();
                string UserDOBMonth = requestParameters["UserDOBMonth"].ToString();
                string UserDOBDay = requestParameters["UserDOBDay"].ToString();
                string UserDOBYear = requestParameters["UserDOBYear"].ToString();
                string AvatarArchive = requestParameters.ContainsKey("AvatarArchive")
                                           ? requestParameters["AvatarArchive"].ToString()
                                           : "";
                bool ToSAccept = requestParameters.ContainsKey("ToSAccept") &&
                                 requestParameters["ToSAccept"].ToString() == "Accepted";

                string UserType = requestParameters.ContainsKey("UserType")         // only admins can set membership
                    ? requestParameters ["UserType"].ToString ()
                    : "Resident";

                // revise UserDOBMonth to a number
                UserDOBMonth = ShortMonthToNumber(UserDOBMonth);

                // revise Type flags
                int UserFlags = webInterface.UserTypeToUserFlags (UserType);

                // a bit of idiot proofing
                if (AvatarName == "")  {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarNameError") + "</h3>";
                    return null;
                }
                if ( (AvatarPassword == "") || (AvatarPassword != AvatarPasswordCheck) )
                {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarPasswordError") + "</h3>";
                    return null;
                }
                if (UserEmail == "")
                {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarEmailError") + "</h3>";
                    return null;
                }

                // Thish -  Only one space is allowed in the name to seperate First and Last of the avatar name
                if (AvatarName.Split (' ').Length != 2)
                {
                    response = "<h3>" + translator.GetTranslatedString("AvatarNameSpacingError") + "</h3>";
                    return null;
                }

                // so far so good...
                if (ToSAccept)
                {
                    AvatarPassword = Util.Md5Hash(AvatarPassword);

                    IUserAccountService accountService =
                        webInterface.Registry.RequestModuleInterface<IUserAccountService>();
                    UUID userID = UUID.Random();
                    string error = accountService.CreateUser(userID, settings.DefaultScopeID, AvatarName, AvatarPassword,
                                                             UserEmail);
                    if (error == "")
                    {
                        // set the user account type
                        UserAccount account = accountService.GetUserAccount (null, userID);
                        account.UserFlags = UserFlags;
                        accountService.StoreUserAccount (account);

                        // create and save agent info
                        IAgentConnector con = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector> ();
                        con.CreateNewAgent (userID);
                        IAgentInfo agent = con.GetAgent (userID);
                        agent.OtherAgentInformation ["RLFirstName"] = FirstName;
                        agent.OtherAgentInformation ["RLLastName"] = LastName;
                        //agent.OtherAgentInformation ["RLAddress"] = UserAddress;
                        agent.OtherAgentInformation ["RLCity"] = UserCity;
                        //agent.OtherAgentInformation ["RLZip"] = UserZip;
                        agent.OtherAgentInformation ["UserDOBMonth"] = UserDOBMonth;
                        agent.OtherAgentInformation ["UserDOBDay"] = UserDOBDay;
                        agent.OtherAgentInformation ["UserDOBYear"] = UserDOBYear;
                        agent.OtherAgentInformation ["UserFlags"] = UserFlags;
                        /*if (activationRequired)
                        {
                            UUID activationToken = UUID.Random();
                            agent.OtherAgentInformation["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + PasswordHash);
                            resp["WebUIActivationToken"] = activationToken;
                        }*/
                        con.UpdateAgent (agent);

                        // create user profile details
                        IProfileConnector profileData =
                            Framework.Utilities.DataManager.RequestPlugin<IProfileConnector> ();
                        if (profileData != null)
                        {
                            IUserProfileInfo profile = profileData.GetUserProfile (userID);
                            if (profile == null)
                            {
                                profileData.CreateNewProfile (userID);
                                profile = profileData.GetUserProfile (userID);
                            }

                            if (AvatarArchive != "")
                            {
                                profile.AArchiveName = AvatarArchive;

                                List<AvatarArchive> avarchives = webInterface.Registry.RequestModuleInterface<IAvatarAppearanceArchiver>().GetAvatarArchives();
                                UUID snapshotUUID = UUID.Zero;
                                foreach (var archive in avarchives)
                                    if (archive.FolderName == AvatarArchive)
                                        snapshotUUID = archive.Snapshot;

                                if (snapshotUUID != UUID.Zero)
                                    profile.Image = snapshotUUID;
                            }
                            profile.MembershipGroup = webInterface.UserFlagToType (UserFlags, webInterface.EnglishTranslator);    // membership is english
                            profile.IsNewUser = true;
                            profileData.UpdateUserProfile (profile);
                        }

                        IAgentInfoService agentInfoService = webInterface.Registry.RequestModuleInterface<IAgentInfoService> ();
                        Vector3 position = new Vector3 (128, 128, 25);
                        Vector3 lookAt = new Vector3 (0, 0, 22);

                        if (agentInfoService != null)
                            agentInfoService.SetHomePosition (userID.ToString (), (UUID) UserHomeRegion, position, lookAt);

                        vars.Add ("ErrorMessage", "Successfully created account, redirecting to main page");
                        response = "<h3>Successfully created account, redirecting to main page</h3>" +
                        "<script language=\"javascript\">" +
                        "setTimeout(function() {window.location.href = \"index.html\";}, 3000);" +
                        "</script>";
                    } else
                    {
                        vars.Add ("ErrorMessage", "<h3>" + error + "</h3>");
                        response = "<h3>" + error + "</h3>";
                    }
                }
                else
                    response = "<h3>You did not accept the Terms of Service agreement.</h3>";
                return null;
            }

            List<Dictionary<string, object>> daysArgs = new List<Dictionary<string, object>>();
            for (int i = 1; i <= 31; i++)
                daysArgs.Add(new Dictionary<string, object> {{"Value", i}});

            List<Dictionary<string, object>> monthsArgs = new List<Dictionary<string, object>>();
            //for (int i = 1; i <= 12; i++)
            //    monthsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jan_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Feb_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Mar_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Apr_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("May_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jun_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jul_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Aug_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Sep_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Oct_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Nov_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Dec_Short")}});

            List<Dictionary<string, object>> yearsArgs = new List<Dictionary<string, object>>();
            for (int i = 1940; i <= 2013; i++)
                yearsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            vars.Add("Days", daysArgs);
            vars.Add("Months", monthsArgs);
            vars.Add("Years", yearsArgs);

            var sortBy = new Dictionary<string, bool>();
            sortBy.Add("RegionName", true);

            var RegionListVars = new List<Dictionary<string, object>>();
            var regions = Framework.Utilities.DataManager.RequestPlugin<IRegionData>().Get((RegionFlags) 0,
                RegionFlags.Hyperlink |
                RegionFlags.Foreign |
                RegionFlags.Hidden,
                null, null, sortBy);
            foreach (var region in regions)
            {

                RegionListVars.Add (new Dictionary<string, object> {
                    { "RegionName", region.RegionName },
                    { "RegionUUID", region.RegionID }
                });
            }

            vars.Add("RegionList", RegionListVars);
            vars.Add("UserHomeRegionText", translator.GetTranslatedString("UserHomeRegionText"));

            vars.Add("UserTypeText", translator.GetTranslatedString("UserTypeText"));
            vars.Add("UserType", webInterface.UserTypeArgs(translator)) ;

            List<AvatarArchive> archives = webInterface.Registry.RequestModuleInterface<IAvatarAppearanceArchiver>().GetAvatarArchives();

            List<Dictionary<string, object>> avatarArchives = new List<Dictionary<string, object>>();
            IWebHttpTextureService webTextureService = webInterface.Registry.
                                                                    RequestModuleInterface<IWebHttpTextureService>();
            foreach (var archive in archives)
                avatarArchives.Add(new Dictionary<string, object>
                                       {
                                           {"AvatarArchiveName", archive.FolderName },
                                           {"AvatarArchiveSnapshotID", archive.Snapshot},
                                           {
                                               "AvatarArchiveSnapshotURL",
                                               webTextureService.GetTextureURL(archive.Snapshot)
                                           }
                                       });

            vars.Add("AvatarArchive", avatarArchives);

            IConfig loginServerConfig =
                webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs["LoginService"];
            string tosLocation = "";
            if (loginServerConfig != null && loginServerConfig.GetBoolean("UseTermsOfServiceOnFirstLogin", false))
            {
                tosLocation = loginServerConfig.GetString("FileNameOfTOS", "");
                tosLocation = PathHelpers.VerifyReadFile (tosLocation,  ".txt", Constants.DEFAULT_DATA_DIR);
            }
            string ToS = "There are no Terms of Service currently. This may be changed at any point in the future.";

            if (tosLocation != "")
            {
                System.IO.StreamReader reader =
                    new System.IO.StreamReader(System.IO.Path.Combine(Environment.CurrentDirectory, tosLocation));
                ToS = reader.ReadToEnd();
                reader.Close();
            }

            // check for user name seed
            string[] m_userNameSeed = null;
            if (loginServerConfig != null)
            {
                string userNameSeed = loginServerConfig.GetString ("UserNameSeed", "");
                if (userNameSeed != "")
                    m_userNameSeed = userNameSeed.Split (',');
            }

            Utilities.MarkovNameGenerator ufNames = new Utilities.MarkovNameGenerator ();
            Utilities.MarkovNameGenerator ulNames = new Utilities.MarkovNameGenerator ();
            string[] nameSeed = m_userNameSeed == null ? Utilities.UserNames : m_userNameSeed;

            string firstName = ufNames.FirstName (nameSeed, 3, 4);
            string lastName = ulNames.FirstName (nameSeed, 5, 6);
            string enteredName = firstName + " " + lastName;

            vars.Add("AvatarName",enteredName);
            vars.Add("ToSMessage", ToS);
            vars.Add("TermsOfServiceAccept", translator.GetTranslatedString("TermsOfServiceAccept"));
            vars.Add("TermsOfServiceText", translator.GetTranslatedString("TermsOfServiceText"));
            vars.Add("RegistrationsDisabled", "");
            //vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
            vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
            vars.Add("AvatarNameText", translator.GetTranslatedString("AvatarNameText"));
            vars.Add("AvatarPasswordText", translator.GetTranslatedString("Password"));
            vars.Add("AvatarPasswordConfirmationText", translator.GetTranslatedString("PasswordConfirmation"));
            vars.Add("AvatarScopeText", translator.GetTranslatedString("AvatarScopeText"));
            vars.Add("FirstNameText", translator.GetTranslatedString("FirstNameText"));
            vars.Add("LastNameText", translator.GetTranslatedString("LastNameText"));
            vars.Add("UserAddressText", translator.GetTranslatedString("UserAddressText"));
            vars.Add("UserZipText", translator.GetTranslatedString("UserZipText"));
            vars.Add("UserCityText", translator.GetTranslatedString("UserCityText"));
            vars.Add("UserCountryText", translator.GetTranslatedString("UserCountryText"));
            vars.Add("UserDOBText", translator.GetTranslatedString("UserDOBText"));
            vars.Add("UserEmailText", translator.GetTranslatedString("UserEmailText"));
            vars.Add("Accept", translator.GetTranslatedString("Accept"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));
            vars.Add("SubmitURL", "register.html");
            vars.Add("ErrorMessage", "");
            vars.Add("Registrations", true);
            vars.Add("NoRegistrations", false);

            return vars;
        }
Exemplo n.º 3
0
        public Dictionary<string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
            OSHttpResponse httpResponse, Dictionary<string, object> requestParameters,
            ITranslator translator, out string response)
        {
            response = null;
            var vars = new Dictionary<string, object>();

            IGenericsConnector generics = Framework.Utilities.DataManager.RequestPlugin<IGenericsConnector>();
            var settings = generics.GetGeneric<GridSettings>(UUID.Zero, "WebSettings", "Settings");

            bool adminUser = Authenticator.CheckAdminAuthentication(httpRequest, Constants.USER_GOD_CUSTOMER_SERVICE);
            bool allowRegistration = settings.WebRegistration;

            // allow configuration to override the web settings?
            //IConfig config = webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs ["LoginService"];
            //if (config != null)
            //    allowRegistration = config.GetBoolean ("AllowAnonymousLogin", false);

            if (!adminUser && !allowRegistration)
            {
                vars.Add("ErrorMessage", "");
                vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
                vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
                vars.Add("Registrations", false);
                vars.Add("NoRegistrations", true);
                return vars;
             }

            if (requestParameters.ContainsKey("Submit"))
            {
                string AvatarName = requestParameters["AvatarName"].ToString();
                string AvatarPassword = requestParameters["AvatarPassword"].ToString();
                string AvatarPasswordCheck = requestParameters["AvatarPassword2"].ToString();
                string FirstName = requestParameters["FirstName"].ToString();
                string LastName = requestParameters["LastName"].ToString();
                //removed - greythane - deemed not used
                //string UserAddress = requestParameters["UserAddress"].ToString();
                //string UserZip = requestParameters["UserZip"].ToString();
                string UserCity = requestParameters["UserCity"].ToString();
                string UserEmail = requestParameters["UserEmail"].ToString();
                string UserDOBMonth = requestParameters["UserDOBMonth"].ToString();
                string UserDOBDay = requestParameters["UserDOBDay"].ToString();
                string UserDOBYear = requestParameters["UserDOBYear"].ToString();
                string AvatarArchive = requestParameters.ContainsKey("AvatarArchive")
                                           ? requestParameters["AvatarArchive"].ToString()
                                           : "";
                bool ToSAccept = requestParameters.ContainsKey("ToSAccept") &&
                                 requestParameters["ToSAccept"].ToString() == "Accepted";

                string UserType = requestParameters.ContainsKey("UserType")         // only admins can set membership
                    ? requestParameters ["UserType"].ToString ()
                    : "Resident";

                // revise UserDOBMonth to a number
                UserDOBMonth = ShortMonthToNumber(UserDOBMonth);

                // revise Type flags
                int UserFlags = webInterface.UserTypeToUserFlags (UserType);

                // a bit of idiot proofing
                if (AvatarName == "")  {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarNameError") + "</h3>";
                    return null;
                }
                if ( (AvatarPassword == "") || (AvatarPassword != AvatarPasswordCheck) )
                {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarPasswordError") + "</h3>";
                    return null;
                }
                if (UserEmail == "")
                {
                    response = "<h3>" + translator.GetTranslatedString ("AvatarEmailError") + "</h3>";
                    return null;
                }

                // so far so good...
                if (ToSAccept)
                {
                    AvatarPassword = Util.Md5Hash(AvatarPassword);

                    IUserAccountService accountService =
                        webInterface.Registry.RequestModuleInterface<IUserAccountService>();
                    UUID userID = UUID.Random();
                    string error = accountService.CreateUser(userID, settings.DefaultScopeID, AvatarName, AvatarPassword,
                                                             UserEmail);
                     if (error == "")
                    {
                        // set the user account type
                        UserAccount account = accountService.GetUserAccount(null, userID);
                        account.UserFlags = UserFlags;
                        accountService.StoreUserAccount (account);

                        // create and save agent info
                        IAgentConnector con = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>();
                        con.CreateNewAgent(userID);
                        IAgentInfo agent = con.GetAgent(userID);
                        agent.OtherAgentInformation ["RLFirstName"] = FirstName;
                        agent.OtherAgentInformation ["RLLastName"] = LastName;
                        //agent.OtherAgentInformation ["RLAddress"] = UserAddress;
                        agent.OtherAgentInformation ["RLCity"] = UserCity;
                        //agent.OtherAgentInformation ["RLZip"] = UserZip;
                        agent.OtherAgentInformation ["UserDOBMonth"] = UserDOBMonth;
                        agent.OtherAgentInformation ["UserDOBDay"] = UserDOBDay;
                        agent.OtherAgentInformation ["UserDOBYear"] = UserDOBYear;
                        agent.OtherAgentInformation ["UserFlags"] = UserFlags;
                        /*if (activationRequired)
                        {
                            UUID activationToken = UUID.Random();
                            agent.OtherAgentInformation["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + PasswordHash);
                            resp["WebUIActivationToken"] = activationToken;
                        }*/
                        con.UpdateAgent(agent);

                        // create user profile details
                        IProfileConnector profileData =
                                Framework.Utilities.DataManager.RequestPlugin<IProfileConnector>();
                        if (profileData != null)
                        {
                            profileData.CreateNewProfile (userID);
                            IUserProfileInfo profile = profileData.GetUserProfile (userID);

                            if (AvatarArchive != "")
                                profile.AArchiveName = AvatarArchive;

                            profile.MembershipGroup = webInterface.UserFlagToType (UserFlags, webInterface.EnglishTranslator);    // membership is english
                            profile.IsNewUser = true;
                            profileData.UpdateUserProfile (profile);
                        }

                        response = "<h3>Successfully created account, redirecting to main page</h3>" +
                                   "<script language=\"javascript\">" +
                                   "setTimeout(function() {window.location.href = \"index.html\";}, 3000);" +
                                   "</script>";
                    }
                    else
                        response = "<h3>" + error + "</h3>";
                }
                else
                    response = "<h3>You did not accept the Terms of Service agreement.</h3>";
                return null;
            }

            List<Dictionary<string, object>> daysArgs = new List<Dictionary<string, object>>();
            for (int i = 1; i <= 31; i++)
                daysArgs.Add(new Dictionary<string, object> {{"Value", i}});

            List<Dictionary<string, object>> monthsArgs = new List<Dictionary<string, object>>();
            //for (int i = 1; i <= 12; i++)
            //    monthsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jan_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Feb_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Mar_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Apr_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("May_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jun_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Jul_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Aug_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Sep_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Oct_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Nov_Short")}});
            monthsArgs.Add(new Dictionary<string, object> {{"Value", translator.GetTranslatedString("Dec_Short")}});

            List<Dictionary<string, object>> yearsArgs = new List<Dictionary<string, object>>();
            for (int i = 1940; i <= 2013; i++)
                yearsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            vars.Add("Days", daysArgs);
            vars.Add("Months", monthsArgs);
            vars.Add("Years", yearsArgs);

            vars.Add("UserTypeText", translator.GetTranslatedString("UserTypeText"));
            vars.Add("UserType", webInterface.UserTypeArgs(translator)) ;

            List<AvatarArchive> archives = webInterface.Registry.RequestModuleInterface<IAvatarAppearanceArchiver>().GetAvatarArchives();

            List<Dictionary<string, object>> avatarArchives = new List<Dictionary<string, object>>();
            IWebHttpTextureService webTextureService = webInterface.Registry.
                                                                    RequestModuleInterface<IWebHttpTextureService>();
            foreach (var archive in archives)
                avatarArchives.Add(new Dictionary<string, object>
                                       {
                                           {"AvatarArchiveName", archive.FileName },
                                           {"AvatarArchiveSnapshotID", archive.Snapshot},
                                           {
                                               "AvatarArchiveSnapshotURL",
                                               webTextureService.GetTextureURL(archive.Snapshot)
                                           }
                                       });

            vars.Add("AvatarArchive", avatarArchives);

            IConfig loginServerConfig =
                webInterface.Registry.RequestModuleInterface<ISimulationBase>().ConfigSource.Configs["LoginService"];
            string tosLocation = "";
            if (loginServerConfig != null && loginServerConfig.GetBoolean("UseTermsOfServiceOnFirstLogin", false))
                tosLocation = loginServerConfig.GetString("FileNameOfTOS", "");
            string ToS = "There are no Terms of Service currently. This may be changed at any point in the future.";

            if (tosLocation != "")
            {
                System.IO.StreamReader reader =
                    new System.IO.StreamReader(System.IO.Path.Combine(Environment.CurrentDirectory, tosLocation));
                ToS = reader.ReadToEnd();
                reader.Close();
            }
            vars.Add("ToSMessage", ToS);
            vars.Add("TermsOfServiceAccept", translator.GetTranslatedString("TermsOfServiceAccept"));
            vars.Add("TermsOfServiceText", translator.GetTranslatedString("TermsOfServiceText"));
            vars.Add("RegistrationsDisabled", "");
            //vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
            vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
            vars.Add("AvatarNameText", translator.GetTranslatedString("AvatarNameText"));
            vars.Add("AvatarPasswordText", translator.GetTranslatedString("Password"));
            vars.Add("AvatarPasswordConfirmationText", translator.GetTranslatedString("PasswordConfirmation"));
            vars.Add("AvatarScopeText", translator.GetTranslatedString("AvatarScopeText"));
            vars.Add("FirstNameText", translator.GetTranslatedString("FirstNameText"));
            vars.Add("LastNameText", translator.GetTranslatedString("LastNameText"));
            vars.Add("UserAddressText", translator.GetTranslatedString("UserAddressText"));
            vars.Add("UserZipText", translator.GetTranslatedString("UserZipText"));
            vars.Add("UserCityText", translator.GetTranslatedString("UserCityText"));
            vars.Add("UserCountryText", translator.GetTranslatedString("UserCountryText"));
            vars.Add("UserDOBText", translator.GetTranslatedString("UserDOBText"));
            vars.Add("UserEmailText", translator.GetTranslatedString("UserEmailText"));
            vars.Add("Accept", translator.GetTranslatedString("Accept"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));
            vars.Add("SubmitURL", "register.html");
            vars.Add("ErrorMessage", "");
            vars.Add("Registrations", true);
            vars.Add("NoRegistrations", false);

            return vars;
        }