protected void btnLogin_Click(object sender, EventArgs e) { v.SetUser(new User(txtEmail.Text, txtPassword.Text)); try { bool userValid = v.UserValid(); if (userValid) { Int32 userId = Database.UserId(v.GetUser()); userInfo["isAuth"] = "true"; userInfo["userId"] = userId.ToString(); userInfo.Expires = DateTime.Now.AddMinutes(10); if (userId == 0) { throw new Exception("This user does not exist"); } Response.Cookies.Add(userInfo); Response.Redirect("Home.aspx"); } else { throw new Exception("Please enter a valid Email/Password"); } } catch (Exception ex) { alertBody.Text = "<div ID=\"alert\" class=\"alert alert-danger\">" + ex.Message + "</div>"; } }
protected void btnCreateAccount_Click(object sender, EventArgs e) { bool valid = false; user = new User(txtUsername.Text, txtPassword.Text); user.SetFirstName(txtFirstName.Text); user.SetLastName(txtLastName.Text); user.SetEmail(txtEmail.Text); Address address = new Address(txtAdress1.Text, txtAdress2.Text, txtCity.Text, txtState.Text, txtZipCode.Text); user.SetAddress(address); InputTypes[] totalTypes = { InputTypes.Username, InputTypes.FirstName, InputTypes.LastName, InputTypes.Email, InputTypes.FullAddress, InputTypes.Password, InputTypes.ConfirmPassword }; v.SetUser(user); foreach (InputTypes type in totalTypes) { valid = v.IsValid(type); if (!valid) { error.Add(type); } } if (valid && error.Count == 0) { Response.Redirect("Home.aspx"); } else { //TODO: v.HandleErrors(error); } }
protected void btnLogin_Click(object sender, EventArgs e) { v.SetUser(new User(txtUsername.Text, txtPassword.Text)); bool userNameValid = v.IsValid(InputTypes.Username); bool passwordValid = v.IsValid(InputTypes.Password); if (userNameValid && passwordValid) { Response.Redirect("Home.aspx"); } else { lblPasswordError.Text = "Please enter a valid Username/Password"; } }