authentication backend
This commit is contained in:
@@ -41,6 +41,8 @@ INSTALLED_APPS = [
|
||||
'classroom',
|
||||
'posts',
|
||||
'users',
|
||||
'crispy_forms',
|
||||
'widget_tweaks',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -133,3 +135,10 @@ STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, 'core/static'),
|
||||
]
|
||||
|
||||
|
||||
LOGIN_REDIRECT_URL = 'classroom:home'
|
||||
LOGOUT_REDIRECT_URL = 'landing-page'
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
|
||||
<!-- Main Content -->
|
||||
<div id="content">
|
||||
|
||||
{% include 'partials/_topbar.html' %}
|
||||
|
||||
<!-- Begin Page Content -->
|
||||
<div class="container-fluid">
|
||||
{% include 'partials/_alerts.html' %}
|
||||
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div id="message" class="container">
|
||||
<div class="alert alert-{{ message.tags }} alert-dismissible text-center" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>
|
||||
<strong>
|
||||
{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}
|
||||
Error:
|
||||
{% else %}
|
||||
{{ message.tags|title }}
|
||||
{% endif %}
|
||||
</strong>
|
||||
{{ message }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
{% load static %}
|
||||
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
@@ -27,4 +29,4 @@
|
||||
|
||||
<!-- Custom scripts for all pages-->
|
||||
<script src="{% static 'mainapp/js/sb-admin-2.min.js' %}" defer></script>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
@@ -179,4 +179,4 @@
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
<!-- End of Topbar -->
|
||||
<!-- End of Topbar -->
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<body class="bg-gradient-primary">
|
||||
|
||||
<div class="container">
|
||||
{% include 'partials/_alerts.html' %}
|
||||
{% block content %} {% endblock content %}
|
||||
</div>
|
||||
|
||||
|
||||
+4
-1
@@ -17,6 +17,7 @@ from django.contrib import admin
|
||||
from django.urls import path,include
|
||||
from django.conf.urls.static import static
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.views import LoginView, LogoutView
|
||||
|
||||
from . import views
|
||||
|
||||
@@ -24,5 +25,7 @@ from . import views
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('classroom/',include('classroom.urls')),
|
||||
path('', views.landing, name='langing-page'),
|
||||
path('', views.landing, name='landing-page'),
|
||||
path('users/', include('users.urls')),
|
||||
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django import forms
|
||||
|
||||
class UserRegistrationForm(UserCreationForm):
|
||||
email = forms.EmailField()
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields= ['username', 'email', 'password1', 'password2']
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{% extends 'user_base.html' %}
|
||||
{% load static %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %} Forgot Password {% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
@@ -17,29 +21,17 @@
|
||||
<div class="text-center">
|
||||
<h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
|
||||
</div>
|
||||
<form class="user">
|
||||
<div class="form-group">
|
||||
<input type="email" class="form-control form-control-user" id="exampleInputEmail" aria-describedby="emailHelp" placeholder="Enter Email Address...">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" class="form-control form-control-user" id="exampleInputPassword" placeholder="Password">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox small">
|
||||
<input type="checkbox" class="custom-control-input" id="customCheck">
|
||||
<label class="custom-control-label" for="customCheck">Remember Me</label>
|
||||
</div>
|
||||
</div>
|
||||
<a href="index.html" class="btn btn-primary btn-user btn-block">
|
||||
Login
|
||||
</a>
|
||||
<hr>
|
||||
<a href="index.html" class="btn btn-google btn-user btn-block">
|
||||
<i class="fab fa-google fa-fw"></i> Login with Google
|
||||
</a>
|
||||
<a href="index.html" class="btn btn-facebook btn-user btn-block">
|
||||
<i class="fab fa-facebook-f fa-fw"></i> Login with Facebook
|
||||
</a>
|
||||
<form class="user" method='POST'>
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
{{ form.username | attr:'class: form-control form-control-user'| attr:'placeholder: Username' }}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.password | attr:'class: form-control form-control-user'| attr:'placeholder: Password' }}
|
||||
</div>
|
||||
|
||||
<button class="btn btn-primary btn-user btn-block" type='submit'>Login</button>
|
||||
</form>
|
||||
<hr>
|
||||
<div class="text-center">
|
||||
@@ -57,4 +49,4 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
{% endblock content %}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{% extends 'user_base.html' %}
|
||||
{% block title %} Forgot Password {% endblock title %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %} Register {% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card o-hidden border-0 shadow-lg my-5">
|
||||
@@ -12,36 +14,24 @@
|
||||
<div class="text-center">
|
||||
<h1 class="h4 text-gray-900 mb-4">Create an Account!</h1>
|
||||
</div>
|
||||
<form class="user">
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-6 mb-3 mb-sm-0">
|
||||
<input type="text" class="form-control form-control-user" id="exampleFirstName" placeholder="First Name">
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control form-control-user" id="exampleLastName" placeholder="Last Name">
|
||||
</div>
|
||||
<form class="user" method='POST'>
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="form-group">
|
||||
{{ form.username | attr:'class: form-control form-control-user'|attr:'placeholder:Username' }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="email" class="form-control form-control-user" id="exampleInputEmail" placeholder="Email Address">
|
||||
{{ form.email | attr:'class: form-control form-control-user'|attr:'placeholder:Email' }}
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-6 mb-3 mb-sm-0">
|
||||
<input type="password" class="form-control form-control-user" id="exampleInputPassword" placeholder="Password">
|
||||
{{ form.password1 | attr:'class: form-control form-control-user'|attr:'placeholder:Password' }}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<input type="password" class="form-control form-control-user" id="exampleRepeatPassword" placeholder="Repeat Password">
|
||||
{{ form.password2 | attr:'class: form-control form-control-user'|attr:'placeholder:Confirm Password' }}
|
||||
</div>
|
||||
</div>
|
||||
<a href="login.html" class="btn btn-primary btn-user btn-block">
|
||||
Register Account
|
||||
</a>
|
||||
<hr>
|
||||
<a href="index.html" class="btn btn-google btn-user btn-block">
|
||||
<i class="fab fa-google fa-fw"></i> Register with Google
|
||||
</a>
|
||||
<a href="index.html" class="btn btn-facebook btn-user btn-block">
|
||||
<i class="fab fa-facebook-f fa-fw"></i> Register with Facebook
|
||||
</a>
|
||||
</div>
|
||||
<button class="btn- btn-primary btn-user btn-block">Register</button>
|
||||
</form>
|
||||
<hr>
|
||||
<div class="text-center">
|
||||
@@ -55,4 +45,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
{% endblock content %}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from django.urls import path
|
||||
from django.contrib.auth.views import LoginView, LogoutView
|
||||
from django.conf import settings
|
||||
|
||||
from . import views
|
||||
|
||||
app_name= 'users'
|
||||
|
||||
urlpatterns = [
|
||||
path('login/', LoginView.as_view(template_name="users/login.html"),name="login"),
|
||||
path('logout/', LogoutView.as_view(), {'next_page': settings.LOGOUT_REDIRECT_URL},name="logout"),
|
||||
path('register/', views.register, name='register')
|
||||
]
|
||||
|
||||
|
||||
+20
-2
@@ -1,3 +1,21 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib import messages
|
||||
from .forms import UserRegistrationForm
|
||||
|
||||
|
||||
def register(request):
|
||||
if request.method == 'POST':
|
||||
form = UserRegistrationForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
username = form.cleaned_data.get('username')
|
||||
messages.success(request, f'Account Created Successfully for {username}')
|
||||
return redirect('users:login')
|
||||
else:
|
||||
messages.success(request, f'Error Setting up the account')
|
||||
else:
|
||||
form = UserRegistrationForm()
|
||||
return render(request, 'users/register.html', {'form':form})
|
||||
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
Reference in New Issue
Block a user