protected void btn_has_staff_Click(object sender, EventArgs e)
    {
        UserRegistrationService.Service1Client proxy = new UserRegistrationService.Service1Client();

        //Ensure entry not null
        if (!String.IsNullOrWhiteSpace(txt_has_staffuser.Text) && !String.IsNullOrWhiteSpace(txt_has_staffpass.Text))
        {
            //Call the operation to register
            Boolean created = proxy.hasStaff(txt_has_staffuser.Text, Class1.Encrypt(txt_has_staffpass.Text));

            //Set label to the apt response
            if (created)
            {
                Label4.Text      = "User found in Staff.xml!";
                Label4.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                Label4.Text      = "User not found in Staff.xml please register first!";
                Label4.ForeColor = System.Drawing.Color.Red;
            }
        }
        else
        {
            Label4.Text      = "Enter Valid Username and password!";
            Label4.ForeColor = System.Drawing.Color.Red;
        }
    }
예제 #2
0
    protected void btn_login_Click(object sender, EventArgs e)
    {
        try
        {
            UserRegistrationService.Service1Client client = new UserRegistrationService.Service1Client();
            bool response = client.hasStaff(username_input.Text, Class1.Encrypt(passsword_input.Text));  // Check whether user and password are correct by searching in users.xml file
            if (response.Equals(true))
            {
                HttpCookie mycookies = new HttpCookie("MemberCookieId");  // Clearing the cookies if required
                mycookies.Expires = DateTime.Now.AddMonths(-6);
                Response.Cookies.Add(mycookies);

                //HttpCookie mycookies = new HttpCookie("MemberCookieId");
                mycookies             = new HttpCookie("StaffCookieId");
                mycookies["Name"]     = username_input.Text;        // Store username and password in cookies
                mycookies["Password"] = Class1.Encrypt(passsword_input.Text);
                mycookies.Expires     = DateTime.Now.AddMonths(6);
                Response.Cookies.Add(mycookies);
                Session["staffname"] = username_input.Text;   // Storing username is session so that it could be used in welcome page
                Session["role"]      = "3";
                Response.Redirect("~/Protected/Staff.aspx");
            }
            else if (response.Equals(false))
            {
                Error.Text = "User does not exist. Please register first.";
            }
            else
            {
                Error.Text = response.ToString();
            }
        }

        catch (Exception e1)
        {
            Error.Text = e1.Message;
        }
    }