Skip to content

You are a junior developer working in a small start-up. Your managers have asked you to develop a new account registration system for a mobile app. The system must validate user input on the sign-up form before creating an account.

The previous junior developer wrote some helper functions that validate the name, email, and password. Use these functions to register users, store their data, and implement some error handling! These have been imported into the workspace for you. They will be a great help to you when registering the user, but first you have to understand what the function does! Inspect the docstrings of each of the helper functions: validate_name, validate_email and validate_password.

Hidden code
# Taking a look at the pre-defined helper functions
import inspect
print (inspect.getsource(validate_name))
print(inspect.getsource(validate_email))
print(inspect.getsource(validate_password))
# Creating validate_user function - short version

def validate_user_1 (name, email, password):
    if validate_name(name) and validate_email(email) and validate_password(password):       
      return True
    else: 
      raise ValueError("Invalid user input")
# Validate_function - long version

def validate_user(name, email, password):
    if not validate_name(name):
        raise ValueError("Invalid name: must be a string longer than 2 characters.")
    if not validate_email(email):
        raise ValueError("Invalid email: the email must have a username greater than 1 character, an '@' symbol, and an allowed domain that is in the `top_level_domains` variable.")
    if not validate_password(password):
        raise ValueError("Invalid password: the password should include a capital letter, a number between 0-9 and be greater than 8 characters.")
    return True
# Creating register_uer function
def register_user(name, email, password):
    try:
        validate_user(name, email, password)
    except ValueError:
        return False
        
    return{"name": name,
          "email": email,
          "password":password}