Exemple #1
0
def handleFacebookUser():
    fb_response = request.json.get(Labels.FbResponse)
    guest_jwt = request.json.get(Labels.Jwt)
    guest_user = JwtUtil.getUserInfoFromJwt(guest_jwt)
    fb_id = fb_response.get(Labels.Id)
    if fb_id == None:
        return JsonUtil.failure()

    fb_user = User.query.filter_by(fb_id=fb_response.get(Labels.Id)).first()

    # if the fb_user already has an account
    if fb_user:
        fb_user.transferGuestCart(guest_user)
        user_jwt = JwtUtil.create_jwt(fb_user.toJwtDict())
        user_info = fb_user.toPublicDictFast()
        output = {Labels.User: user_info, Labels.Jwt: user_jwt}
        return JsonUtil.successWithOutput(output)

    register_user_response = User.registerFacebookUser(fb_response, guest_user)
    if register_user_response.get(Labels.Success):
        register_user_response[Labels.Jwt] = JwtUtil.create_jwt(
            register_user_response[Labels.Jwt])
        return JsonUtil.successWithOutput(register_user_response)
    else:
        return JsonUtil.failureWithOutput(register_user_response)
    return JsonUtil.failure()
Exemple #2
0
def checkoutCart(this_user):
    card_id = request.json.get(Labels.CardId)
    address_id = request.json.get(Labels.AddressId)
    checkout_cart_response = Checkout.checkoutCart(this_user, card_id,
                                                   address_id)
    if checkout_cart_response.get(Labels.Success):
        return JsonUtil.successWithOutput(checkout_cart_response)
    else:
        return JsonUtil.failureWithOutput(checkout_cart_response)
Exemple #3
0
def updateCartQuantity(this_user):
    this_cart_item = request.json.get(Labels.CartItem)
    product_id = this_cart_item.get(Labels.ProductId)
    new_num_items = int(request.json.get(Labels.NewNumItems))
    this_product = MarketProduct.query.filter_by(product_id=product_id).first()
    update_cart_quantity_response = Checkout.updateCartQuantity(
        this_user, this_product, this_cart_item, new_num_items)
    if update_cart_quantity_response.get(Labels.Success):
        return JsonUtil.successWithOutput(update_cart_quantity_response)
    else:
        return JsonUtil.failureWithOutput(update_cart_quantity_response)
Exemple #4
0
def addItemToCart(this_user):
    product_id = request.json.get(Labels.ProductId)
    quantity = int(request.json.get(Labels.Quantity))
    variant = request.json.get(Labels.Variant)
    if variant:
        variant_id = variant.get(Labels.VariantId)
    else:
        variant_id = None
    add_to_cart_response = this_user.addItemToCart(product_id, quantity,
                                                   variant_id)
    if add_to_cart_response.get(Labels.Success):
        return JsonUtil.successWithOutput(add_to_cart_response)
    else:
        return JsonUtil.failureWithOutput(add_to_cart_response)
Exemple #5
0
def registerUserAccount():
    name = request.json.get(Labels.Name)
    email_input = request.json.get(Labels.Email)
    password = request.json.get(Labels.Password)
    password_confirm = request.json.get(Labels.PasswordConfirm)
    guest_jwt = request.json.get(Labels.GuestJwt)
    guest_user = JwtUtil.getUserInfoFromJwt(guest_jwt)
    register_user_response = User.registerUser(name, email_input, password,
                                               password_confirm, guest_user)
    if register_user_response.get(Labels.Success):
        register_user_response[Labels.Jwt] = JwtUtil.create_jwt(
            register_user_response[Labels.Jwt])
        return JsonUtil.successWithOutput(register_user_response)
    else:
        return JsonUtil.failureWithOutput(register_user_response)
Exemple #6
0
def addUserAddress(this_user):
    name = request.json.get(Labels.AddressName)
    description = request.json.get(Labels.Description)
    address_city = request.json.get(Labels.AddressCity)
    address_country = request.json.get(Labels.AddressCountry)
    address_line1 = request.json.get(Labels.AddressLine1)
    address_line2 = request.json.get(Labels.AddressLine2)
    address_zip = request.json.get(Labels.AddressZip)
    address_state = request.json.get(Labels.AddressState)

    add_address_response = this_user.addAddress(description, name,
                                                address_line1, address_line2,
                                                address_city, address_state,
                                                address_zip, address_country)
    if add_address_response.get(Labels.Success):
        return JsonUtil.successWithOutput(add_address_response)
    else:
        return JsonUtil.failureWithOutput(add_address_response)
Exemple #7
0
def addCreditCard(this_user):
    name = request.json.get(Labels.Name)
    address_city = request.json.get(Labels.AddressCity)
    address_country = request.json.get(Labels.AddressCountry)
    address_line1 = request.json.get(Labels.AddressLine1)
    address_line2 = request.json.get(Labels.AddressLine2)
    address_state = request.json.get(Labels.AddressState)
    address_zip = request.json.get(Labels.AddressZip)
    exp_month = request.json.get(Labels.ExpMonth)
    exp_year = request.json.get(Labels.ExpYear)
    number = request.json.get(Labels.Number)
    cvc = request.json.get(Labels.Cvc)
    add_card_response = this_user.addCreditCard(address_city, address_line1,
                                                address_line2, address_zip,
                                                exp_month, exp_year, number,
                                                cvc, name, address_state,
                                                address_country)

    if add_card_response.get(Labels.Success):
        return JsonUtil.successWithOutput(add_card_response)
    else:
        return JsonUtil.failureWithOutput(add_card_response)