init commit
This commit is contained in:
0
accounts/__init__.py
Normal file
0
accounts/__init__.py
Normal file
BIN
accounts/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/admin.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/admin.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/admin.cpython-311.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/apps.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/apps.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/apps.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/apps.cpython-311.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/forms.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/forms.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/forms.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/forms.cpython-311.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/models.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/models.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/urls.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/urls.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/urls.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/urls.cpython-311.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/views.cpython-310.pyc
Normal file
BIN
accounts/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/__pycache__/views.cpython-311.pyc
Normal file
BIN
accounts/__pycache__/views.cpython-311.pyc
Normal file
Binary file not shown.
3
accounts/admin.py
Normal file
3
accounts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
accounts/apps.py
Normal file
6
accounts/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'accounts'
|
||||
11
accounts/forms.py
Normal file
11
accounts/forms.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django import forms
|
||||
|
||||
|
||||
class UserRegistrationForm(forms.Form):
|
||||
username = forms.CharField()
|
||||
email = forms.EmailField()
|
||||
password = forms.CharField()
|
||||
|
||||
class UserLoginForm(forms.Form):
|
||||
username = forms.CharField()
|
||||
password = forms.CharField()
|
||||
0
accounts/migrations/__init__.py
Normal file
0
accounts/migrations/__init__.py
Normal file
BIN
accounts/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
accounts/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
accounts/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
accounts/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
7
accounts/models.py
Normal file
7
accounts/models.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
|
||||
|
||||
3
accounts/tests.py
Normal file
3
accounts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
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('register/', views.user_register, name='user_register'),
|
||||
path('login/', views.user_login, name='user_login'),
|
||||
path('logout/', views.user_logout, name='user_logout')
|
||||
]
|
||||
43
accounts/views.py
Normal file
43
accounts/views.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth.models import User
|
||||
from .forms import UserRegistrationForm, UserLoginForm
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def user_register(request):
|
||||
if request.method == 'POST':
|
||||
form = UserRegistrationForm(request.POST)
|
||||
if form.is_valid():
|
||||
cd = form.cleaned_data
|
||||
User.objects.create_user(cd['username'], cd['email'], cd['password'])
|
||||
messages.success(request, 'user created successfully')
|
||||
return redirect('home')
|
||||
else:
|
||||
form = UserRegistrationForm()
|
||||
|
||||
return render(request, 'register.html', {'form' : form})
|
||||
|
||||
|
||||
def user_login(request):
|
||||
if request.method == 'POST':
|
||||
form = UserLoginForm(request.POST)
|
||||
if form.is_valid():
|
||||
cd = form.cleaned_data
|
||||
user = authenticate(request, username=cd['username'], password=cd['password'])
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
messages.success(request, 'logged in successfully')
|
||||
return redirect('home')
|
||||
else:
|
||||
messages.error(request, 'username or password is wrong')
|
||||
else:
|
||||
form = UserLoginForm()
|
||||
return render(request, 'login.html', {'form': form})
|
||||
|
||||
|
||||
def user_logout(request):
|
||||
logout(request)
|
||||
messages.success(request, 'logged out successfully')
|
||||
return redirect('home')
|
||||
Reference in New Issue
Block a user