First Commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
name = 'accounts'
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@@ -0,0 +1,34 @@
|
||||
{% extends 'base.html'%}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if error %}
|
||||
{{ error }}
|
||||
<br />
|
||||
<br />
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
<h1> Log In </h1>
|
||||
|
||||
<form method="POST" action="{% url 'login' %}">
|
||||
{% csrf_token %}
|
||||
Username:
|
||||
<br />
|
||||
<input type="text" name="username" placeholder="username">
|
||||
<br />
|
||||
Password:
|
||||
<br />
|
||||
<input type="password" name="password" placeholder="password">
|
||||
<br />
|
||||
<br />
|
||||
<input class="btn btn-primary "type="submit" value="Log In"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,38 @@
|
||||
{% extends 'base.html'%}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if error %}
|
||||
{{ error }}
|
||||
<br />
|
||||
<br />
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
<h1> Sign Up</h1>
|
||||
|
||||
<form method="POST" action="{% url 'signup' %}">
|
||||
{% csrf_token %}
|
||||
Username:
|
||||
<br />
|
||||
<input type="text" name="username" placeholder="username">
|
||||
<br />
|
||||
Password:
|
||||
<br />
|
||||
<input type="password" name="password1" placeholder="password">
|
||||
<br />
|
||||
Confirm Password:
|
||||
<br />
|
||||
<input type="password" name="password2" placeholder=" confirm password">
|
||||
<br />
|
||||
<br />
|
||||
<input class="btn btn-primary "type="submit" value="Sign Up"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
from django.urls import path,include
|
||||
from . import views
|
||||
urlpatterns = [
|
||||
path('signup',views.signup, name='signup'),
|
||||
path('login',views.login, name='login'),
|
||||
path('logout',views.logout, name='logout'),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
from django.shortcuts import render,redirect
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib import auth
|
||||
|
||||
# Create your views here.
|
||||
def signup(request):
|
||||
if request.method =='POST':
|
||||
if request.POST['password1'] == request.POST['password2']:
|
||||
try:
|
||||
user=User.objects.get(username=request.POST['username'])
|
||||
return render(request,'signup.html',{'error':'Username has been already taken '})
|
||||
except User.DoesNotExist:
|
||||
user=User.objects.create_user(request.POST['username'],password=request.POST['password1'])
|
||||
auth.login(request,user)
|
||||
return redirect('home')
|
||||
else:
|
||||
return render(request,'signup.html',{'error':'Passwords must match'})
|
||||
|
||||
|
||||
else:
|
||||
return render(request,'signup.html')
|
||||
|
||||
def login(request):
|
||||
if request.method =='POST':
|
||||
user=auth.authenticate(username=request.POST['username'],password=request.POST['password'])
|
||||
if user is not None:
|
||||
auth.login(request,user)
|
||||
return redirect('home')
|
||||
else:
|
||||
return render(request,'login.html', {'error':'username or password is invalid.'})
|
||||
else:
|
||||
return render(request,'login.html')
|
||||
|
||||
def logout(request):
|
||||
if request.method =='POST':
|
||||
auth.logout(request)
|
||||
return redirect('home')
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user