def home(request): data = cartData(request) cartItems = data['cartItems'] product=Product.objects.order_by('-listing_date')[:8] context={'product':product,'cartItems':cartItems} return render(request,'pages/index.html',context)
def contact(request): data = cartData(request) cartItems = data['cartItems'] if request.method == 'POST': email= request.POST['email'] fname= request.POST['firstname'] lname= request.POST['lastname'] content = request.POST['message'] message = f"firstname-{fname} lastname-{lname} email-{email} message-{content}" send_mail('Contact Form',message,email,[settings.EMAIL_HOST_USER],fail_silently=False) messages.success(request,'Message sent successfully !!') context={'cartItems':cartItems} return render(request,'pages/contact.html',context)
def login(request): data = cartData(request) cartItems = data['cartItems'] if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = auth.authenticate(username=username, password=password) if user is not None: auth.login(request, user) messages.success(request, 'you are logged in successfully!') return redirect('home') else: messages.error(request, 'invalid credentials') return redirect('login') else: context = {'cartItems': cartItems} return render(request, 'accounts/login.html', context)
def register(request): data = cartData(request) cartItems = data['cartItems'] if request.method == 'POST': first_name = request.POST['first_name'] last_name = request.POST['last_name'] username = request.POST['username'] email = request.POST['email'] password = request.POST['password'] password2 = request.POST['password2'] if password == password2: if User.objects.filter(username=username).exists(): messages.error(request, 'username already taken') return redirect('register') else: if User.objects.filter(email=email).exists(): messages.error(request, 'email already being taken') return redirect('register') else: user = User.objects.create_user(first_name=first_name, last_name=last_name, username=username, password=password, email=email) user.save() customer, created = Customer.objects.get_or_create( email=email, ) customer.user = user customer.name = username customer.save() messages.success(request, 'you are successfully registered') return redirect('login') customer, created = Customer.objects.get_or_create( email=email, ) customer.user = user customer.name = name customer.save() else: messages.error(request, 'password did not match') return render(request, 'accounts/register.html') else: context = {'cartItems': cartItems} return render(request, 'accounts/register.html', context)
def points(request): data = cartData(request) cartItems = data['cartItems'] reward=Reward.objects.all() context={'cartItems':cartItems,'reward':reward} return render(request,'pages/points.html',context)
def aboutus(request): data = cartData(request) cartItems = data['cartItems'] context={'cartItems':cartItems} return render(request,'pages/aboutus.html',context)