parameters: ()
docstring: This router function attempts to register a new username. During its
      attempt, it returns a json string, with three possible values:
  
          - integer, codified indicator of registration attempt:
              - 0, successful account creation
              - 1, password doesn't meet minimum requirements
              - 2, username already exists in the database
              - 3, email already exists in the database
              - 4, internal database errors
          - username, string value of the user
          - email, is returned if the value already exists in the database, or
              the registration process was successful
function: def register():
      '''
  
      This router function attempts to register a new username. During its
      attempt, it returns a json string, with three possible values:
  
          - integer, codified indicator of registration attempt:
              - 0, successful account creation
              - 1, password doesn't meet minimum requirements
              - 2, username already exists in the database
              - 3, email already exists in the database
              - 4, internal database errors
          - username, string value of the user
          - email, is returned if the value already exists in the database, or
              the registration process was successful
  
      '''
  
      if request.method == 'POST':
          # local variables
          username = request.form.getlist('user[login]')[0]
          email = request.form.getlist('user[email]')[0]
          password = request.form.getlist('user[password]')[0]
          account = Account()
  
          # validate requirements: one letter, one number, and ten characters.
          if (password and validate_password(password)):
  
              # validate: unique username
              if (
                  username and
                  not account.check_username(username)['result']
              ):
  
                  # validate: unique email
                  if (
                      email and
                      isValidEmail(email) and
                      not account.check_email(email)['result']
                  ):
  
                      # database query: save username, and password
                      hashed = hash_pass(str(password))
                      result = Account().save_account(
                          username,
                          email,
                          hashed
                      )
  
                      # notification: attempt to store account
                      if result:
                          return json.dumps({
                              'status': 0,
                              'username': username,
                              'email': email
                          })
  
                      else:
                          return json.dumps({
                              'status': 4,
                              'username': username,
                          })
  
                  # notification: email already exists
                  else:
                      return json.dumps({
                          'status': 3,
                          'username': username,
                          'email': email
                      })
  
              # notification: account already exists
              else:
                  return json.dumps({
                      'status': 2,
                      'username': username
                  })
  
          # notification: password doesn't meet criteria
          else:
              return json.dumps({
                  'status': 1,
                  'username': username
              })
function_tokens: def register ( ) : if request . method == 'POST' : # local variables username = request . form . getlist ( 'user[login]' ) [ 0 ] email = request . form . getlist ( 'user[email]' ) [ 0 ] password = request . form . getlist ( 'user[password]' ) [ 0 ] account = Account ( ) # validate requirements: one letter, one number, and ten characters. if ( password and validate_password ( password ) ) : # validate: unique username if ( username and not account . check_username ( username ) [ 'result' ] ) : # validate: unique email if ( email and isValidEmail ( email ) and not account . check_email ( email ) [ 'result' ] ) : # database query: save username, and password hashed = hash_pass ( str ( password ) ) result = Account ( ) . save_account ( username , email , hashed ) # notification: attempt to store account if result : return json . dumps ( { 'status' : 0 , 'username' : username , 'email' : email } ) else : return json . dumps ( { 'status' : 4 , 'username' : username , } ) # notification: email already exists else : return json . dumps ( { 'status' : 3 , 'username' : username , 'email' : email } ) # notification: account already exists else : return json . dumps ( { 'status' : 2 , 'username' : username } ) # notification: password doesn't meet criteria else : return json . dumps ( { 'status' : 1 , 'username' : username } )