示例#1
0
    protected void addUserBtn_Click(object sender, EventArgs e)
    {
        this.errorLabel.Visible = false;
        string   username = this.usernameTB.Text;
        string   email    = this.emailTB.Text;
        string   password = this.passwordTB.Text;
        bool     isAdmin  = this.isAdminCB.Checked;
        DateTime birthday = default(DateTime);

        try
        {
            birthday = DateTime.Parse(this.birthdayTB.Text);
        }
        catch
        {
            this.errorLabel.Text    = "Error!";
            this.errorLabel.Visible = true;
            return;
        }

        // Validate Data:
        localhost.UserValidationWS validationWS = new localhost.UserValidationWS();
        if (!validationWS.isUsernameValid(username))
        {
            this.errorLabel.Text    = validationWS.usernameLengthInvalidMessage();
            this.errorLabel.Visible = true;
            return;
        }
        if (!validationWS.isEmailLengthValid(email))
        {
            this.errorLabel.Text    = validationWS.emailLengthInvalidMessage();
            this.errorLabel.Visible = true;
            return;
        }
        if (!validationWS.isPasswordValid(password))
        {
            this.errorLabel.Text    = validationWS.passwordLengthInvalidMessage();
            this.errorLabel.Visible = true;
            return;
        }

        localhost.GigaGalleryWS dbWS = new localhost.GigaGalleryWS();
        try
        {
            dbWS.AdminAddUser(username, email, password, birthday, isAdmin);
        }
        catch
        {
            this.errorLabel.Text    = "Error!";
            this.errorLabel.Visible = true;
            return;
        }

        Response.Redirect(Page.Request.Url.ToString(), true);
    }
示例#2
0
    protected void submitBtnClick(object sender, EventArgs e)
    {
        string   username        = this.usernameTB.Text;
        string   email           = this.emailTB.Text;
        string   password        = this.passwordTB.Text;
        string   confirmPassword = this.passwordConfirmTB.Text;
        DateTime birthday        = default(DateTime);

        try
        {
            birthday = DateTime.Parse(this.birthdayTB.Text);
        }
        catch
        {
            this.birthdayErrorLabel.Text    = "Invalid birthday!";
            this.birthdayErrorLabel.Visible = true;
            return;
        }

        // Validate Data:
        localhost.UserValidationWS validationWS = new localhost.UserValidationWS();
        if (!validationWS.isUsernameValid(username))
        {
            this.usernameErrorLabel.Text    = validationWS.usernameLengthInvalidMessage();
            this.usernameErrorLabel.Visible = true;
            return;
        }
        if (!validationWS.isEmailLengthValid(email))
        {
            this.emailErrorLabel.Text    = validationWS.emailLengthInvalidMessage();
            this.emailErrorLabel.Visible = true;
            return;
        }
        if (!validationWS.isPasswordValid(password))
        {
            this.passwordErrorLabel.Text    = validationWS.passwordLengthInvalidMessage();
            this.passwordErrorLabel.Visible = true;
            return;
        }
        if (password != confirmPassword)
        {
            this.passwordErrorLabel.Text    = "Passwords do not match!";
            this.passwordErrorLabel.Visible = true;
            return;
        }

        localhost.GigaGalleryWS dbWS = new localhost.GigaGalleryWS();
        bool result = false;

        try
        {
            result = dbWS.Signup(username, email, password, birthday);
        }
        catch
        {
            this.errorLabel.Text    = "Error!";
            this.errorLabel.Visible = true;
            return;
        }

        if (result)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            this.errorLabel.Text    = "Error!";
            this.errorLabel.Visible = true;
            return;
        }
    }