from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from .forms import CustomUserCreationForm
from django.contrib import messages


# Create your views here.   
def home(request):
    return render(request, "users/home.html")

def about(request):
    return render(request, "users/about.html")

def loginUser(request):
    page = 'login'
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user=authenticate(request, username=username, password=password)

        if user is not None: 
            login(request, user)
            return redirect('index')
        if user is None:
            messages.error(request, "Incorrect username or password.")

    return render(request, "users/login_register.html", {'page': page})

def logoutUser(request):
    logout(request)
    return redirect('loginPage')

def registerUser(request):  
    page = 'register'
    form = CustomUserCreationForm()

    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()

            user=authenticate(request, username=user.username, password=request.POST['password1'])

            if user is not None:
                login(request, user)
                return redirect('index')


    context = {'form': form, 'page': page}
    return render(request, 'users/login_register.html', context)


51c0a40fd739618fbad19c348da628f179f8680e
<mask token>


def home(request):
    return render(request, 'users/home.html')


<mask token>


def logoutUser(request):
    logout(request)
    return redirect('loginPage')


<mask token>

<mask token>


def home(request):
    return render(request, 'users/home.html')


<mask token>


def loginUser(request):
    page = 'login'
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            return redirect('index')
        if user is None:
            messages.error(request, 'Incorrect username or password.')
    return render(request, 'users/login_register.html', {'page': page})


def logoutUser(request):
    logout(request)
    return redirect('loginPage')


def registerUser(request):
    page = 'register'
    form = CustomUserCreationForm()
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            user = authenticate(request, username=user.username, password=
                request.POST['password1'])
            if user is not None:
                login(request, user)
                return redirect('index')
    context = {'form': form, 'page': page}
    return render(request, 'users/login_register.html', context)

<mask token>


def home(request):
    return render(request, 'users/home.html')


def about(request):
    return render(request, 'users/about.html')


def loginUser(request):
    page = 'login'
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            return redirect('index')
        if user is None:
            messages.error(request, 'Incorrect username or password.')
    return render(request, 'users/login_register.html', {'page': page})


def logoutUser(request):
    logout(request)
    return redirect('loginPage')


def registerUser(request):
    page = 'register'
    form = CustomUserCreationForm()
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            user = authenticate(request, username=user.username, password=
                request.POST['password1'])
            if user is not None:
                login(request, user)
                return redirect('index')
    context = {'form': form, 'page': page}
    return render(request, 'users/login_register.html', context)

from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from .forms import CustomUserCreationForm
from django.contrib import messages


def home(request):
    return render(request, 'users/home.html')


def about(request):
    return render(request, 'users/about.html')


def loginUser(request):
    page = 'login'
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            return redirect('index')
        if user is None:
            messages.error(request, 'Incorrect username or password.')
    return render(request, 'users/login_register.html', {'page': page})


def logoutUser(request):
    logout(request)
    return redirect('loginPage')


def registerUser(request):
    page = 'register'
    form = CustomUserCreationForm()
    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()
            user = authenticate(request, username=user.username, password=
                request.POST['password1'])
            if user is not None:
                login(request, user)
                return redirect('index')
    context = {'form': form, 'page': page}
    return render(request, 'users/login_register.html', context)

from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from .forms import CustomUserCreationForm
from django.contrib import messages


# Create your views here.   
def home(request):
    return render(request, "users/home.html")

def about(request):
    return render(request, "users/about.html")

def loginUser(request):
    page = 'login'
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user=authenticate(request, username=username, password=password)

        if user is not None: 
            login(request, user)
            return redirect('index')
        if user is None:
            messages.error(request, "Incorrect username or password.")

    return render(request, "users/login_register.html", {'page': page})

def logoutUser(request):
    logout(request)
    return redirect('loginPage')

def registerUser(request):  
    page = 'register'
    form = CustomUserCreationForm()

    if request.method == 'POST':
        form = CustomUserCreationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()

            user=authenticate(request, username=user.username, password=request.POST['password1'])

            if user is not None:
                login(request, user)
                return redirect('index')


    context = {'form': form, 'page': page}
    return render(request, 'users/login_register.html', context)

