Exemplo n.º 1
0
def validateSignup(**raw):
  """Validates the signup form input

  Validates the input from the signup form using the regex defined in settings

  Args:
    **raw: Collects all the named arguments

  Returns:
    A tuple containing:
      - Boolean: Whether there was an error or not
      - dict(): Containing the original params and the generated error params
  """
  error = False
  params = { 'username': raw['username'], 'email': raw['email'] }
  
  if not utils.validateUsername(raw['username']):
    params['error_username'] = settings.RE_USERNAME_FAIL
    error = True
  
  if not utils.validatePassword(raw['password']):
    params['error_password'] = settings.RE_PASSWORD_FAIL
    error = True
  elif raw['password'] != raw['verify']:
    params['error_verify'] = settings.RE_PASSWORD_MATCH
    error = True
  
  if not utils.validateEmail(raw['email']):
    params['error_email'] =  settings.RE_EMAIL_FAIL
    error = True
  
  return (error, params)
Exemplo n.º 2
0
def room_exists():
    r = request.args.get('r','')
    p = request.args.get('p','')
    exists = roomExists(r)
    if not exists:
        return jsonify(result = 'DNE')
    
    passvalid = validatePassword(r,p)
    if not passvalid:
        return jsonify(result = 'INVALID')
    else:
        return jsonify(result = 'OK')
Exemplo n.º 3
0
def createUser(dbCursor, connection):
    if db.getNumUsers(
            dbCursor
    ) >= constants.MAX_USER_ACCOUNTS:  # checks if number of accounts in database is at max limit
        print(
            "All permitted accounts have been created, please come back later")
        settings.currentState = states.loggedOut  # returns to main() w/ currentState = loggedOut
        return

    print(
        "Enter desired account credentials, or only press enter at any time to cancel account creation."
    )
    uname = input("Enter your desired username: "******"":
        print("Account creation canceled.")
        settings.currentState = states.loggedOut
        return

    while db.getUserByName(dbCursor, uname):
        print("Sorry, that username has already been taken.")
        uname = input("Enter your desired username: "******"":
            print("Account creation canceled.")
            settings.currentState = states.loggedOut
            return

    pword = input("Enter your desired password: "******"":
        print("Account creation canceled.")
        settings.currentState = states.loggedOut
        return

    while not utils.validatePassword(pword):
        print(
            "Invalid password. Must be length 8-12 characters, contain one digit, one uppercase character, and one non-alphanumeric."
        )
        pword = input("Enter your desired password: "******"":
            print("Account creation canceled.")
            settings.currentState = states.loggedOut
            return

    fname = input("Enter your first name: ")
    if fname == "":
        print("Account creation canceled.")
        settings.currentState = states.loggedOut
        return

    lname = input("Enter your last name: ")
    if lname == "":
        print("Account creation canceled.")
        settings.currentState = states.loggedOut
        return

    plusMember = input(
        "Sign up for InCollege-Plus membership? (Enter Y for Plus, N for Standard): "
    )
    while True:
        if plusMember.upper() == "Y":
            plusMember = 1
            break
        elif plusMember.upper() == "N":
            plusMember = 0
            break
        else:
            print(constants.INVALID_INPUT)
            plusMember = input(
                "Sign up for InCollege-Plus membership? (Enter Y for Plus, N for Standard): "
            )

    today = date.today()  # Get today's date
    date_format = "%m/%d/%Y"
    todayDate = today.strftime(date_format)  # Format date mm/dd/yyyy
    currentDate = datetime.strptime(todayDate,
                                    date_format)  # Today's date as a string

    db.insertUser(dbCursor, uname, pword, fname, lname, plusMember,
                  currentDate)
    db.insertUserSettings(dbCursor, uname, settings.emailNotif,
                          settings.smsNotif, settings.targetAdvert,
                          settings.language)
    db.insertProfilePage(dbCursor, uname, "", "", "")

    # add notification to let other users know a new student has joined
    other_users = db.getAllOtherUsers(dbCursor, uname)
    if len(other_users) > 0:
        for user in other_users:
            db.insertNotification(dbCursor, "new_student", fname + " " + lname,
                                  user[0])

    connection.commit(
    )  # commits the new account and settings to the database (ensures account and settings are saved)
    API.outputUsers(dbCursor)
    API.outputProfiles(dbCursor)

    settings.currentState = states.loggedOut  # returns to main() w/ currentState = loggedOut

    print("Account has been created.")
Exemplo n.º 4
0
def testValidatePasswordIncorrect(password):
    assert not utils.validatePassword(password)
Exemplo n.º 5
0
def testValidatePasswordCorrect():
    assert utils.validatePassword("Testing123!")