move to root directory
This commit is contained in:
parent
74681d0be6
commit
d4b75f60e6
20 changed files with 0 additions and 0 deletions
0
account/__init__.py
Normal file
0
account/__init__.py
Normal file
3
account/admin.py
Normal file
3
account/admin.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
account/apps.py
Normal file
6
account/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'account'
|
||||
56
account/forms.py
Normal file
56
account/forms.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
class LoginForm(AuthenticationForm):
|
||||
|
||||
username = forms.CharField(widget=forms.TextInput(attrs={
|
||||
'class' : 'form-control',
|
||||
'placeholder' : 'kullanici adi giriniz'
|
||||
}))
|
||||
|
||||
password = forms.CharField(widget=forms.PasswordInput(attrs={
|
||||
'class' : 'form-control',
|
||||
'placeholder' : 'şifre gir'
|
||||
}))
|
||||
|
||||
class RegisterForm(UserCreationForm):
|
||||
|
||||
username = forms.CharField(widget=forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'kullanici adi giriniz'
|
||||
}))
|
||||
email = forms.EmailField(widget=forms.EmailInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'email giriniz'
|
||||
}))
|
||||
password1 = forms.CharField(widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'şifre giriniz'
|
||||
}))
|
||||
password2 = forms.CharField(widget=forms.PasswordInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'şifreyi tekrar giriniz'
|
||||
}))
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ('username', 'email', 'password1', 'password2')
|
||||
widgets = {
|
||||
'username': forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'kullanici adi giriniz'
|
||||
}),
|
||||
'email': forms.EmailInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'email giriniz'
|
||||
}),
|
||||
'password1': forms.PasswordInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'şifre giriniz'
|
||||
}),
|
||||
'password2': forms.PasswordInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'şifreyi tekrar giriniz'
|
||||
}),
|
||||
}
|
||||
0
account/migrations/__init__.py
Normal file
0
account/migrations/__init__.py
Normal file
3
account/models.py
Normal file
3
account/models.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
account/tests.py
Normal file
3
account/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
8
account/urls.py
Normal file
8
account/urls.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('login/', views.LoginView.as_view(), name='login'),
|
||||
path('logout/', views.LogoutView.as_view(), name='logout'),
|
||||
path('register/', views.RegisterView.as_view(), name='register'),
|
||||
]
|
||||
54
account/views.py
Normal file
54
account/views.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from .forms import LoginForm, RegisterForm
|
||||
from django.views import View
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
|
||||
class LoginView(View):
|
||||
template_name = 'accounts/login.html'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
form = LoginForm()
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
||||
def post(self, request):
|
||||
|
||||
form = LoginForm(data=request.POST)
|
||||
if form.is_valid():
|
||||
user = form.get_user()
|
||||
login(request, user)
|
||||
messages.success(request, "Login successful")
|
||||
return redirect('home')
|
||||
else:
|
||||
messages.warning(request, "Login failed")
|
||||
return redirect('login')
|
||||
|
||||
|
||||
class RegisterView(View):
|
||||
template_name = 'accounts/register.html'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
form = RegisterForm()
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = RegisterForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, "Registration successful")
|
||||
return redirect("login")
|
||||
else:
|
||||
messages.error(request, "Registration failed")
|
||||
return render(request, self.template_name, {'form': form})
|
||||
|
||||
|
||||
class LogoutView(View):
|
||||
@method_decorator(login_required)
|
||||
def get(self, request, *args, **kwargs):
|
||||
logout(request)
|
||||
messages.success(request, "Logout successful")
|
||||
return redirect('login')
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue