This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .models import Account | |
from django.shortcuts import render | |
from django.contrib import messages | |
from django.contrib.auth import ( | |
authenticate, | |
logout , | |
login | |
) | |
from django.shortcuts import ( | |
render, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from .models import Account | |
from django.contrib.auth.models import User | |
from django.contrib.auth import authenticate | |
from django.contrib.auth.forms import UserCreationForm | |
class RegistrationForm(UserCreationForm): | |
""" | |
Form for Registering new users | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager | |
#manager for our custom model | |
class MyAccountManager(BaseUserManager): | |
""" | |
This is a manager for Account class | |
""" | |
def create_user(self, email, username, password=None): | |
if not email: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def home(request): | |
#rendering our home page | |
return render(request, 'home.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from account import views | |
app_name="account" | |
urlpatterns=[ | |
path('register/' , views.register , name="register"), | |
path('user_login/', views.user_login, name="user_login"), | |
path('home/', views.home, name="home"), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""login_system URL Configuration | |
The `urlpatterns` list routes URLs to views. For more information please see: | |
https://docs.djangoproject.com/en/3.0/topics/http/urls/ | |
Examples: | |
Function views | |
1. Add an import: from my_app import views | |
2. Add a URL to urlpatterns: path('', views.home, name='home') | |
Class-based views | |
1. Add an import: from other_app.views import Home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "account/base.html" %} | |
{% block body_block %} | |
<div class="container"> | |
<div class="jumbotron"> | |
<h1>Welcome to the our Login System !!!</h1> | |
{% if user.is_authenticated %} | |
<h2>Hello {{ user.username }}</h2> | |
{% else %} | |
<h2>Register or Login if you'd like to</h2> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'account/base.html' %} | |
{% block body_block %} | |
<div class="container "> | |
<div class=""> | |
<h1>Login here :</h1> | |
<form method="post" action="{% url 'account:user_login' %}"> | |
{% csrf_token %} | |
<p><label for="username">Username:</label> | |
<input type="text" name="username" placeholder="Username"> | |
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "account/base.html" %} | |
{% load static %} | |
{% block body_block %} | |
<div class="container "> | |
{% if registered %} | |
<h1>Thank you for registering!</h1> | |
{% else %} | |
<h1>Register Here</h1> | |
<h3>Just fill out the form.</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Base</title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> | |
</head> | |
<body> |