Skip to content

Commit 2643228

Browse files
authored
Merge pull request #117 from f-yamak/master
NotionFM - Furkan Yamak Mine Altuğ
2 parents 65de231 + 7fe9ed1 commit 2643228

File tree

1,401 files changed

+55876
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,401 files changed

+55876
-0
lines changed

Projects/NotionClone/.gitignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/django
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=django
3+
4+
### Django ###
5+
*.log
6+
*.pot
7+
*.pyc
8+
__pycache__/
9+
local_settings.py
10+
db.sqlite3
11+
db.sqlite3-journal
12+
media
13+
14+
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
15+
# in your Git repository. Update and uncomment the following line accordingly.
16+
# <django-project-name>/staticfiles/
17+
18+
### Django.Python Stack ###
19+
# Byte-compiled / optimized / DLL files
20+
*.py[cod]
21+
*$py.class
22+
23+
# C extensions
24+
*.so
25+
26+
# Distribution / packaging
27+
.Python
28+
build/
29+
develop-eggs/
30+
dist/
31+
downloads/
32+
eggs/
33+
.eggs/
34+
lib/
35+
lib64/
36+
parts/
37+
sdist/
38+
var/
39+
wheels/
40+
share/python-wheels/
41+
*.egg-info/
42+
.installed.cfg
43+
*.egg
44+
MANIFEST
45+
46+
# PyInstaller
47+
# Usually these files are written by a python script from a template
48+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
49+
*.manifest
50+
*.spec
51+
52+
# Installer logs
53+
pip-log.txt
54+
pip-delete-this-directory.txt
55+
56+
# Unit test / coverage reports
57+
htmlcov/
58+
.tox/
59+
.nox/
60+
.coverage
61+
.coverage.*
62+
.cache
63+
nosetests.xml
64+
coverage.xml
65+
*.cover
66+
*.py,cover
67+
.hypothesis/
68+
.pytest_cache/
69+
cover/
70+
71+
# Translations
72+
*.mo
73+
74+
# Django stuff:
75+
76+
# Flask stuff:
77+
instance/
78+
.webassets-cache
79+
80+
# Scrapy stuff:
81+
.scrapy
82+
83+
# Sphinx documentation
84+
docs/_build/
85+
86+
# PyBuilder
87+
.pybuilder/
88+
target/
89+
90+
# Jupyter Notebook
91+
.ipynb_checkpoints
92+
93+
# IPython
94+
profile_default/
95+
ipython_config.py
96+
97+
# pyenv
98+
# For a library or package, you might want to ignore these files since the code is
99+
# intended to run in multiple environments; otherwise, check them in:
100+
# .python-version
101+
102+
# pipenv
103+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
104+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
105+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
106+
# install all needed dependencies.
107+
#Pipfile.lock
108+
109+
# poetry
110+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
111+
# This is especially recommended for binary packages to ensure reproducibility, and is more
112+
# commonly ignored for libraries.
113+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
114+
#poetry.lock
115+
116+
# pdm
117+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
118+
#pdm.lock
119+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
120+
# in version control.
121+
# https://pdm.fming.dev/#use-with-ide
122+
.pdm.toml
123+
124+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
125+
__pypackages__/
126+
127+
# Celery stuff
128+
celerybeat-schedule
129+
celerybeat.pid
130+
131+
# SageMath parsed files
132+
*.sage.py
133+
134+
# Environments
135+
.env
136+
.venv
137+
env/
138+
venv/
139+
ENV/
140+
env.bak/
141+
venv.bak/
142+
venv_notion/
143+
144+
# Spyder project settings
145+
.spyderproject
146+
.spyproject
147+
148+
# Rope project settings
149+
.ropeproject
150+
151+
# mkdocs documentation
152+
/site
153+
154+
# mypy
155+
.mypy_cache/
156+
.dmypy.json
157+
dmypy.json
158+
159+
# Pyre type checker
160+
.pyre/
161+
162+
# pytype static type analyzer
163+
.pytype/
164+
165+
# Cython debug symbols
166+
cython_debug/

Projects/NotionClone/account/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'account'
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from django import forms
2+
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
3+
from django.contrib.auth.models import User
4+
from django.forms import widgets
5+
from django.contrib.auth.forms import PasswordChangeForm
6+
from django.contrib.auth import get_user_model
7+
8+
9+
class LoginUserForm(AuthenticationForm):
10+
def __init__(self, *args, **kwargs):
11+
super().__init__(*args, **kwargs)
12+
self.fields["username"].widget = widgets.TextInput(attrs={
13+
"class":"form-control",
14+
"placeholder" : "Enter your username here"
15+
})
16+
17+
self.fields["password"].widget = widgets.PasswordInput(attrs={
18+
"class":"form-control",
19+
"placeholder" : "Password"
20+
})
21+
22+
23+
class RegisterUserForm(UserCreationForm):
24+
class Meta:
25+
model = User
26+
fields = ("first_name","last_name","username","email",)
27+
28+
def __init__(self, *args, **kwargs):
29+
super().__init__(*args, **kwargs)
30+
self.fields["first_name"].widget = widgets.TextInput(attrs={"class":"form-control"})
31+
self.fields["last_name"].widget = widgets.TextInput(attrs={"class":"form-control"})
32+
self.fields["username"].widget = widgets.TimeInput(attrs={"class":"form-control"})
33+
self.fields["email"].widget = widgets.EmailInput(attrs={"class":"form-control"})
34+
self.fields["email"].required = True
35+
self.fields["password1"].widget = widgets.PasswordInput(attrs={"class":"form-control"})
36+
self.fields["password2"].widget = widgets.PasswordInput(attrs={"class":"form-control"})
37+
38+
def clean_email(self):
39+
email = self.cleaned_data.get('email')
40+
if User.objects.filter(email=email).exists():
41+
self.add_error("email","This address already used")
42+
return email
43+
44+
def clean_username(self):
45+
username = self.cleaned_data.get('username')
46+
if User.objects.filter(username=username).exists():
47+
self.add_error("username","This username already used")
48+
return username
49+
50+
51+
class CustomPasswordChangeForm(PasswordChangeForm):
52+
old_password = forms.CharField(
53+
label="Old Password",
54+
widget=forms.PasswordInput(attrs={'class': 'form-control'})
55+
)
56+
new_password1 = forms.CharField(
57+
label="New Password",
58+
widget=forms.PasswordInput(attrs={'class': 'form-control'})
59+
)
60+
new_password2 = forms.CharField(
61+
label="Confirm New Password",
62+
widget=forms.PasswordInput(attrs={'class': 'form-control'})
63+
)
64+
65+
# Ekstra alanlar veya özelleştirmeler ekleyebilirsiniz
66+
67+
class Meta:
68+
model = get_user_model()

Projects/NotionClone/account/migrations/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.db import models
2+
from django.shortcuts import render
3+
from django.contrib.auth import update_session_auth_hash
4+
from django.contrib import messages
5+
from django.contrib.auth.forms import PasswordChangeForm
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.urls import path
2+
from . import views
3+
from .views import change_password
4+
5+
6+
urlpatterns = [
7+
path('login/', views.user_login, name='user_login'),
8+
path("register/",views.user_register ,name="user_register"),
9+
path("logout/",views.user_logout ,name="user_logout"),
10+
path('change-password/', views.change_password, name='change_password'),
11+
12+
]
13+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from django.shortcuts import render,redirect
2+
from django.contrib.auth import authenticate,login,logout
3+
from account.forms import LoginUserForm ,RegisterUserForm
4+
from django.contrib import messages
5+
from django.views.generic.edit import FormView
6+
from django.views.decorators.csrf import csrf_exempt
7+
from django.contrib.auth.decorators import login_required
8+
from django.shortcuts import render, redirect
9+
from django.shortcuts import render, redirect
10+
from django.contrib.auth.decorators import login_required
11+
from .forms import CustomPasswordChangeForm
12+
from django.contrib.auth import update_session_auth_hash
13+
14+
15+
16+
17+
@csrf_exempt
18+
def user_login(request):
19+
if request.method == "POST":
20+
form = LoginUserForm(request, data=request.POST)
21+
22+
if form.is_valid():
23+
username = form.cleaned_data['username']
24+
password = form.cleaned_data['password']
25+
user = authenticate(request, username=username, password=password)
26+
27+
if user is not None and user.is_active:
28+
login(request, user)
29+
return redirect('add_page')
30+
else:
31+
return render(request, 'account/login.html', {'form': form})
32+
else:
33+
return render(request, 'account/login.html', {'form': form})
34+
35+
form = LoginUserForm()
36+
return render(request, 'account/login.html', {'form': form})
37+
38+
39+
@csrf_exempt
40+
def user_register(request):
41+
if request.method == "POST":
42+
form = RegisterUserForm(request.POST)
43+
if form.is_valid():
44+
form.save()
45+
return redirect("user_login")
46+
else:
47+
return render(request, "account/register.html",{"form":form})
48+
49+
form = RegisterUserForm()
50+
return render(request, "account/register.html", {"form": form})
51+
52+
53+
54+
def user_logout(request):
55+
logout(request)
56+
return redirect('homepage')
57+
58+
from django.contrib import messages
59+
60+
@csrf_exempt
61+
def change_password(request):
62+
if request.method == 'POST':
63+
form = CustomPasswordChangeForm(user=request.user, data=request.POST)
64+
if form.is_valid():
65+
print("1")
66+
user = form.save()
67+
update_session_auth_hash(request, user) # Oturum açıkken oturumun geçerliliğini koru
68+
messages.success(request, 'Your password was successfully updated!')
69+
return redirect('members_settings') # Şifre değiştikten sonra profil sayfasına yönlendir
70+
else:
71+
# Form geçerli değilse, hata mesajlarını alıp kullanıcıya göster
72+
print("2")
73+
for field, errors in form.errors.items():
74+
for error in errors:
75+
messages.error(request, f'{field}: {error}')
76+
else:
77+
print("1")
78+
form = CustomPasswordChangeForm(user=request.user)
79+
return render(request, 'members_settings.html', {'form': form})
80+
81+
82+
83+
84+
85+
86+
87+

0 commit comments

Comments
 (0)