Ejemplo n.º 1
0
    protected void registerBtn_Click(object sender, EventArgs e)
    {
        resultsLabel.Visible = true;
        XMLAccess xmlAccess = new XMLAccess();

        if (!xmlAccess.SearchUserNode(username.Text))
        {
            Dictionary <string, string> userInfo = new Dictionary <string, string>();
            userInfo.Add("name", username.Text);
            userInfo.Add("password", passwd.Text);
            userInfo.Add("isAdmin", adminRights.Checked ? "yes" : "no");

            if (xmlAccess.AddUserNode(userInfo))
            {
                if (Session["SignedIn"] == null || (bool)Session["SignedIn"] == false)
                {
                    Session["SignedIn"] = true;
                    Session["UserName"] = username.Text;
                    Session["isAdmin"]  = adminRights.Checked;
                }
                resultsLabel.Text = "Success! Welcome to the Carrell Books family.";
            }
            else
            {
                resultsLabel.Text = "For some reason, we could not register you.";
            }
        }
        else
        {
            resultsLabel.Text = String.Format("User {0} already exists. Please choose a different name.", username.Text);
        }
    }
Ejemplo n.º 2
0
    protected void loginBtn_Click(object sender, EventArgs e)
    {
        resultLabel.Visible = false;
        XMLAccess xmlAccess = new XMLAccess();

        if (!xmlAccess.SearchUserNode(username.Text, password.Text))
        {
            resultLabel.Text    = "We couldn't find that person.";
            resultLabel.Visible = true;
            Session["SignedIn"] = false;
        }
        else
        {
            Session["SignedIn"] = true;
            Session["UserName"] = username.Text;

            Hashtable userInfo = xmlAccess.GetUserNode(username.Text);
            bool      isAdmin  = ("yes" == (string)userInfo["isAdmin"]) ? true : false;
            Session["isAdmin"] = isAdmin;

            if (isAdmin)
            {
                resultLabel.Text = String.Format("You are now signed in, {0}. Enjoy your stay, administrator!", username.Text);
            }
            else
            {
                resultLabel.Text = String.Format("You are now signed in, {0}. Enjoy your stay!", username.Text);
            }

            resultLabel.Visible = true;
        }
    }