def addAdminSettings(form, companyName):
    passLength = form.plength.data
    requireCaps = form.caps.data
    requireLow = form.lowercase.data
    requireNum = form.numeric.data
    requireSpec = form.special.data
    expDays = form.expiration.data

    mySettings = Admin_Setting(company_name=companyName,
                               password_length=passLength,
                               require_caps=requireCaps,
                               require_lowercase=requireLow,
                               require_number=requireNum,
                               require_special=requireSpec,
                               expiration_days=expDays)
    mysession.add(mySettings)
    mysession.commit()
def addUser(user, password):
    today = datetime(1996, 1, 2, 3, 4, 5)
    userName = user[0]
    userCurrPass = password
    adminStatus = (user[4] == 'admin')
    userEmail = user[1]
    userCompany = user[2]
    userPhone = user[3]
    userLastSet = today
    userLastLogin = today
    userCurrPass = hashPassword(userCurrPass)

    myUser = User(name=userName,
                  current_password=userCurrPass,
                  is_admin=adminStatus,
                  email=userEmail,
                  company_name=userCompany,
                  phone_number=userPhone,
                  password_last_set=userLastSet,
                  token=None,
                  last_login=userLastLogin)
    mysession.add(myUser)
    mysession.commit()
def checkWithOldPasswordsAndUpdateChange(request):
    email = request.form['email']
    password = request.form['password']
    oldPassword = request.form['oldPassword']
    oldPasswords = mysession.query(Old_Password).filter_by(
        userEmail=email).all()
    oldPasswordsArr = []
    for i in oldPasswords:
        oldPasswordsArr.append(i.hashed_password)

    responseArray = newPasswordToOldPasswordComparison(password, oldPassword,
                                                       oldPasswordsArr)
    if (responseArray[0]):
        newHashedPassword = responseArray[1]
        mysession.query(User).filter_by(email=email).update(
            {"current_password": newHashedPassword})
        oldPassword = hashPassword(oldPassword)
        newRow = Old_Password(userEmail=email, hashed_password=oldPassword)
        mysession.add(newRow)
        mysession.commit()
        return True
    else:
        return False