protected void btn_register_Click(object sender, EventArgs e)
 {
     //save to xml file --> using our service
     try
     {
         UserRegistrationService.Service1Client client = new UserRegistrationService.Service1Client();
         Boolean response = client.registerUser(UserInput.Text, Class1.Encrypt(PasswordInput.Text));  // Adding the user by manipulating XML file
         if (response.Equals(true))
         {
             //  Error.Text = "User has been registered Successfully!";
             Session["registration"] = "success";
             Response.Redirect("MemberLogin.aspx");
         }
         else if (response.Equals(false))
         {
             Error.Text = "Username already exist! Provide a new username";
         }
         else
         {
             Error.Text = "Username or password is incorrect!!";
             //Error.Text = response;
         }
         //}
     }
     catch (Exception e1)
     {
         Error.Text = e1.Message;
     }
 }
    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;
        }
    }
    protected void btn_register_staff_Click(object sender, EventArgs e)
    {
        UserRegistrationService.Service1Client proxy = new UserRegistrationService.Service1Client();

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

            //Set label to the apt response
            if (created)
            {
                Label3.Text      = "User successfully Registered in Staff.xml!";
                Label3.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                Label3.Text      = "User already registered in Staff.xml!";
                Label3.ForeColor = System.Drawing.Color.Red;
            }
        }
        else
        {
            Label3.Text      = "Enter Valid Username and password!";
            Label3.ForeColor = System.Drawing.Color.Red;
        }
    }
示例#4
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!";
        }
    }