Ejemplo n.º 1
0
def storepwd(request):
    username = request.POST['username']
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, _, picture, _, _ = parse_user(response)
    
    password = make_password(request.POST['password'])
    data = {'username': username, 'email': email, 'password':password, 'picture':picture, 'code':"0", 'verified':"1"}
    response = make_query(dbhost + "set_user/", data)
    return HttpResponseRedirect(reverse(index))
Ejemplo n.º 2
0
def profile(request):
    if 'username' not in request.session:
        return HttpResponseRedirect(reverse(index))
    
    username = request.session['username']
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, _, picture, _, _ = parse_user(response)
    
    if picture is None:
        picture = "profilepic/default.jpg"
    if picture == "None":
        picture = "profilepic/default.jpg"
    
    data = { 'username': username, 'delivstatus': "Pending"}
    response = make_query(dbhost + "get_orders/", data)
    orders = parse_orders(response)
    
    pending = list()
    for order in orders:
        dct = dict()
        dct['duedate'] = order['duedate']
        dct['productid'] = order['productid']
        dct['count'] = order['count']
        dct['amount'] = order['amount']
        dct['paymentmethod'] = order['paymentmethod']
        if 'paymentinfo' in order:
            dct['paymentinfo'] = order['paymentinfo']
        dct['contactno'] = order['contactno']
        dct['address'] = order['address']
        pending.append(dct)
    
    data = { 'username': username, 'delivstatus': "Done"}
    response = make_query(dbhost + "get_orders/", data)
    orders = parse_orders(response)
    
    history = list()
    for order in orders:
        dct = dict()
        dct['duedate'] = order['duedate']
        dct['productid'] = order['productid']
        dct['count'] = order['count']
        dct['amount'] = order['amount']
        dct['paymentmethod'] = order['paymentmethod']
        if 'paymentinfo' in order:
            dct['paymentinfo'] = order['paymentinfo']
        dct['contactno'] = order['contactno']
        dct['address'] = order['address']
        history.append(dct)
    
    
    data = { 'username': username, 'email': email, 'picture': picture, 'pending':pending, 'history':history}
    return render(request, 'profile.html', data)
Ejemplo n.º 3
0
def product(request):

    if 'productid' not in request.GET:
        return HttpResponseRedirect(reverse(shop))

    data = {'productid': request.GET['productid']}
    product = make_query(dbhost + "get_product/", data)
    product = parse_product(product)

    dct = dict()
    # productid, name, category, price, count, discount, details, image, sold
    dct["productid"] = product["productid"]
    dct["name"] = product["name"]
    dct["category"] = product["category"]
    dct["discprice"] = float(
        product["price"]) * (100.0 - float(product["discount"])) / 100.0
    if dct["discprice"] != float(product["price"]):
        dct["origprice"] = product["price"]
    dct["details"] = product["details"]
    dct["image"] = product["image"]

    reviews = make_query(dbhost + "get_reviews/", data)
    reviews = parse_reviews(reviews)

    rating = 0.0
    cnt = 0.0
    data = list()
    for review in reviews:
        dct2 = dict()
        dct2["productid"] = review["productid"]
        dct2["username"] = review["username"]

        temp = {'username': review["username"]}
        response = make_query(dbhost + "get_user/", temp)
        _, _, _, picture, _, _ = parse_user(response)
        dct2["image"] = picture

        dct2["reviewid"] = review["reviewid"]
        dct2["rating"] = review["rating"]
        rating += float(review["rating"])
        cnt += 1.0
        dct2["details"] = review["details"]
        data.append(dct2)

    if cnt > 0:
        rating = rating / cnt

    dct['rating'] = str(rating)

    return render(request, "product.html", {'product': dct, 'reviews': data})
Ejemplo n.º 4
0
def pwdreset(request):
    code = request.GET['code']
    if(code =="0"):
        return HttpResponseRedirect(reverse(enter))
    
    data = { 'code': code }
    response = make_query(dbhost + "get_user_by_code/", data)
    username, _, _, _, _, _ = parse_user(response)
    
    if(username is None):
        return HttpResponseRedirect(reverse(enter))
    
    data = { 'username': username }
    return render(request, "newpwd.html", data)
Ejemplo n.º 5
0
def product(request):

    if 'productid' not in request.GET:
        return HttpResponseRedirect(reverse(shop))
    
    data = { 'productid': request.GET['productid'] }
    product = make_query(dbhost + "get_product/", data)
    product = parse_product(product)

    dct = dict()
    # productid, name, category, price, count, discount, details, image, sold 
    dct["productid"] = product["productid"]
    dct["name"] = product["name"]
    dct["category"] = product["category"]
    dct["discprice"] = float(product["price"]) * (100.0 - float(product["discount"])) / 100.0
    if dct["discprice"] != float(product["price"]):
        dct["origprice"] = product["price"]
    dct["details"] = product["details"]
    dct["image"] = product["image"]

    reviews = make_query(dbhost + "get_reviews/", data)
    reviews = parse_reviews(reviews)

    rating = 0.0
    cnt = 0.0
    data = list()
    for review in reviews:
        dct2 = dict()
        dct2["productid"] = review["productid"]
        dct2["username"] = review["username"]
        
        temp = { 'username': review["username"] }
        response = make_query(dbhost + "get_user/", temp)
        _, _, _, picture, _,_ = parse_user(response)
        dct2["image"] = picture
        
        dct2["reviewid"] = review["reviewid"]
        dct2["rating"] = review["rating"]
        rating += float(review["rating"])
        cnt += 1.0
        dct2["details"] = review["details"]
        data.append(dct2)
    
    if cnt>0 :
        rating = rating/cnt

    dct['rating'] = str(rating)
    
    return render(request,"product.html", { 'product': dct , 'reviews':data })
Ejemplo n.º 6
0
def updprofile(request):
    username = request.session['username']
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, password, picture, code, verified = parse_user(response)
    
    if request.POST['password'] != "":
        password = make_password(request.POST['password'])
    data = {'username': username, 'email': email, 'password':password, 'picture':picture, 'code':code, 'verified':verified}
    response = make_query(dbhost + "set_user/", data)
    
    return HttpResponseRedirect(reverse(profile))
    
    return HttpResponse('update')
Ejemplo n.º 7
0
def delprofilepic(request):
    username = request.session['username']
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, password, picture, code, verified = parse_user(response)
    
    if picture is not None:
        os.remove(os.path.join(settings.MEDIA_ROOT, picture))
    
    picture = ""
    
    data = {'username': username, 'email': email, 'password':password, 'picture':picture, 'code':code, 'verified':verified}
    response = make_query(dbhost + "set_user/", data)
    
    return HttpResponseRedirect(reverse(profile))
Ejemplo n.º 8
0
def updprofilepic(request):
    username = request.session['username']
    
    if len(request.FILES) > 0:
        saveprofpic(username, request.FILES['picture'])
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, password, picture, code, verified = parse_user(response)
    
    picture = "profilepic/" + username + ".jpg"
    
    data = {'username': username, 'email': email, 'password':password, 'picture':picture, 'code':code, 'verified':verified}
    response = make_query(dbhost + "set_user/", data)
    
    return HttpResponseRedirect(reverse(profile))
Ejemplo n.º 9
0
def verify(request):
    
    username = request.POST['username']
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, password, _, code, _ = parse_user(response)
    
    if(code == request.POST['code']):
        request.session['username'] = username
        data = {'username': username, 'email': email, 'password':password, 'picture':None, 'code':"0", 'verified':"1"}
        response = make_query(dbhost + "set_user/", data)
        return HttpResponseRedirect(reverse(index))
    
    else:
        data = {'username': username}  # error
        return render(request, "verify.html", data)
Ejemplo n.º 10
0
def forgot(request):
    
    username = request.POST['username']
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, email, password, picture, code, verified = parse_user(response)
    
    if(username is None):
        return HttpResponseRedirect(reverse(enter))
    
    code = gencode()
    msg = 'Visit: http://localhost:8080/pwdreset?code=' + code
    send_mail('Password reset', msg, '*****@*****.**', [email], fail_silently=True)
    
    data = {'username': username, 'email': email, 'password':password, 'picture':picture, 'code':code, 'verified':verified}
    response = make_query(dbhost + "set_user/", data)
    
    return HttpResponseRedirect(reverse(index))
Ejemplo n.º 11
0
def signin(request):

    username = request.POST['username']

    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, _, password, _, _, verified = parse_user(response)
    
    if(username is None):
        return HttpResponseRedirect(reverse(enter))

    if(verified == "0"):
        data = {'username':username}
        return render(request, "verify.html", data)

    if check_password(request.POST['password'], password):
        request.session['username'] = username

    return HttpResponseRedirect(reverse(index))
Ejemplo n.º 12
0
def signup(request):
    
    username = request.POST['username']
    
    data = { 'username': username }
    response = make_query(dbhost + "get_user/", data)
    username, _, _, _, _, _ = parse_user(response)
    
    if(username is not None):
        return HttpResponseRedirect(reverse(index))

    username = request.POST['username']
    email = request.POST['email']
    password = make_password(request.POST['password'])
    code = gencode()
    verified = "0"
    data = {'username': username, 'email':email, 'password':password, 'picture':None , 'code':code, 'verified': verified}
    response = make_query(dbhost + "set_user/", data)
    
    msg = 'Your verification code is: ' + code
    send_mail('Verification code', msg, '*****@*****.**', [email], fail_silently=True)

    data = {'username': username }
    return render(request, "verify.html", data)