<repo_name>vinay-yadav/College-Management-System<file_sep>/main_site/views.py
from django.shortcuts import render, HttpResponse,get_object_or_404
from .models import Authenticate


def home(request):
    template_name = 'site/index.html'
    return render(request, template_name)


def login(request):
    template_name = 'login/login.html'
    if request.method == 'POST':
        roll_no = request.POST.get('roll_no')
        password = request.POST.get('password')
        try:
            query = Authenticate.objects.get(roll=roll_no)
            print(query)
            if query:
                if query.password == password:
                    return HttpResponse('<h1>Login Successfull</h1>')
                else:
                    context = {'match': 'your password is incorrect'}
                    return render(request, template_name, context)
        except Exception as e:
            print(e, 'hi')
            context = {'not_member': "Roll no. didn't found"}
            return render(request, template_name, context)
    return render(request, template_name)


def sign_up(request):
    template_name = 'signup/signup.html'
    if request.method == 'POST':
        roll_no = request.POST.get('roll_no')
        email = request.POST.get('email')
        password = request.POST.get('<PASSWORD>')
        conf_password = request.POST.get('confirm_password')
        if password == conf_password:
            Authenticate.objects.create(roll=roll_no, email=email, password=password)
            return HttpResponse('<h1>Sign-up successfull</h1>')
        else:
            return HttpResponse('<h1>password didn;t match<h1>')
    return render(request, template_name)<file_sep>/main_site/migrations/0005_remove_authenticate_user.py
# Generated by Django 2.2.4 on 2019-08-24 20:18

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('main_site', '0004_remove_authenticate_username'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='authenticate',
            name='user',
        ),
    ]
<file_sep>/main_site/migrations/0004_remove_authenticate_username.py
# Generated by Django 2.2.4 on 2019-08-24 18:23

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('main_site', '0003_authenticate'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='authenticate',
            name='username',
        ),
    ]
<file_sep>/main_site/urls.py
from django.urls import path, include
from .views import *

urlpatterns = [
    path('', home),
    path('login/', login),
    path('sign_up/', sign_up),
]
<file_sep>/main_site/models.py
from django.db import models
from django.conf import settings

User = settings.AUTH_USER_MODEL


class Authenticate(models.Model):
    # user = models.ForeignKey(User, on_delete=models.CASCADE)
    roll = models.CharField(primary_key=True, max_length=10)
    # username = models.CharField(unique=True, null=False, blank=False, max_length=50)
    email = models.CharField(null=False, unique=True, blank=False, max_length=50)
    password = models.CharField(null=False, blank=False, max_length=220)
    created = models.DateTimeField(auto_now_add=True, editable=True)

    class Meta:
        ordering = ['-created']
<file_sep>/main_site/tests.py
from django.test import TestCase

# Create your tests here.

def signup(request):
    if request.method == "POST":
        roll = request.POST.get("Roll")
        mail = request.POST.get("Email")
        passw = request.POST.get("password")
        c_passw = request.POST.get("Confirm_password")
        try:
            if passw == c_passw:
                data = Student_login(roll_no=roll, password=<PASSWORD>, email=mail)
                data.save()
                # messages.success(request, ("Succesfully Registered"))
                return render(request, 'signup/signup.html')
            else:
                # messages.success(request,("Password not match"))
                return render(request, 'signup/signup.html')
        except Exception as e:
            print(e)
    return render(request, 'signup/signup.html')


def login(request):
    if request.method == "POST":
        roll = request.POST.get("Roll_no")
        passw = request.POST.get("<PASSWORD>")
        # print(roll)
        # print(passw)
        user = Student_login.objects.filter(roll_no=roll).first()  # taking data from database
        # print(user)
        try:
            if user:
                if user.password == <PASSWORD>:
                    request.session['user'] = roll
                    print("Login success")
                    return HttpResponse("Login Successful")
                else:
                    print("Pass didn't match")
                    return HttpResponse("Password didn't match")
        except Exception as e:
            print(e)
    return render(request, 'login/login.html')

<file_sep>/main_site/migrations/0006_auto_20190824_2054.py
# Generated by Django 2.2.4 on 2019-08-24 20:54

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('main_site', '0005_remove_authenticate_user'),
    ]

    operations = [
        migrations.RenameField(
            model_name='authenticate',
            old_name='roll_no',
            new_name='roll',
        ),
    ]
