def validate_customer(cls, new_customer_data):
     is_valid = True
     if len(new_customer_data["first_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_customer_data["first_name"]):
         is_valid = False
         flash("Please enter a valid first name.")
     if len(new_customer_data["last_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_customer_data["last_name"]):
         is_valid = False
         flash(
             "Please enter a valid last name. Must be between 3-20 characters in length and contain no numbers or special characters."
         )
     if len(new_customer_data["email"]) < 1 or not re.search(
             "[^@]+@[^@]+\.[^@]+", new_customer_data["email"]):
         is_valid = False
         flash("Please enter a valid email address.")
     if len(new_customer_data["phone_number"]) < 1 or not re.search(
             "^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$",
             new_customer_data["phone_number"]):
         is_valid = False
         flash("Please enter a valid phone number.")
     if len(new_customer_data["password"]) < 8:
         is_valid = False
         flash(
             "Password should be at least 8 characters and contain one number and uppercase letter"
         )
     if new_customer_data["confirm_password"] != new_customer_data[
             "password"]:
         is_valid = False
         flash("Passwords do not match!")
     return is_valid
Exemple #2
0
 def validate_dog(cls, new_dog_data):
     is_valid = True
     if len(new_dog_data["dog_name"]) < 1:
         is_valid = False
         flash("Please enter a valid dog name.")
     if len(new_dog_data["breed"]) < 1:
         is_valid = False
         flash("Please enter a valid breed.")
     if len(new_dog_data["age"]) < 0:
         is_valid = False
         flash("Please enter a valid dog age.")
     if len(new_dog_data["eye_color"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_dog_data["eye_color"]):
         is_valid = False
         flash("Please enter a valid dog eye color.")
     if len(new_dog_data["fur_color"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_dog_data["fur_color"]):
         is_valid = False
         flash("Please enter a valid dog fur color.")
     if len(new_dog_data["fur_type"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_dog_data["fur_type"]):
         is_valid = False
         flash("Please enter a valid fur type.")
     if len(new_dog_data["allergies"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_dog_data["allergies"]):
         is_valid = False
         flash("Please enter a valid dog allergies.")
     if len(new_dog_data["brief_bio"]) < 1 or len(
             new_dog_data["brief_bio"]) > 255:
         is_valid = False
         flash("Please enter a valid dog bio.")
     return is_valid
def addUser(user_name, email, password, confirm):
    user_added = False
    if len(user_name) == 0:
        flash("Please enter user name.")
    elif not EMAIL_REGEX.match(
            email):  # test whether a field matches the pattern
        flash("Invalid email address.")
    elif not re.search(PWD_REGEX, password):
        flash(
            "Password must be 6-20 characters and contain one or more of each of: a number, uppercase letter, lower case letter, and special symbol."
        )
    elif password != confirm:
        flash("Password confirmation does not match.")
    else:
        # check if email address already exists
        result = User.query.filter_by(email=email).first()
        if result:
            flash("Account already exists.")
        else:
            # add new member
            new_user = User(user_name=user_name,
                            email=email,
                            password=bcrypt.generate_password_hash(password),
                            balance=starting_balance,
                            current_game_id=None)
            db.session.add(new_user)
            db.session.commit()
            flash("New user added.")
            user_added = True
    return user_added
Exemple #4
0
 def validate_edit_user(cls, edit_user_data):
     is_valid = True
     if len(edit_user_data["edit_first_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", edit_user_data["edit_first_name"]):
         is_valid = False
         flash("Please enter a valid first name.")
     if len(edit_user_data["edit_last_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", edit_user_data["edit_last_name"]):
         is_valid = False
         flash("Please enter a valid last name.")
     if len(edit_user_data["edit_email"]) < 1 or (
             edit_user_data["edit_email"]
             == edit_user_data["edit_email"]) or not re.search(
                 "[^@]+@[^@]+\.[^@]+", edit_user_data["edit_email"]):
         is_valid = False
     return is_valid
 def validate_edit_customer(cls, new_customer_data):
     is_valid = True
     if len(new_customer_data["first_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_customer_data["first_name"]):
         is_valid = False
         flash("Please enter a valid first name.")
     if len(new_customer_data["last_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_customer_data["last_name"]):
         is_valid = False
         flash(
             "Please enter a valid last name. Must be between 3-20 characters in length and contain no numbers or special characters."
         )
     if len(new_customer_data["phone_number"]) < 1 or not re.search(
             "^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$",
             new_customer_data["phone_number"]):
         is_valid = False
         flash("Please enter a valid phone number.")
     return is_valid
 def validate_billing(cls, new_billing_data):
     is_valid = True
     if len(new_billing_data["street"]) < 1 or not re.search(
             "^[#.0-9a-zA-Z\s,-]+$", new_billing_data["street"]):
         is_valid = False
         flash("Please enter a valid street address.")
     if len(new_billing_data["city"]) < 1 or not re.search(
             "^[a-zA-Z',.\s-]{1,25}$", new_billing_data["city"]):
         is_valid = False
         flash("Please enter a valid city.")
     if len(new_billing_data["state"]) < 1 or not re.search(
             "^[a-zA-Z',.\s-]{1,25}$", new_billing_data["state"]):
         is_valid = False
         flash("Please enter a state.")
     if len(new_billing_data["zipcode"]) < 1 or not re.search(
             "^\d{5}(?:[-\s]\d{4})?$", new_billing_data["zipcode"]):
         is_valid = False
         flash("Please enter a valid zipcode.")
     return is_valid
Exemple #7
0
 def validate_user(cls, new_user_data):
     is_valid = True
     if len(new_user_data["first_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_user_data["first_name"]):
         is_valid = False
         flash("Please enter a valid first name.")
     if len(new_user_data["last_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_user_data["last_name"]):
         is_valid = False
         flash("Please enter a valid last name.")
     if len(new_user_data["email"]) < 1 or not re.search(
             "[^@]+@[^@]+\.[^@]+", new_user_data["email"]):
         is_valid = False
         flash(
             "Please enter a valid email address containing @ AND . followed by com/org/etc."
         )
     if len(new_user_data["password"]) < 8:
         is_valid = False
         flash("Password should be at least 8 characters.")
     if new_user_data["confirm_password"] != new_user_data["password"]:
         is_valid = False
         flash("Passwords do not match!")
     return is_valid
Exemple #8
0
 def validate_user(cls, new_user_data):
     is_valid = True
     if len(new_user_data["first_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_user_data["first_name"]):
         is_valid = False
         flash("Please enter a valid first name.")
     if len(new_user_data["last_name"]) < 1 or re.search(
             "[^a-zA-ZäöüßÄÖÜ]", new_user_data["last_name"]):
         is_valid = False
         flash(
             "Please enter a valid last name. Must be between 3-20 characters in length and contain no numbers or special characters."
         )
     if len(new_user_data["email"]) < 1 or not re.search(
             "[^@]+@[^@]+\.[^@]+", new_user_data["email"]):
         is_valid = False
         flash(
             "Please enter a valid email address containing @ AND . followed by com/org/etc."
         )
     if len(new_user_data["phone_number"]) < 1 or not re.search(
             "^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$",
             new_user_data["phone_number"]):
         is_valid = False
         flash("Please enter a valid phone number.")
     if new_user_data["confirm_password"] != new_user_data["password"]:
         is_valid = False
         flash("Passwords do not match!")
     try:
         birthday = datetime.strptime(new_user_data["birthday"], "%Y-%m-%d")
         diff = datetime.now() - birthday
         if int(diff.total_seconds()) < 56764800:
             is_valid = False
             flash("You must be 18 years old or older to register!")
     except:
         is_valid = False
         flash("Please enter a valid birthday.")
     return is_valid