-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented login page features along wit simple template
- Loading branch information
Showing
7 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django import forms | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.forms import AuthenticationForm | ||
|
||
User = get_user_model() | ||
|
||
class CustomAuthenticationForm(AuthenticationForm): | ||
username = forms.CharField( | ||
widget=forms.TextInput(attrs={'required': True})) | ||
password = forms.CharField( | ||
widget=forms.PasswordInput(attrs={'required': True})) | ||
remember_me = forms.BooleanField(required=False) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Login</h1> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit">Submit</button> | ||
</form> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
from .import views | ||
|
||
app_name = 'core' | ||
|
||
urlpatterns = [ | ||
path('login/', views.LoginView.as_view(), name='login'), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
from django.shortcuts import render | ||
from . forms import CustomAuthenticationForm | ||
from django.views import generic | ||
from django.contrib.auth import views | ||
from django.contrib.auth import login | ||
from django.shortcuts import redirect | ||
|
||
class LandingPageView(generic.TemplateView): | ||
template_name = 'landing_page.html' | ||
template_name = 'landing_page.html' | ||
|
||
|
||
class LoginView(views.LoginView): | ||
form_class = CustomAuthenticationForm | ||
template_name = 'core/login.html' | ||
|
||
def form_valid(self, form): | ||
remember_me = form.cleaned_data['remember_me'] | ||
login(self.request, form.get_user()) | ||
if remember_me: | ||
self.request.session.set_expiry(1209600) | ||
return redirect('landing-page') |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
<h1>Landing Page</h1> | ||
<h1>Landing Page</h1> | ||
{% if user.is_authenticated %} | ||
<p>{{user.email}}</p> | ||
{% else %} | ||
<p>Not logged in</p> | ||
{% endif %} |