Skip to content

Commit ed78a45

Browse files
account done
1 parent 380ec10 commit ed78a45

29 files changed

+362
-4
lines changed

accounts/__init__.py

Whitespace-only changes.
145 Bytes
Binary file not shown.
186 Bytes
Binary file not shown.
428 Bytes
Binary file not shown.
1.8 KB
Binary file not shown.
2.56 KB
Binary file not shown.

accounts/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

accounts/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountsConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "accounts"

accounts/forms.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from django import forms
2+
from django.contrib.auth.forms import ReadOnlyPasswordHashField
3+
from django.contrib.auth import get_user_model
4+
5+
6+
7+
User = get_user_model()
8+
9+
10+
class RegistrationUserForm(forms.ModelForm):
11+
password1 = forms.CharField(label='Şifrə', widget=forms.PasswordInput(attrs={"placeholder": "Şifrə"}))
12+
password2 = forms.CharField(label='Təkrar şifrə', widget=forms.PasswordInput(attrs={"placeholder": "Təkrar şifrə"}))
13+
14+
15+
class Meta:
16+
model = User
17+
fields = ("name", "email", "password1", "password2")
18+
19+
def __init__(self, *args, **kwargs):
20+
super(RegistrationUserForm, self).__init__(*args, **kwargs)
21+
for field in self.fields:
22+
self.fields[field].required = True
23+
self.fields["name"].widget.attrs.update({"placeholder": "Adınızı daxil edin", "id":"form3Example1c"})
24+
self.fields["email"].widget.attrs.update({"placeholder": "E-poçtunuzu daxil edin", "id": "form3Example3c"})
25+
26+
def clean(self):
27+
email = self.cleaned_data.get("email")
28+
password1 = self.cleaned_data.get("password1")
29+
password2 = self.cleaned_data.get("password2")
30+
31+
32+
33+
if not (password1 and password2 and password1 == password2):
34+
raise forms.ValidationError("Şifrələr uyğun deyil")
35+
36+
if len(password1) < 8:
37+
raise forms.ValidationError("Şifrənin uzunluğu minimum 8 simvoldan ibarət olmalıdır.")
38+
39+
if User.objects.filter(email=email).exists():
40+
raise forms.ValidationError("Bu nömrə ilə hesab mövcuddur")
41+
42+
return self.cleaned_data

accounts/migrations/0001_initial.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Generated by Django 4.2.7 on 2024-02-22 07:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
initial = True
8+
9+
dependencies = []
10+
11+
operations = [
12+
migrations.CreateModel(
13+
name="MyUser",
14+
fields=[
15+
(
16+
"id",
17+
models.BigAutoField(
18+
auto_created=True,
19+
primary_key=True,
20+
serialize=False,
21+
verbose_name="ID",
22+
),
23+
),
24+
("password", models.CharField(max_length=128, verbose_name="password")),
25+
(
26+
"last_login",
27+
models.DateTimeField(
28+
blank=True, null=True, verbose_name="last login"
29+
),
30+
),
31+
("email", models.EmailField(max_length=120, unique=True)),
32+
(
33+
"name",
34+
models.CharField(
35+
blank=True,
36+
max_length=40,
37+
null=True,
38+
verbose_name="Istifadəçi adı",
39+
),
40+
),
41+
(
42+
"surname",
43+
models.CharField(
44+
blank=True,
45+
max_length=40,
46+
null=True,
47+
verbose_name="Istifadəçi soyadı",
48+
),
49+
),
50+
(
51+
"activation_code",
52+
models.CharField(blank=True, max_length=50, null=True, unique=True),
53+
),
54+
(
55+
"password_reset_code",
56+
models.CharField(blank=True, max_length=120, null=True),
57+
),
58+
("created_at", models.DateTimeField(auto_now_add=True)),
59+
("is_active", models.BooleanField(default=True)),
60+
("is_staff", models.BooleanField(default=False)),
61+
("is_superuser", models.BooleanField(default=False)),
62+
],
63+
options={
64+
"verbose_name": "İstifadəçi",
65+
"verbose_name_plural": "İstifadəçilər",
66+
"ordering": ["-created_at"],
67+
},
68+
),
69+
]

accounts/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

accounts/models.py

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from django.db import models
2+
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
3+
4+
5+
6+
class MyUserManager(BaseUserManager):
7+
def create_user(self, email, password=None, is_active=True, is_staff=False, is_superuser=False):
8+
if not email:
9+
raise ValueError("İstifadəçinin elektron-poçtu olmalıdır")
10+
user = self.model(
11+
email=self.normalize_email(email)
12+
)
13+
user.set_password(password)
14+
user.is_staff = is_staff
15+
user.is_superuser = is_superuser
16+
user.is_active = is_active
17+
user.save(using=self._db)
18+
return user
19+
20+
def create_superuser(self, email, password=None):
21+
user = self.create_user(
22+
email=self.normalize_email(email),
23+
password=password
24+
)
25+
user.is_staff = True
26+
user.is_superuser = True
27+
user.save(using=self._db)
28+
return user
29+
30+
31+
class MyUser(AbstractBaseUser):
32+
email = models.EmailField(max_length=120, unique=True)
33+
name = models.CharField(max_length=40, verbose_name="Istifadəçi adı", blank=True, null=True)
34+
surname = models.CharField(max_length=40, verbose_name="Istifadəçi soyadı", blank=True, null=True)
35+
activation_code = models.CharField(max_length=50, unique=True, blank=True, null=True)
36+
password_reset_code = models.CharField(max_length=120, blank=True, null=True)
37+
created_at = models.DateTimeField(auto_now_add=True)
38+
39+
is_active = models.BooleanField(default=True)
40+
is_staff = models.BooleanField(default=False)
41+
is_superuser = models.BooleanField(default=False)
42+
43+
objects = MyUserManager()
44+
45+
USERNAME_FIELD = 'email'
46+
47+
class Meta:
48+
ordering = ['-created_at']
49+
verbose_name = 'İstifadəçi'
50+
verbose_name_plural = 'İstifadəçilər'
51+
52+
def __str__(self):
53+
return str(self.email)
54+
55+
def get_full_name(self):
56+
if self.surname:
57+
return '%s %s' % (self.name, self.surname)
58+
return self.name
59+
60+
def has_perm(self, perm, obj=None):
61+
return self.is_superuser
62+
63+
def has_module_perms(self, app_label):
64+
return True
65+
66+

accounts/permissions.py

Whitespace-only changes.

accounts/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

accounts/urls.py

Whitespace-only changes.

accounts/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.
7 Bytes
Binary file not shown.

chat/__pycache__/urls.cpython-310.pyc

84 Bytes
Binary file not shown.
1 KB
Binary file not shown.

chat/consumers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def connect(self):
1818
print(self.user)
1919
if not self.user.is_anonymous:
2020
# If the user is authenticated, use their username
21-
self.username = self.user.username
21+
self.username = self.user.email
2222
else:
2323
# If the user is not authenticated, use a default value or handle as needed
2424
self.username = "Anonymous"

chat/urls.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from chat.views import *
33

44
urlpatterns = [
5-
path("", index_view, name='index'),
5+
path("selection/", index_view, name='index'),
66
path("<str:room_name>/", room_view, name='room'),
7+
path("", login_view, name='login'),
8+
path("register", register_view, name='register'),
79
]

chat/views.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
from django.shortcuts import render
2+
from django.contrib.auth import authenticate, login, logout
3+
from django.contrib import messages
4+
from django.shortcuts import render, redirect
5+
from accounts.forms import RegistrationUserForm
6+
27

38
def index_view(request):
49
context = {}
510
return render(request, "index.html", context)
611

712
def room_view(request, room_name):
813
user = request.user
9-
return render(request, "room.html", {"room_name": room_name, "user": user})
14+
return render(request, "room.html", {"room_name": room_name, "user": user})
15+
16+
def login_view(request):
17+
if request.method == 'POST':
18+
email = request.POST.get("email")
19+
pwd = request.POST.get("pwd")
20+
user = authenticate(request, email=email, password=pwd)
21+
22+
if user is not None:
23+
login(request, user)
24+
return redirect("index")
25+
else:
26+
messages.error(request, "Wrong email or password..")
27+
28+
context = {
29+
30+
}
31+
return render(request, "login.html", context)
32+
33+
def register_view(request):
34+
35+
form = RegistrationUserForm()
36+
if request.method == 'POST':
37+
form = RegistrationUserForm(request.POST or None)
38+
if form.is_valid():
39+
new_user = form.save(commit=False)
40+
new_user.set_password(form.cleaned_data.get("password1"))
41+
new_user.is_active = True
42+
new_user.save()
43+
return redirect("login")
44+
else:
45+
print(form.errors)
46+
context = {
47+
"form": form,
48+
}
49+
return render(request, 'register.html',context)
50+
-73 Bytes
Binary file not shown.

core/settings.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

28-
ALLOWED_HOSTS = ['.vercel.app','now.sh','127.0.0.1','localhost', 'intiqamquluzada.pythonanywhere.com']
28+
ALLOWED_HOSTS = ['127.0.0.1','localhost', '45.155.125.243']
2929

3030

3131
# Application definition
@@ -40,6 +40,7 @@
4040
'django.contrib.messages',
4141
'django.contrib.staticfiles',
4242
'chat',
43+
'accounts',
4344
]
4445

4546
MIDDLEWARE = [
@@ -70,6 +71,9 @@
7071
},
7172
]
7273

74+
AUTH_USER_MODEL = "accounts.MyUser"
75+
76+
7377
WSGI_APPLICATION = 'core.wsgi.application'
7478
ASGI_APPLICATION = 'core.asgi.application'
7579
CHANNEL_LAYERS = {

db.sqlite3

-28 KB
Binary file not shown.

templates/login.html

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Log in for talking</title>
6+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
7+
</head>
8+
<body style="display: flex; justify-content: center; align-items:center;">
9+
<form method="post">
10+
{% csrf_token %}
11+
<!-- Email input -->
12+
<div class="form-outline mt-3">
13+
<input type="email" id="form2Example1" class="form-control" name="email"/>
14+
<label class="form-label" for="form2Example1">Email address</label>
15+
</div>
16+
17+
<!-- Password input -->
18+
<div class="form-outline mb-4">
19+
<input type="password" id="form2Example2" class="form-control" name="pwd"/>
20+
<label class="form-label" for="form2Example2">Password</label>
21+
</div>
22+
23+
24+
25+
<!-- Submit button -->
26+
<button type="submit" class="btn btn-primary btn-block mb-4">Sign in</button>
27+
28+
<!-- Register buttons -->
29+
<div class="text-center">
30+
<p>Not a member? <a href="{% url 'register' %}">Register</a></p>
31+
</div>
32+
</form>
33+
34+
35+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)