/// <summary>
    /// Grabs the value associated with the key "t2sAccountEmail" and sets
    /// the literal in the .aspx page for users to send their codes to.
    /// </summary>
    protected void GetNumberToSendVerificationTo()
    {
        try
        {
            IDBController controller = new SqlController();
            //verificationCode.Text = controller.GetCurrentVerificationValueForUser(_currentUser);
            string code = VerificationGenerator.GenerateString(6);

            verificationCode.Text = code;
            verificationCodeText.Text = "Register " + code;
            t2sAccountEmail.Text = controller.GetPairEntryValue("t2sEmailAccount");
            controller.SetVerificationCodeForUser(code, _currentUser);
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException ex)
        {
            Logger.LogMessage("Verification.aspx: " + ex.Message, LoggerLevel.SEVERE);
            errorMessage.Text = "An unknown error occured. Please try again later.1";
            return;
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("Verification.aspx: " + ex.Message, LoggerLevel.SEVERE);
            errorMessage.Text = "An unknown error occured. Please try again later.2";
            return;
        }
    }
        public void Setup()
        {
            this.stubbedController = MockRepository.GenerateStub<SqlController>();

            this._user1 = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111111",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            this._user2 = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111112",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            this._user3 = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111113",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            this._group = new GroupDAO(this._user1)
            {
                Description = "Test description",
                GroupID = 1,
                GroupTag = "TEST",
                Moderators = new HashSet<UserDAO>(),
                Name = "TEST GROUP",
                EnabledPlugins = new HashSet<PluginDAO>(),
                Users = new HashSet<UserDAO>()
            };
            this._group.Users.Add(this._user2);

            this.stubbedController.Stub(x => x.RetrieveGroup(this._group.GroupTag)).Return(this._group);
            this.stubbedController.Stub(x => x.RetrieveUserByPhoneEmail(this._user1.PhoneEmail)).Return(this._user1);
            this.stubbedController.Stub(x => x.RetrieveUserByPhoneEmail(this._user2.PhoneEmail)).Return(this._user2);
        }
    private bool doGET()
    {
        UserDAO user = (UserDAO)Session["userDAO"];
        String pluginName = Request.QueryString["pluginname"];
        if (pluginName == null)
        {
            // Redirect them back
            SendErrorMessage("Please specify a plugin");
            return false;
        }
        IDBController controller = new SqlController();
        PluginDAO plugin = null;
        try
        {
            plugin = controller.RetrievePlugin(pluginName);
            PluginDescriptionEditor.InnerText = plugin.Description;

            if (!plugin.OwnerID.Equals(user.UserID))
            {
                //SendErrorMessage("That is not a plugin you have written");
                //return false;
                extraJavascript = @"editor.setReadOnly(true);";
            }

            String luacodeFileLoc = LUADefinitions.getLuaScriptLocation(plugin.Name);

            // See if it's there
            if (File.Exists(luacodeFileLoc))
            {
                String luacode = "";
                try
                {
                    luacode = File.ReadAllText(luacodeFileLoc);
                }
                catch (Exception)
                {
                    SendErrorMessage("Could not find plugin " + pluginName);
                    return false;
                }

                editorText.InnerText = luacode;
            }
            else
            {
                SendErrorMessage("Could not find plugin " + pluginName);
                return false;
            }
        }
        catch (CouldNotFindException)
        {
            SendErrorMessage("That is not a valid plugin");
            return false;
        }

        return true;
    }
Beispiel #4
0
    /// <summary>
    /// adds a new group to the database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <exception cref="ArgumentNullException">If the given string is null.</exception>
    /// <exception cref="CouldNotFindException">If the user for the given username could not be found.</exception>
    /// <exception cref="EntryAlreadyExistsException">If the group already exists in the database.</exception>
    /// <exception cref="SQLException">An unknown SQL happened.</exception>
    public void addGroup_Click(Object sender, EventArgs e)
    {
        SqlController controller = new SqlController();

        UserDAO owner = Session["userDAO"] as UserDAO;

        GroupDAO group = new GroupDAO(owner);
        group.Name = Request["groupNameBox"];
        group.GroupTag = Request["groupTagBox"];
        group.Description = Request["groupDescriptionBox"];

        if (string.IsNullOrWhiteSpace(group.Name) || group.Name.Length >= GroupDAO.NameMaxLength)
        {
            ShowError(string.Format("Invalid group name. Please enter a name under {0} characters.", GroupDAO.NameMaxLength));
            groupNameBox.Focus();
        }
        else if (string.IsNullOrWhiteSpace(group.GroupTag) || group.GroupTag.Length > GroupDAO.GroupTagMaxLength || group.GroupTag.Length < 4)
        {
            ShowError(string.Format("Invalid group tag. Please enter a tag between {0} and {1} characters.", 4, GroupDAO.GroupTagMaxLength));
            groupTagBox.Focus();
        }
        else if (string.IsNullOrWhiteSpace(group.Description) || group.Description.Length >= GroupDAO.DescriptionMaxLength)
        {
            ShowError(string.Format("Invalid group description. Please enter a name under {0} characters.", GroupDAO.DescriptionMaxLength));
            groupDescriptionBox.Focus();
        }
        else
        {
            try
            {
                if (controller.CreateGroup(group))
                {
                    // Redirect to the manage page
                    Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}", HttpUtility.UrlEncode(group.GroupTag)));
                }
                else
                {
                    ShowError("Your group was not created successfully. Please try again!");
                }
            }
            catch (ArgumentNullException)
            {
                ShowError("An unknown error has happened. Please try again later.");
            }
            catch (EntryAlreadyExistsException)
            {
                ShowError("This group already exists!");
            }
            catch (SqlException error)
            {
                ShowError("An unknown error has happened. Please try again later.");
                Logger.LogMessage("AddGroup.aspx: " + error.Message, LoggerLevel.SEVERE);
            }
        }
    }
    /// <summary>
    /// Updates the group's metadata in the database 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void submitPluginsButton_Click(object sender, EventArgs e)
    {
        bool isMod = false;
        string groupTag = Request.QueryString["grouptag"];
        SqlController control = new SqlController();
        GroupDAO group = control.RetrieveGroup(groupTag);
        List<GroupDAO> groupList = control.GetGroupsUserIsModeratorOf(_currentUser.UserID);
        foreach (GroupDAO x in groupList)
        {
            if (x.GroupID == group.GroupID)
            {
                isMod = true;
            }
        }

        if (_currentGroup.Owner.UserID != _currentUser.UserID && !isMod)
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit plugins in groups you do not own.")));
            return;
        }

        try
        {
            IDBController controller = new SqlController();

            _currentGroup.EnabledPlugins = ParseFromTextArea(enabledPlugins);

            control.UpdateGroupPlugins(_currentGroup);

        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugins.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManagePlugins.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return;
        }

        Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&success={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Plugins successfully updated!")));
    }
    public void deletePlugin_Click(Object sender, EventArgs e)
    {
        if (_currentPlugin != null)
        {
            // Are they the owner?
            if (_currentPlugin.OwnerID != _currentUser.UserID)
            {
                Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit plugins you do not own.")));
            }

            try
            {
                IDBController database = new SqlController();
                if (database.DeletePlugin(_currentPlugin))
                {
                    // Delete the file
                    // Create a blank file
                    string path = LUADefinitions.getLuaScriptLocation(_currentPlugin.Name);
                    try
                    {
                        File.Delete(path);
                    }
                    catch (Exception)
                    {
                    }

                    Response.Redirect(string.Format(@"Index.aspx?success={0}", HttpUtility.UrlEncode(@"The plugin has been deleted.")));
                }
                else
                {
                    ShowError("Failed to delete plugin.");
                }
            }
            catch (CouldNotFindException)
            {
                // Shouldn't happen
            }
            catch (ArgumentNullException)
            {
                // Shouldn't happen
            }
            catch (SqlException ex)
            {
                Logger.LogMessage("ManagePlugin: " + ex.Message, LoggerLevel.SEVERE);
                ShowError("An unknown error occurred loading plugin data. Please try again soon.");
            }
        }

        PopulatePage();
    }
Beispiel #7
0
    public void Login_Click(Object sender, EventArgs e)
    {
        SqlController controller = new SqlController();
        String userName = Request["userNameBox"];
        String pasword = Request["passwordBox"];

        if (controller.CheckLogin(userName, pasword))
        {
            UserDAO user;
            try
            {
                user = controller.RetrieveUserByUserName(userName);
            }
            catch (ArgumentNullException)
            {
                invalidCredentials.Text = "Invalid user name or password.";
                return;
            }
            catch (CouldNotFindException)
            {
                invalidCredentials.Text = "Invalid user name or password.";
                return;
            }

            HttpContext.Current.Session["userDAO"] = user;

            // Check if the user's phone-email is already verified in the system
            try
            {
                if (!base.isVerified(user))
                {
                    Response.Redirect("Verification.aspx");
                }
                else
                {
                    Response.Redirect("Index.aspx");
                }
            }
            catch (SqlException ex)
            {
                Logger.LogMessage("Verification.aspx: " + ex.Message, LoggerLevel.SEVERE);
                invalidCredentials.Text = "An unknown error occured. Please try again later.";
            }

            return;
        }

        invalidCredentials.Text = "Invalid user name or password.";
        return;
    }
Beispiel #8
0
    public void retrievePlugins()
    {
        List<PluginDAO> plugins = new List<PluginDAO>();

        try
        {
            IDBController controller = new SqlController();
            plugins = controller.GetPluginsOwnedByUser(_currentUser);
        }
        catch (ArgumentNullException)
        {
            // Should not happen
        }

        printPluginsToPage(plugins, pluginsUserOwns, @"<li>You do not own any plugins. Press ""Create Plugin"" to make a new one!</li>");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "application/json; charset=utf-8";

        String searchFor = Request.QueryString["search"];

        StringBuilder userJson = new StringBuilder();
        userJson.Append(@"{");
        userJson.Append(@" ""Users"" : [ ");

        try
        {
            if (!String.IsNullOrEmpty(searchFor))
            {
                SqlController controller = new SqlController();
                List<UserDAO> users = controller.GetAllUsers();

                bool first = true;
                foreach (UserDAO user in users)
                {
                    if (!user.UserName.Equals("SYSTEM", StringComparison.OrdinalIgnoreCase)
                        && user.UserName.IndexOf(searchFor, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        if (!first)
                            userJson.Append(@", ");
                        userJson.Append(@"""");
                        userJson.Append(user.UserName);
                        userJson.Append(@"""");

                        first = false;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Logger.LogMessage("Users.json.aspx: " + ex.Message, LoggerLevel.SEVERE);
        }

        userJson.Append(@" ] ");
        userJson.Append(@"}");

        Response.Write(userJson.ToString());
        Response.End();
    }
Beispiel #10
0
        static void Main(string[] args)
        {
            IDBController database = new SqlController();
            Logger.LogMessage("Established connection to SQL server", LoggerLevel.DEBUG);
            //try
            //{
            //    // Try and add data, if it errors we probably already have it in the DB
            //    PrivateInfo.addTestData(database);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("ADDING PRIVATE INFO: " + ex.Message);
            //}
            AWatcherService gmailServ = new GMailWatcherService(
                database.GetPairEntryValue("t2sEmailAccount"),
                PrivateInfo.Email.Password,
                true,
                "imap.gmail.com",
                993,
                "smtp.gmail.com",
                587);

            MessageControllerOverride controller = new MessageControllerOverride(gmailServ, database);
            PluginLibrary pluginLib = new PluginLibrary(controller, gmailServ, database);

            pluginLib.Start();
            Logger.LogMessage("Started PluginLibrary", LoggerLevel.DEBUG);
            gmailServ.Start();
            Logger.LogMessage("Started AWatcherService", LoggerLevel.DEBUG);

            // Add fake emails (For testing)
            List<Message> msgArray = new List<Message>();
            //msgArray.Add(new Message(...));

            foreach (Message msg in msgArray)
                controller.putNextMessage(MessageParser.Parse(msg, database));

            Logger.LogMessage("Waiting for messages...", LoggerLevel.DEBUG);

            // BAD
            while (true) ;
        }
Beispiel #11
0
    /// <summary>
    /// updates the user's information
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <exception cref="ArgumentNullException">If the given string is null.</exception>
    /// <exception cref="CouldNotFindException">If the user for the given username could not be found.</exception>
    /// <exception cref="SQL Exception">An unknown SQL happened.</exception>
    public void update_Click(Object sender, EventArgs e)
    {
        SqlController controller = new SqlController();
        UserDAO user;
        String firstName = Request["firstNameBox"];
        String lastName = Request["lastNameBox"];
        String userName = Request["userNameBox"];
        String phoneNumber = Request["phoneNumberBox"];
        String carrier = Request["carrierBox"];

        user = Session["userDAO"] as UserDAO;
        //user.UserName = userName;
        //user.PhoneNumber = phoneNumber;
        user.FirstName = firstName;
        user.LastName = lastName;
        try
        {
            //check if user name or phone email is already being used
            //if (controller.UserExists(user.UserName, user.PhoneEmail))
            //{
            //    ShowError("User Name or Phone Number is already taken", false);
            //}
            //else
            {
                controller.UpdateUser(user);
                ShowError("User information successfully updated.", true);
            }
        }
        catch (ArgumentNullException)
        {
            ShowError("An unknown error occured. Please try again later.", true);
        }
        catch (CouldNotFindException)
        {
            ShowError("An unknown error occured. Please try again later.", true);
        }
        catch (SqlException err)
        {
            Logger.LogMessage("ManageUser.aspx: " + err.Message, LoggerLevel.SEVERE);
            ShowError("An unknown error occured. Please try again later.", true);
        }
    }
Beispiel #12
0
    /// <summary>
    /// Checks if the given user is verified in the database. If they are not, they are redirected to the
    /// Verification page. Otherwise, they are sent to the Index page. Users are always sent to the
    /// Verification page on first registering with the application.
    /// </summary>
    /// <param name="currentUser">The user to check in the database.</param>
    /// <returns>true if the user is already verified</returns>
    /// <exception cref="SqlException">If there is an issue connecting to the database.</exception>
    public bool isVerified(UserDAO currentUser)
    {
        try
        {
            IDBController controller = new SqlController();
            string val = controller.GetCurrentVerificationValueForUser(currentUser);
            return null == val;
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            // User was literally just created, shouldn't be a problem
        }
        // Let the other pages handle SqlExceptions, for displaying to users

        return false;
    }
Beispiel #13
0
    public void printPluginsToPage(List<PluginDAO> plugins, Literal pageLiteral, string zeroPluginCountMessage)
    {
        StringBuilder pluginBuilder = new StringBuilder();
        if (0 == plugins.Count)
        {
            pluginBuilder.Append(zeroPluginCountMessage);
        }
        else
        {
            foreach (PluginDAO plugin in plugins)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(string.Format(@"<li><a href=""ManagePlugin.aspx?pluginname={1}"">{0} ",
                    HttpUtility.HtmlEncode(plugin.Name),
                    HttpUtility.HtmlEncode(HttpUtility.UrlEncode(plugin.Name))));
                if (plugin.IsDisabled)
                {
                    sb.Append(string.Format(@"<span class=""label label-important pull-right"">Disabled</span>"));
                }
                else
                {
                    try
                    {
                        IDBController controller = new SqlController();
                        int errorCount = controller.GetPluginFailedAttemptCount(plugin.PluginID);
                        if (errorCount > 0)
                            sb.Append(string.Format(@"<span class=""badge badge-important pull-right"">{0}</span>", HttpUtility.HtmlEncode(errorCount)));
                    }
                    catch (Exception)
                    {
                        // Shh... nothing but tears.
                    }
                }
                sb.Append(string.Format(@"</a></li>"));
                pluginBuilder.Append(sb.ToString());
            }
        }

        pageLiteral.Text = pluginBuilder.ToString();
    }
    protected void deleteGroupButton_Click(object sender, EventArgs e)
    {
        if (null != _currentGroup)
        {
            if (_currentGroup.Owner.UserID != _currentUser.UserID)
            {
                Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit groups you do not own.")));
                return;
            }

            try
            {
                IDBController controller = new SqlController();
                if (controller.DeleteGroup(_currentGroup))
                {
                    Response.Redirect(string.Format(@"Index.aspx?success={0}", HttpUtility.UrlEncode(@"The group has been deleted.")));
                }
            }
            catch (ArgumentNullException)
            {
                // Shouldn't happen
            }
            catch (SqlException ex)
            {
                Logger.LogMessage("ManageGroup.aspx: " + ex.Message, LoggerLevel.SEVERE);
                Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                    HttpUtility.UrlEncode(_currentGroup.GroupTag),
                    HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
                return;
            }
        }

        SetGroupData();
        RetrieveUsers();
        RetrievePlugins();
    }
Beispiel #15
0
    private bool doPOST()
    {
        UserDAO user = (UserDAO)Session["userDAO"];
        String pluginName = Request.Form["pluginName"];

        String successMessage = "";

        if (pluginName == null)
        {
            // Redirect them back
            SendErrorMessage("Please specify a plugin");
            return false;
        }

        IDBController controller = new SqlController();
        PluginDAO plugin = null;
        try
        {
            plugin = controller.RetrievePlugin(pluginName);

            if (!plugin.OwnerID.Equals(user.UserID))
            {
                SendErrorMessage("That is not a plugin you have written.");
                return false;
            }
            else
            {
                // Go ahead and save it
                String luacodeFileLoc = LUADefinitions.getLuaScriptLocation(plugin.Name);

                // See if it's there
                if (File.Exists(luacodeFileLoc))
                {
                    String luacode = Request.Form["editorText"];
                    try
                    {
                        File.WriteAllText(luacodeFileLoc, luacode);
                        controller.ResetPluginFailedAttemptCount(plugin.PluginID);
                        if (controller.GetPluginFailedAttemptCount(plugin.PluginID) == 0)
                        {
                            // Reenable the plugin
                            controller.EnableGlobalPlugin(plugin.PluginID);
                        }
                        successMessage = "Plugin has been updated.";
                    }
                    catch (Exception)
                    {
                        SendErrorMessage("Could not save plugin.");
                        return false;
                    }
                }
                else
                {
                    SendErrorMessage("Could not save plugin.");
                    return false;
                }
            }
        }
        catch (CouldNotFindException)
        {
            SendErrorMessage("That is not a valid plugin");
            return false;
        }

        // Always redirect on POST
        Response.Redirect(string.Format("EditPlugin.aspx?pluginname={0}&success={1}", HttpUtility.UrlEncode(pluginName), HttpUtility.UrlEncode(successMessage)));

        return false;
    }
        public void Setup()
        {
            _controller = new SqlController();

            _owner = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111111",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };
            _controller.CreateUser(_owner, "password");

            _plugin1 = new PluginDAO()
            {
                Name = "TEST1",
                Description = "A test plugin",
                HelpText = "A simple test plugin",
                IsDisabled = false,
                VersionNum = "1",
                Access = PluginAccess.STANDARD,
                OwnerID = (int) _owner.UserID
            };

            _plugin2 = new PluginDAO()
            {
                Name = "TEST2",
                Description = "A test plugin 2",
                HelpText = "A simple test plugin 2",
                IsDisabled = false,
                VersionNum = "1",
                Access = PluginAccess.STANDARD,
                OwnerID = (int)_owner.UserID
            };

            _nullPlugin = new PluginDAO()
            {
                Name = null,
                Description = null,
                HelpText = null,
                IsDisabled = false,
                VersionNum = null,
                Access = PluginAccess.STANDARD,
                OwnerID = (int)_owner.UserID
            };
        }
    private void GetPagePlugin()
    {
        if (null == Request["pluginname"])
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An error occurred retrieving the plugin information")));
            return;
        }

        try
        {
            IDBController controller = new SqlController();
            _currentPlugin = controller.RetrievePlugin(Request["pluginname"]);
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An unknown error occurred loading plugin data. Please try again soon.")));
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugin: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An unknown error occurred loading plugin data. Please try again soon.")));
        }
    }
Beispiel #18
0
    /// <summary>
    /// Retrieves groups from the database associated with the current user in session.
    /// </summary>
    private void retrieveGroups()
    {
        if (null != _currentUser)
        {
            List<GroupDAO> ownedGroups = new List<GroupDAO>();
            List<GroupDAO> moderatedGroups = new List<GroupDAO>();
            List<GroupDAO> userIsInGroups = new List<GroupDAO>();

            try
            {
                IDBController controller = new SqlController();
                ownedGroups = controller.GetGroupsUserIsOwnerOf(_currentUser.UserID);
                moderatedGroups = controller.GetGroupsUserIsModeratorOf(_currentUser.UserID);
                userIsInGroups = controller.GetGroupsUserIsMemberOf(_currentUser.UserID);
            }
            catch (SqlException)
            {
                groupsUserOwns.Text = "<li>An error occurred gathering group information. Please try again later.</li>";
                return;
            }

            printGroupsToPage(ownedGroups, groupsUserOwns, @"<li>You do not own any groups. Press ""Create Group"" to make a new one!</li>");
            printGroupsToPage(moderatedGroups, groupsUserModerates, "<li>You are not the moderator of any groups.</li>");
            printGroupsToPage(userIsInGroups, groupsUserIsIn, "<li>You are not a user of any groups.</li>");
        }
    }
    /// <summary>
    /// Splits up the user names in the given TextBox input, finds them in the database and adds them to a HashSet.
    /// </summary>
    /// <param name="textarea"></param>
    /// <returns></returns>
    private HashSet<UserDAO> ParseUsersFromTextArea(TextBox textarea)
    {
        string[] usernames;
        if (textarea.Text.IndexOf(',') < 0)
        {
            usernames = new string[] { textarea.Text.Trim() };
        }
        else
        {
            usernames = textarea.Text.Split(',');
        }

        HashSet<UserDAO> users = new HashSet<UserDAO>();

        try
        {
            IDBController controller = new SqlController();
            foreach (string username in usernames)
            {
                try
                {
                    users.Add(controller.RetrieveUserByUserName(username.Trim()));
                }
                catch (CouldNotFindException)
                {
                    usersNotFound.Add(username);
                }
            }
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManageGroup.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return null;
        }

        return users;
    }
    /// <summary>
    /// Updates the group's metadata in the database 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void UpdateGroupMetadata_Click(object sender, EventArgs e)
    {
        bool isMod = false;
        string groupTag = Request.QueryString["grouptag"];
        SqlController control = new SqlController();
        GroupDAO group = control.RetrieveGroup(groupTag);
        List<GroupDAO> groupList = control.GetGroupsUserIsModeratorOf(_currentUser.UserID);
        foreach (GroupDAO x in groupList)
        {
            if (x.GroupID == group.GroupID)
            {
                isMod = true;
            }
        }

        if (_currentGroup.Owner.UserID != _currentUser.UserID && !isMod)
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit groups you do not own.")));
            return;
        }

        // Check that they are not updating to empty values
        if (string.IsNullOrWhiteSpace(groupNameBox.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group name to be empty or whitespace.")));
            groupNameBox.Focus();
            return;
        }
        else if (string.IsNullOrWhiteSpace(groupTagBox.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group tag to be empty or whitespace.")));
            groupTagBox.Focus();
            return;
        }
        else if (string.IsNullOrWhiteSpace(groupDescriptionBox.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group description to be empty or whitespace.")));
            groupDescriptionBox.Focus();
            return;
        }
        else if (string.IsNullOrWhiteSpace(groupOwner.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group owner to be empty or whitespace.")));
            groupOwner.Focus();
            return;
        }

        try
        {
            IDBController controller = new SqlController();
            // Check first that the group tag isn't already being used in the database by a different group
            if (!controller.GroupExists(groupTagBox.Text, _currentGroup.GroupID))
            {
                // If ok, set the current groupDAO reference to the group tag and update the database
                _currentGroup.Name = groupNameBox.Text;
                _currentGroup.GroupTag = groupTagBox.Text;
                _currentGroup.Description = groupDescriptionBox.Text;

                controller.UpdateGroupMetadata(_currentGroup);

                _currentGroup.Moderators = ParseUsersFromTextArea(groupModerators);
                _currentGroup.Users = ParseUsersFromTextArea(groupUsers);

                controller.UpdateGroup(_currentGroup);
            }
            else
            {
                // Tell the user they can't use the group tag
                Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                    HttpUtility.UrlEncode(_currentGroup.GroupTag),
                    HttpUtility.UrlEncode(string.Format(@"A group with grouptag ""{0}"" already exists.", HttpUtility.HtmlEncode(groupTagBox.Text)))));
                return;
            }
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManageGroup.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return;
        }

        if (usersNotFound.Count > 0)
        {
            StringBuilder builder = new StringBuilder();
            foreach (string user in usersNotFound)
            {
                builder.Append(user + " ");
            }

            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("The following users were not found in the database and were not added to the group: " + builder.ToString())));
        }

        Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&success={1}",
            HttpUtility.UrlEncode(_currentGroup.GroupTag),
            HttpUtility.UrlEncode("The group information was updated successfully!")));
    }
 public void TearDown()
 {
     this._user2 = null;
     this._user1 = null;
     this._group = null;
     this.stubbedController = null;
 }
    public void updatePlugin_Click(Object sender, EventArgs e)
    {
        //String pluginName = Request["pluginNameBox"];
        String pluginDescription = Request["pluginDescriptionBox"];
        String pluginHelpText = Request["helpTextBox"];
        String pluginVersion = Request["versionBox"];

        try
        {
            // Are they the owner?
            if (_currentPlugin.OwnerID != _currentUser.UserID)
            {
                Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit plugins you do not own.")));
            }

            //if (string.IsNullOrWhiteSpace(pluginName) || pluginName.Length >= PluginDAO.NameMaxLength)
            //{
            //    ShowError("Plugin name cannot be empty or all spaces, and must be less than 64 characters.");
            //    return;
            //}
            if (string.IsNullOrWhiteSpace(pluginDescription) || pluginDescription.Length >= PluginDAO.DescriptionMaxLength)
            {
                ShowError("Plugin description cannot be empty or all spaces.");
            }
            else if (string.IsNullOrWhiteSpace(pluginHelpText) || pluginHelpText.Length >= PluginDAO.HelpTextMaxLength)
            {
                ShowError("Plugin help text cannot be empty or all spaces, and must be less than 160 characters.");
            }
            else if (string.IsNullOrWhiteSpace(pluginVersion) || pluginVersion.Length >= PluginDAO.VersionNumberMaxLength)
            {
                ShowError("Plugin version number cannot be empty or all spaces, and must be less than 32 characters.");
            }
            else
            {
                // Everything checks out--set the current plugin information
                //_currentPlugin.Name = pluginName;
                _currentPlugin.Description = pluginDescription;
                _currentPlugin.HelpText = pluginHelpText;
                _currentPlugin.VersionNum = pluginVersion;

                IDBController controller = new SqlController();
                //controller.UpdatePluginOwner(_currentPlugin, _currentUser);
                controller.UpdatePlugin(_currentPlugin);
            }
        }
        catch (CouldNotFindException)
        {
            // Shouldn't happen
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugin: " + ex.Message, LoggerLevel.SEVERE);
            ShowError("An unknown error occurred loading plugin data. Please try again soon.");
        }

        PopulatePage();
    }
    /// <summary>
    /// Splits up the user names in the given TextBox input, finds them in the database and adds them to a HashSet.
    /// </summary>
    /// <param name="textarea"></param>
    /// <returns></returns>
    private HashSet<PluginDAO> ParseFromTextArea(TextBox textarea)
    {
        string[] pluginsSplit;
        if (textarea.Text.IndexOf(',') < 0)
        {
            pluginsSplit = new string[] { textarea.Text.Trim() };
        }
        else
        {
            pluginsSplit = textarea.Text.Split(',');
        }

        HashSet<PluginDAO> plugins = new HashSet<PluginDAO>();

        try
        {
            IDBController controller = new SqlController();
            foreach (string plug in pluginsSplit)
            {
                try
                {
                    plugins.Add(controller.RetrievePlugin(plug.Trim()));
                }
                catch (CouldNotFindException)
                {
                    Response.Redirect(string.Format("ManagePlugins.aspx?grouptag={0}&error={1}{2}{3}",
                    HttpUtility.UrlEncode(_currentGroup.GroupTag),
                    HttpUtility.UrlEncode("Could not find plugin '"),
                    HttpUtility.UrlEncode(plug),
                    HttpUtility.UrlEncode("'")));
                    return null;
                }
            }
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugins.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManagePlugins.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return null;
        }

        return plugins;
    }
        public void Setup()
        {
            _controller = new SqlController();

            _owner = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111111",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _moderator = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111112",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _user = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111113",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _controller.CreateUser(_owner, "password");
            _controller.CreateUser(_moderator, "password");
            _controller.CreateUser(_user, "password");

            _enabledPlugin = new PluginDAO()
            {
                Name = "EnPlgn",
                Description = "An enabled test plugin",
                IsDisabled = false,
                VersionNum = "1.0.0",
                OwnerID = _user.UserID,
                Access = PluginAccess.STANDARD,
                HelpText = "Help meh, I'm an enabled plugin!"
            };

            _disabledPlugin = new PluginDAO()
            {
                Name = "DsPlgn",
                Description = "A disabled test plugin",
                IsDisabled = true,
                VersionNum = "1.0.0",
                OwnerID = _user.UserID,
                Access = PluginAccess.STANDARD,
                HelpText = "Help meh, I'm a disabled plugin!"
            };

            _controller.CreatePlugin(_enabledPlugin);
            _controller.CreatePlugin(_disabledPlugin);

            _group = new GroupDAO(_owner)
            {
                Name = "Test Group",
                Description = "A test group, for testing",
                GroupTag = "TEST"
            };
        }
 private void GetGroupData()
 {
     try
     {
         IDBController controller = new SqlController();
         _currentGroup = controller.RetrieveGroup(Request["grouptag"]);
     }
     catch (ArgumentNullException)
     {
         // Shouldn't happen
     }
     catch (CouldNotFindException)
     {
         Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An unknown error occurred. Please try again soon.")));
         return;
     }
     catch (SqlException ex)
     {
         Logger.LogMessage("ManageGroup.aspx.cs: " + ex.Message, LoggerLevel.SEVERE);
         Response.Redirect(string.Format("ManagePlugins.aspx?error={0}", HttpUtility.UrlEncode("An unknown error occurred. Please try again soon.")));
         return;
     }
 }
    /// <summary>
    /// registers a user 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <exception cref="ArgumentNullException">If the given string is null.</exception>
    /// <exception cref="EntryAlreadyExitsException">If the user for the given username already exits.</exception>
    /// <exception cref="SQLException">If an unknown databasae exception happends.</exception>
    /// <exception cref="InvalidCastException">If the phonecarrier string value can not be casted to a existing phoneCarrier.</exception>
    public void Register_Click(Object sender, EventArgs e)
    {
        String password = Request["passwordBox"];
        String verifyPassword = Request["verifyPasswordBox"];
        //verify password fields match
        if (!password.Equals(verifyPassword))
        {
            invalidCredentials.Text = "The passwords you entered do not match. Please try again.";
            return;
        }

        SqlController controller = new SqlController();

        String phoneNumber = Request["phoneNumberBox"].Replace("-", String.Empty);
        //create a new userDAO and set it fields
        UserDAO user = null;
        try
        {
             user = new UserDAO()
            {
                FirstName = Request["firstNameBox"],
                LastName = Request["lastNameBox"],
                UserName = Request["userNameBox"],
                PhoneNumber = phoneNumber,
                Carrier = (PhoneCarrier)(Request["carrierDropdown"]),
                PhoneEmail = phoneNumber + "@" + ((PhoneCarrier)(Request["carrierDropdown"])).GetEmail(),
                IsBanned = false,
                IsSuppressed = false
            };
        }
        catch (InvalidCastException)
        {
            Response.Write("Could not find phone carrier! Please try again!");
        }

        //check to see is needs to be hashed before
        try
        {
            if (!controller.CreateUser(user, password))
            {
                Response.Write("The user was not created");
            }
        }
        catch (EntryAlreadyExistsException)
        {
            invalidCredentials.Text = "A user with that name or phone number already exists. Please try again.";
            return;
        }
        catch (ArgumentNullException)
        {
            invalidCredentials.Text = "A field was left blank. Please make sure the form is fully completed.";
            return;
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("Register.aspx: " + ex.Message, LoggerLevel.SEVERE);
            invalidCredentials.Text = "An unknown error occured.  Please try again.";
            return;
        }

        //set the session the same as user login
        HttpContext.Current.Session["userDAO"] = user;

        Response.Redirect("Verification.aspx");
    }
    /// <summary>
    /// Uses the grouptag GET parameter and retrieves the group metadata.
    /// Populates the "Group Information" section as well.
    /// </summary>
    /// <exception cref="ArgumentNullException">If the given string is null.</exception>
    /// <exception cref="CouldNotFindException">If the user for the given username could not be found.</exception>
    /// <exception cref="SQL exception">For an unknown SQL error.</exception>
    private void SetGroupData()
    {
        SqlController controller = new SqlController();
        List<PluginDAO> DisabledPlugins = controller.GetAllDisabledGroupPlugins(_currentGroup.GroupID);
        List<PluginDAO> EnabledPlugins = controller.GetAllEnabledGroupPlugins(_currentGroup.GroupID);

        bool first = true;
        foreach (PluginDAO plug in DisabledPlugins)
        {
            if (!first)
                disabledPlugins.Text += ", ";
            disabledPlugins.Text += plug.Name;

            first = false;
        }

        first = true;
        foreach (PluginDAO plug in EnabledPlugins)
        {
            if (!first)
                enabledPlugins.Text += ", ";
            enabledPlugins.Text += plug.Name;

            first = false;
        }
    }
Beispiel #28
0
    public void AddPlugin_Click(Object sender, EventArgs e)
    {
        PluginDAO plugin = new PluginDAO()
        {
            Name = Request["pluginNameBox"],
            Description = Request["pluginDescriptionBox"],
            HelpText = Request["helpTextBox"],
            IsDisabled = false,
            VersionNum = Request["versionBox"],
            OwnerID = _currentUser.UserID
        };

        // Do some form validation
        if (plugin.Name == null || plugin.Name.Length > PluginDAO.NameMaxLength || plugin.Name.Length < 4)
        {
            ShowError(string.Format("Plugin name is invalid. Please enter a name between {0} and {1} characters.", 4, PluginDAO.NameMaxLength));
            pluginNameBox.Focus();
            return;
        }
        else if (plugin.Description == null || plugin.Description.Length >= PluginDAO.DescriptionMaxLength)
        {
            ShowError(string.Format("Plugin description is invalid. Please enter a description less than {0} characters long.", PluginDAO.DescriptionMaxLength));
            pluginDescriptionBox.Focus();
            return;
        }
        else if (plugin.HelpText == null || plugin.HelpText.Length >= PluginDAO.HelpTextMaxLength)
        {
            ShowError(string.Format("Plugin help text is invalid. Please enter a help text less than {0} characters long.", PluginDAO.HelpTextMaxLength));
            helpTextBox.Focus();
            return;
        }
        else if (plugin.VersionNum == null || plugin.VersionNum.Length >= PluginDAO.VersionNumberMaxLength)
        {
            ShowError(string.Format("Plugin version is invalid. Please enter a version that is less than {0} characters long.", PluginDAO.VersionNumberMaxLength));
            versionBox.Focus();
            return;
        }
        else
        {
            // All systems go
            IDBController controller = new SqlController();
            try
            {
                // Can we create our plugin?
                if (controller.CreatePlugin(plugin))
                {
                    // Create a blank file
                    string path = LUADefinitions.getLuaScriptLocation(Request["pluginNameBox"]);
                    try
                    {
                        using (File.Create(path)) { }
                    }
                    catch (Exception)
                    {
                        // Clean up
                        controller.DeletePlugin(plugin);
                        ShowError("Error creating plugin.  Please try again later.");
                        return;
                    }

                    // Shoot them to the editor
                    Response.Redirect(string.Format("EditPlugin.aspx?pluginname={0}", HttpUtility.UrlEncode(plugin.Name)));
                }
            }
            catch (EntryAlreadyExistsException)
            {
                // Error
                ShowError("That plugin name already exists.");
                return;
            }
            catch (SqlException ex)
            {
                // Error
                Logger.LogMessage("AddPlugin.aspx: " + ex.Message, LoggerLevel.SEVERE);
                return;
            }
        }
    }
        public void Setup()
        {
            _user1 = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111111",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _user2 = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111112",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _nullUser = new UserDAO()
            {
                UserName = null,
                FirstName = null,
                LastName = null,
                PhoneNumber = null,
                PhoneEmail = null,
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _controller = new SqlController();
        }
Beispiel #30
0
 public void Setup()
 {
     _controller = new SqlController();
 }