Ejemplo n.º 1
0
def UpdateUser():
    if not IsAuthenticated():
        return redirect('/')

    try:
        user = User()

        user.firstName = request.args.get('usersettings_firstName',
                                          "",
                                          type=STRING)
        user.lastName = request.args.get('usersettings_lastName',
                                         "",
                                         type=STRING)
        user.username = request.args.get('usersettings_username',
                                         "",
                                         type=STRING)
        user.email = request.args.get('usersettings_email', "", type=STRING)
        user.password = request.args.get('usersettings_password',
                                         "",
                                         type=STRING)

        user.userId = GetUserIdSession()

        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 and users[0].userId != GetUserIdSession():
            return jsonify("This username is already taken")

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

        if len(users) > 0 and users[0].userId != GetUserIdSession():
            return jsonify("This e-mail address is already taken")

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

        return jsonify("")
    except:
        return jsonify("Unexpected error occured")
Ejemplo 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("")