46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
|
from django.shortcuts import render, redirect
|
||
|
from django.contrib import messages
|
||
|
from users.models import User
|
||
|
from .models import VendorsData
|
||
|
from django.contrib.auth import authenticate, login, logout
|
||
|
from django.contrib.auth.decorators import login_required
|
||
|
|
||
|
|
||
|
# Create your views here.
|
||
|
@login_required(login_url='login')
|
||
|
def index(request):
|
||
|
context = {}
|
||
|
return render(request, 'base/dashboard.html', context)
|
||
|
|
||
|
def LoginPage(request):
|
||
|
if request.method == 'POST':
|
||
|
email = request.POST.get('email')
|
||
|
password = request.POST.get('password')
|
||
|
user = None
|
||
|
error = None
|
||
|
try:
|
||
|
user = User.objects.get(email=email)
|
||
|
except:
|
||
|
error = messages.error(request, 'Email not registered')
|
||
|
|
||
|
if user is not None and error is None:
|
||
|
user = authenticate(request, email=email, password=password)
|
||
|
if user is not None:
|
||
|
login(request, user)
|
||
|
return redirect('dashboard')
|
||
|
else:
|
||
|
messages.error(request, 'Wrong password')
|
||
|
|
||
|
|
||
|
context = {}
|
||
|
return render(request, 'base/login.html', context)
|
||
|
|
||
|
def LogoutPage(request):
|
||
|
logout(request)
|
||
|
return redirect('login')
|
||
|
|
||
|
@login_required(login_url='login')
|
||
|
def VendorPage(request):
|
||
|
vendors = VendorsData.objects.filter(vendorid_id=request.user.id)
|
||
|
context = {'vendors': vendors}
|
||
|
return render(request, 'base/vendor.html', context)
|