Esempio n. 1
0
def Get(filterExpression=None):
    connection, cursor = basehandler.DbConnect()

    myQuery = "SELECT * FROM USER_DBT"

    if filterExpression is None:
        cursor = basehandler.DbExecute(myQuery, connection, cursor)
    else:
        myQuery += filterExpression.GetWhere()
        cursor = basehandler.DbExecute(myQuery, connection, cursor,
                                       filterExpression.GetParameters())

    userList = []

    for user in cursor.fetchall():
        tempUser = User()

        tempUser.userId = user[0]
        tempUser.firstName = user[1]
        tempUser.lastName = user[2]
        tempUser.username = user[3]
        tempUser.password = user[4]
        tempUser.email = user[5]
        tempUser.userType = user[6]

        userList.append(tempUser)

    basehandler.DbClose(connection, cursor)

    return userList
Esempio n. 2
0
def Register():
    if IsAuthenticated():
        return redirect('/')

    user = User()

    user.firstName = request.args.get('registerFirstName', "", type=STRING)
    user.lastName = request.args.get('registerLastName', "", type=STRING)
    user.username = request.args.get('registerUsername', "", type=STRING)
    user.email = request.args.get('registerEmail', "", type=STRING)
    user.password = request.args.get('registerPassword', "", type=STRING)
    user.userType = 2

    validationMessage = user.IsValid()

    if validationMessage != "":
        return jsonify(validationMessage)

    filterParameter = FilterParameter("USERUSERNAME", "LIKE", user.username)
    filterExpression = FilterExpression()
    filterExpression.AddParameter(filterParameter)
    users = userhandler.Get(filterExpression)

    if len(users) > 0:
        return jsonify("Username already exists")

    filterParameter = FilterParameter("USEREMAIL", "LIKE", user.email)
    filterExpression = FilterExpression()
    filterExpression.AddParameter(filterParameter)
    users = userhandler.Get(filterExpression)

    if len(users) > 0:
        return jsonify("Email already exists")

    user = userhandler.Insert(user)

    SetUserIdSession(user.userId)
    SetFullNameSession(user.firstName + " " + user.lastName)
    SetUsernameSession(user.username)

    return jsonify("")