Skip to content

Commit

Permalink
Login added
Browse files Browse the repository at this point in the history
  • Loading branch information
supsa-ak committed Dec 19, 2021
1 parent 4e93052 commit 1480540
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 66 deletions.
Binary file modified BudMan/__pycache__/settings.cpython-38.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions BudMan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'api.apps.ApiConfig',
'frontend.apps.FrontendConfig',
]
Expand Down Expand Up @@ -113,3 +114,5 @@
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CRISPY_TEMPLATE_PACK='bootstrap4'
Binary file modified db.sqlite3
Binary file not shown.
14 changes: 14 additions & 0 deletions frontend/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User


class SignupForm(UserCreationForm):
first_name = forms.CharField()
last_name = forms.CharField()
email = forms.EmailField()

class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2']
56 changes: 5 additions & 51 deletions frontend/templates/accounts/login.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{% load static %}
{% load crispy_forms_tags %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sign in & Sign up Form</title>
<title>Sign in</title>
</head>
{% block body %}

<body>
<a href="/">Home</a>
<!-- Login Form ************************************ -->
<div class="container">
<div class="forms-container">
Expand All @@ -31,61 +33,13 @@ <h2 class="title">Sign in</h2>
</div>
{% endfor %}
<input type="submit" name="form_type" value="Login" class="btn solid" />

<div class="social-media">
<a href="#" class="social-icon">
<i class="fab fa-facebook-f"></i>
</a>
<a href="#" class="social-icon">
<i class="fab fa-twitter"></i>
</a>
<a href="#" class="social-icon">
<i class="fab fa-google"></i>
</a>
<a href="#" class="social-icon">
<i class="fab fa-linkedin-in"></i>
</a>
</div>
</form>

<!-- ************ Sign-up Form*************** -->
<form class="sign-up-form" method="POST">
{% csrf_token %}
<h2 class="title">Sign up</h2>
<div class="input-field">
<i class="fas fa-user"></i>
{{form.username}}

</div>
<div class="input-field">
<i class="fas fa-user"></i>
{{form.first_name}}


</div>
<div class="input-field">
<i class="fas fa-user"></i>
{{form.last_name}}

</div>
<div class="input-field">
<i class="fas fa-envelope"></i>
{{form.email}}

</div>
<div class="input-field">
<i class="fas fa-lock"></i>
{{form.password1}}

</div>
<div class="input-field">
<i class="fas fa-lock"></i>
{{form.password2}}

</div>
<div style="color: red;">
{{form.errors}}
</div>
<h2 class="title">Sign Up</h2>
{{ form|crispy }}
<input type="submit" name="form_type" class="btn btn-primary" value="Sign up" />

</form>
Expand Down
3 changes: 3 additions & 0 deletions frontend/templates/frontend/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<title>BudMan - BudMan is a web app that helps you track and adjust your spending so that you are in control of money.</title></head>
<body>
<h1>BudMan - BudMan is a web app that helps you track and adjust your spending so that you are in control of money.</h1>
{% if user.is_authenticated %}
<h2>Logged in as </h2><h2 style="color: green">{{request.user}}</h2>
{% endif %}
<a href="/login">Login</a>
<a href="/logout">Logout</a>
</body>
Expand Down
4 changes: 2 additions & 2 deletions frontend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .views import *
urlpatterns = [
path('', home),
path('login', loginPage),
path('', home, name='home'),
path('login', loginPage, name='login'),
path('logout', logoutUser),
]
31 changes: 18 additions & 13 deletions frontend/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import JsonResponse
from .decorators import unauthenticated_user
from django.contrib.auth.forms import UserCreationForm
from .forms import SignupForm
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required

def home(request):
return render(request, 'frontend/home.html')
context = {}
return render(request, 'frontend/home.html',context)

@unauthenticated_user
def loginPage(request):
form = UserCreationForm()
form = SignupForm()
if request.method == 'POST':
if request.POST.get("form_type") == 'Sign up':
if request.method == 'POST' :
form = UserCreationForm(request.POST)
if form.is_valid():
user = form.save()
user.save()
messages.success(request, 'Account created for '+ user.username)
return redirect('login')

form = SignupForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, 'Account created for '+ request.POST['username'])
return redirect('login')

elif request.POST.get("form_type") == 'Login':
username = request.POST.get('username')
Expand All @@ -37,4 +39,7 @@ def loginPage(request):

def logoutUser(request):
logout(request)
return redirect('login')
return redirect('login')


# @login_required(login_url='login')

0 comments on commit 1480540

Please sign in to comment.