protected void Page_Load(object sender, EventArgs e)
        {
            Classes.User objUser = new Classes.User();

            try
            {
                string activationCode = Request["code"].ToString();
                string email = Request["email"].ToString();

                if (objUser.getActivationCode(email) == activationCode)
                {
                    objUser.setStatus(email, "Active");
                    litError.Text = "Your account is successfully activated";

                }

                else
                    litError.Text = "Invalid Account Activation Information Provided";

                objUser.close();

            }
            catch(Exception ex)
            {
                litError.Text = "Invalid Account Activation Information Provided";
                objUser.close();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Classes.Auth objAuth = new Classes.Auth();
            objAuth.isLoggedIn();

            if (IsPostBack)
                return;

            Classes.User objUser = new Classes.User();

            try
            {
                SqlDataReader userData = objUser.getUser("email", Session["username"].ToString());

                if (userData != null)
                {
                    userData.Read();
                    litEmail.Text = userData["email"].ToString();
                    txtName.Text = userData["name"].ToString();
                    txtMobile.Text = userData["mobile"].ToString();
                }
            }

            catch (Exception ex)
            {

            }

            objUser.close();
        }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            Classes.Validation objValidate = new Classes.Validation();
            bool error = false;
            litError.Text = "";

            if (!objValidate.isValidName(txtName.Text.ToString()))
            {
                error = true;
                litError.Text += "Invalid Name<br>";
            }

            if (!objValidate.isValidEmail(txtEmail.Text.ToString()))
            {
                error = true;
                litError.Text += "Invalid Email Address<br>";
            }

            if (!objValidate.isValidPassword(txtPassword.Text.ToString()))
            {
                error = true;
                litError.Text += "Invalid Password<br>";
            }

            if (txtPassword.Text.ToString() != txtRePassword.Text.ToString())
            {
                error = true;
                litError.Text += "Passwords do not match<br>";
            }

            if (error)
                return;

            Classes.User objUser = new Classes.User();

            if (objUser.addUser(txtName.Text.ToString(), txtEmail.Text.ToString(), txtPassword.Text.ToString(), null, "Customer"))
            {
                string activationCode = objUser.getActivationCode(txtEmail.Text.ToString());

                string activationLink = "http://" + Request.Url.Authority + "/Account/Activate.aspx?code=" + activationCode + "&email=" + txtEmail.Text.ToString(); ;

                string activationMessage = "Hello " + txtName.Text.ToString() + ",<br><br>";
                activationMessage += "Please activate your account by clicking on the link:<br><br>";
                activationMessage += activationLink;

                Classes.Mail objMail = new Classes.Mail(txtEmail.Text.ToString(), "eShopee Account Activation", activationMessage);

                litError.Text = "You are successfully registered";

            }

            else
                litError.Text = "Your account could not be registered";

            objUser.close();
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Classes.User objUser = new Classes.User();
            Classes.Cryptography objCrypto = new Classes.Cryptography();
            Classes.Validation objValidate = new Classes.Validation();

            try
            {
                string email = Session["username"].ToString();
                string oldPassword = txtOldPassword.Text.ToString();
                string newPassword = txtNewPassword.Text.ToString();
                bool error = false;

                if (objUser.getPassword(email) != objCrypto.genPassHash(oldPassword))
                {
                    error = true;
                    litError.Text += "Incorrect Old Password<br>";
                }

                if (!objValidate.isValidPassword(newPassword))
                {
                    error = true;
                    litError.Text = "Invalid New Password";
                }

                if (newPassword != txtConfNewPassword.Text.ToString())
                {
                    error = true;
                    litError.Text = "Passwords Do Not Match";
                }

                if (error)
                    return;

                if (objUser.setPassword(email, newPassword))
                {
                    litError.Text = "Password Updated Successfully";
                }
            }

            catch (Exception ex)
            {
                litError.Text = "Password Could Not Be Updated";
            }

            objUser.close();
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Classes.User objUser = new Classes.User();

            try
            {
                string email = Session["username"].ToString();
                string name = txtName.Text.ToString();
                string mobile = txtMobile.Text.ToString();

                Classes.Validation objValidate = new Classes.Validation();
                bool error = false;
                litError.Text = "";

                if (!objValidate.isValidName(name))
                {
                    error = true;
                    litError.Text = "Invalid Name";
                }

                if (error)
                    return;

                if (objUser.setUser(name, email, mobile))
                {
                    litError.Text = "Account Updated Successfully";
                }

            }

            catch (Exception ex)
            {
                litError.Text = "Account Could Not be Updated";
            }

            objUser.close();
        }