Beispiel #1
0
    def post(self, request):
        email = request.POST.get('Email')
        password = request.POST.get('password')
        print(password, email)

        customer = Customer.get_customer_by_mail(email)

        Errormessage = None

        if customer:

            flag = check_password(password, customer.password)

            if flag:
                # creating session to remember user name, email
                request.session['customer_id']=customer.id
                request.session['customer_email']= customer.email
                return redirect('Homepage')
            else:
                Errormessage = " Password or Email not Valid !!"

        else:
            Errormessage = " Password or Email not Valid !!"

        return render(request, 'login.html', {'error': Errormessage})
Beispiel #2
0
    def get(self, request):
        # checking if cart contain items for condition statements in home
        cart = request.session.get('cart')
        if not cart:
            request.session['cart'] = {}

        prds = None
        categ = Category.get_all_categories()
        categoryId = request.GET.get('category')
        if categoryId:
            prds = Product.get_all_products_by_category(categoryId)
        else:
            prds = Product.get_all_products()

        # Getiing user detail from session
        currentCustomer = None
        mail = request.session.get('customer_email')
        if mail:
            currentCustomer = Customer.get_customer_by_mail(mail)

        #--------------------------------
        data = {}
        data['products'] = prds
        data['categories'] = categ
        data['currentCustomer'] = currentCustomer

        # return render(request,'orders.html')
        return render(request, 'index.html', data)