コード例 #1
0
    protected void btn_has_user_Click(object sender, EventArgs e)
    {
        UserRegistrationService.Service1Client proxy = new UserRegistrationService.Service1Client();

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

            //Set label to the apt response
            if (created)
            {
                Label2.Text      = "User found in Member.xml!";
                Label2.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                Label2.Text      = "User not found in Member.xml please register first!";
                Label2.ForeColor = System.Drawing.Color.Red;
            }
        }
        else
        {
            Label2.Text      = "Enter Valid Username and password!";
            Label2.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.hasUser(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("StaffCookieId");  // Clearing the cookies if required
                mycookies.Expires = DateTime.Now.AddMonths(-6);
                Response.Cookies.Add(mycookies);

                //HttpCookie mycookies = new HttpCookie("MemberCookieId");
                mycookies             = new HttpCookie("MemberCookieId");
                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["username"] = username_input.Text;   // Storing username is session so that it could be used in welcome page
                Session["role"]     = "2";
                Response.Redirect("~/Protected/Members.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;
            Error.Text = "Please fill in the username and password!";
        }
    }