user signup
This commit is contained in:
4
accounts/templates/accounts/login.html
Normal file
4
accounts/templates/accounts/login.html
Normal file
@ -0,0 +1,4 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
HI
|
||||
{% endblock %}
|
4
accounts/templates/accounts/signout.html
Normal file
4
accounts/templates/accounts/signout.html
Normal file
@ -0,0 +1,4 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
HI
|
||||
{% endblock %}
|
25
accounts/templates/accounts/signup.html
Normal file
25
accounts/templates/accounts/signup.html
Normal 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
8
accounts/urls.py
Normal 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'),
|
||||
]
|
@ -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')
|
||||
|
Reference in New Issue
Block a user