user signup

This commit is contained in:
Sharad Ahlawat 2020-03-09 21:41:52 -07:00
parent 7e3d84e2fc
commit 4681cef584
8 changed files with 71 additions and 11 deletions

View File

@ -0,0 +1,4 @@
{% extends 'base.html' %}
{% block content %}
HI
{% endblock %}

View File

@ -0,0 +1,4 @@
{% extends 'base.html' %}
{% block content %}
HI
{% endblock %}

View File

@ -0,0 +1,25 @@
{% 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"/>
<br/>
Password:
<br/>
<input type="password" name="password1"/>
<br/>
Confirm Password:
<br/>
<input type="password" name="password2"/>
<br/><br/>
<input type="submit" value="Sign Up!" class="btn btn-primary">
</form>
{% endblock %}

8
accounts/urls.py Normal file
View File

@ -0,0 +1,8 @@
from django.urls import path
from . import views
urlpatterns = [
path('signup', views.signup, name='signup'),
path('login', views.login, name='login'),
path('logout', views.logout, name='logout'),
]

View File

@ -1,3 +1,27 @@
from django.shortcuts import render
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.objects.get(username=request.POST['username'])
return render(request, 'accounts/signup.html', {'error': 'username already signed up'})
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, 'accounts/signup.html', {'error': 'passwords must match'})
else:
return render(request, 'accounts/signup.html')
def login(request):
return render(request, 'accounts/login.html')
def logout(request):
return render(request, '/accounts/login.html')

View File

@ -17,13 +17,6 @@
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- Favicons -->
<link rel="apple-touch-icon" href="/docs/4.4/assets/img/favicons/apple-touch-icon.png" sizes="180x180">
<link rel="icon" href="/docs/4.4/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png">
<link rel="icon" href="/docs/4.4/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png">
<link rel="manifest" href="/docs/4.4/assets/img/favicons/manifest.json">
<link rel="mask-icon" href="/docs/4.4/assets/img/favicons/safari-pinned-tab.svg" color="#563d7c">
<link rel="icon" href="/docs/4.4/assets/img/favicons/favicon.ico">
<meta name="msapplication-config" content="/docs/4.4/assets/img/favicons/browserconfig.xml">
<meta name="theme-color" content="#563d7c">
@ -56,7 +49,7 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav" ml-auto>
<div class="navbar-nav ml-auto">
<a class="nav-item nav-link" href="{% url 'home' %}">Sign Up</a>
<a class="nav-item nav-link" href="{% url 'home' %}">Login</a>
</div>

View File

@ -14,7 +14,7 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from products import views
@ -22,4 +22,5 @@ from products import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('accounts/', include('accounts.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -1,2 +1,3 @@
django
psycopg2
pillow