from django.shortcuts import render
from examApp.forms import UserForm,StudentForm
from django.contrib.auth import authenticate,login,logout
from django.http import HttpResponseRedirect,HttpResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request):
    return render(request,'examApp/index.html')

@login_required
def special(request):
    return HttpResponse("You are logged in!")

@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('index'))


def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        student_form = StudentForm(data=request.POST)

        if user_form.is_valid() and student_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()

            student = student_form.save(commit=False)
            student.user = user
            student.save()

            registered = True
        else:
            print(user_form.errors,student_form.errors)
    else:

        user_form = UserForm()
        student_form = StudentForm()

    return render(request,'examApp/registration.html',{'user_form':user_form,'student_form':student_form,'registered':registered})

def user_login(request):

    if request.method == 'POST':

        username = request.POST.get('username')
        password = request.POST.get('password')

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

        if user:
            if user.is_active:
                login(request,user)
                return HttpResponseRedirect(reverse('index'))
            else:
                return HttpResponse("ACCOUNT NOT ACTIVE")
        else:
            print("Someone tried to login and failed!")
            print("Username: {} and Password {}".format(username,password))
            return HttpResponse("Invalid Login details!")
    else:
        return render(request,'examApp/login.html',{})

4e1647dd726d0d80e23e36d25cfde4629ee6501b
<mask token>


def index(request):
    return render(request, 'examApp/index.html')


@login_required
def special(request):
    return HttpResponse('You are logged in!')


<mask token>

<mask token>


def index(request):
    return render(request, 'examApp/index.html')


@login_required
def special(request):
    return HttpResponse('You are logged in!')


@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('index'))


<mask token>

<mask token>


def index(request):
    return render(request, 'examApp/index.html')


@login_required
def special(request):
    return HttpResponse('You are logged in!')


@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('index'))


<mask token>


def user_login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)
        if user:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(reverse('index'))
            else:
                return HttpResponse('ACCOUNT NOT ACTIVE')
        else:
            print('Someone tried to login and failed!')
            print('Username: {} and Password {}'.format(username, password))
            return HttpResponse('Invalid Login details!')
    else:
        return render(request, 'examApp/login.html', {})

from django.shortcuts import render
from examApp.forms import UserForm, StudentForm
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required


def index(request):
    return render(request, 'examApp/index.html')


@login_required
def special(request):
    return HttpResponse('You are logged in!')


@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('index'))


def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        student_form = StudentForm(data=request.POST)
        if user_form.is_valid() and student_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            student = student_form.save(commit=False)
            student.user = user
            student.save()
            registered = True
        else:
            print(user_form.errors, student_form.errors)
    else:
        user_form = UserForm()
        student_form = StudentForm()
    return render(request, 'examApp/registration.html', {'user_form':
        user_form, 'student_form': student_form, 'registered': registered})


def user_login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)
        if user:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect(reverse('index'))
            else:
                return HttpResponse('ACCOUNT NOT ACTIVE')
        else:
            print('Someone tried to login and failed!')
            print('Username: {} and Password {}'.format(username, password))
            return HttpResponse('Invalid Login details!')
    else:
        return render(request, 'examApp/login.html', {})

from django.shortcuts import render
from examApp.forms import UserForm,StudentForm
from django.contrib.auth import authenticate,login,logout
from django.http import HttpResponseRedirect,HttpResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request):
    return render(request,'examApp/index.html')

@login_required
def special(request):
    return HttpResponse("You are logged in!")

@login_required
def user_logout(request):
    logout(request)
    return HttpResponseRedirect(reverse('index'))


def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        student_form = StudentForm(data=request.POST)

        if user_form.is_valid() and student_form.is_valid():

            user = user_form.save()
            user.set_password(user.password)
            user.save()

            student = student_form.save(commit=False)
            student.user = user
            student.save()

            registered = True
        else:
            print(user_form.errors,student_form.errors)
    else:

        user_form = UserForm()
        student_form = StudentForm()

    return render(request,'examApp/registration.html',{'user_form':user_form,'student_form':student_form,'registered':registered})

def user_login(request):

    if request.method == 'POST':

        username = request.POST.get('username')
        password = request.POST.get('password')

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

        if user:
            if user.is_active:
                login(request,user)
                return HttpResponseRedirect(reverse('index'))
            else:
                return HttpResponse("ACCOUNT NOT ACTIVE")
        else:
            print("Someone tried to login and failed!")
            print("Username: {} and Password {}".format(username,password))
            return HttpResponse("Invalid Login details!")
    else:
        return render(request,'examApp/login.html',{})
