Example #1
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        XMLUsers userDB = new XMLUsers();

        if (userDB.getNode(txtUsername.Text, "password") == txtPassword.Text)
        {
            String sessID = userDB.getNode(txtUsername.Text, "sessionID");
            Response.SetCookie(Helper.createCookie("sessionID", sessID));
            Response.Redirect("Forum.aspx");
            return;
        }

        // Replace with Validation Control **
        Response.Write("Incorrect Password!");
    }
Example #2
0
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        XMLUsers userDB = new XMLUsers();

        // Check if user already exists
        String username = txtUsername.Text;

        if (userDB.findUser(username))
        {
            // Replace following line with Validation Control **
            Response.Write("Username already in use.");
            return;
        }

        // Check if password and confirmation match
        String password = txtPassword.Text;

        if (password != txtPasswordConfirm.Text)
        {
            // Replace following line with Validation Control **
            Response.Write("Password and password confirmation do not match.");
        }

        // Generate session ID
        String sessID = Helper.createSessionID();

        // Create Dictionary of user info and add to database
        Dictionary <string, string> userInfo = new Dictionary <string, string>();

        userInfo.Add("username", username);
        userInfo.Add("password", password);
        userInfo.Add("sessionID", sessID);
        userDB.AddUser(userInfo);

        // Sets the sessionID as a cookie to help keep user logged in
        Response.SetCookie(Helper.createCookie("sessionID", sessID));

        Response.Redirect("Forum.aspx");
    }
Example #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["post"] != null)
        {
            XMLForum forumDB = new XMLForum();
            XMLUsers userDB  = new XMLUsers();

            TableRow  rowTitle        = new TableRow();
            TableRow  rowContent      = new TableRow();
            TableCell cellTitle       = new TableCell();
            TableCell cellBy          = new TableCell();
            TableCell cellContent     = new TableCell();
            TableCell cellReplyButton = new TableCell();

            Button btnReply = new Button();
            btnReply.Click += new EventHandler(this.onReplyClick);
            btnReply.Text   = "Reply";

            mainTable.Rows.Add(rowTitle);
            mainTable.Rows.Add(rowContent);

            String category = (String)Session["category"];
            String title    = (String)Session["post"];
            String postBy   = userDB.getUserFromSessionID(forumDB.getPostedBy(category, title));

            cellTitle.Text   = title;
            cellBy.Text      = "Posted by " + postBy;
            cellContent.Text = forumDB.readPost(category, title);
            cellReplyButton.Controls.Add(btnReply);

            cellTitle.Attributes.Add("class", "postTitle");
            cellBy.Attributes.Add("class", "postBy");
            cellReplyButton.Attributes.Add("class", "postBy");

            rowTitle.Cells.Add(cellTitle);
            rowTitle.Cells.Add(cellReplyButton);
            rowTitle.Attributes.Add("class", "postTitleRow");
            rowContent.Cells.Add(cellContent);
            rowContent.Cells.Add(cellBy);
            rowContent.Attributes.Add("class", "postContentRow");

            if (forumDB.getPostReplies(category, title) != null)
            {
                TableRow  rowReply;
                TableCell cellReplyContent;
                TableCell cellReplyBy;
                String    replyBy;

                foreach (var pair in forumDB.getPostReplies(category, title))
                {
                    rowReply         = new TableRow();
                    cellReplyContent = new TableCell();
                    cellReplyBy      = new TableCell();

                    mainTable.Rows.Add(rowReply);
                    rowReply.Attributes.Add("class", "postReplyRow");

                    replyBy = pair.Key;
                    replyBy = replyBy.Substring(0, replyBy.Length - 3);
                    replyBy = userDB.getUserFromSessionID(replyBy);

                    cellReplyContent.Text = pair.Value;
                    cellReplyBy.Text      = "Posted by " + replyBy;
                    cellReplyBy.Attributes.Add("class", "postBy");

                    rowReply.Cells.Add(cellReplyContent);
                    rowReply.Cells.Add(cellReplyBy);
                }
            }
        }
        else
        {
            Response.Redirect("Forum.aspx");
        }
    }