Skip to content

Commit

Permalink
Changed authentication structure
Browse files Browse the repository at this point in the history
  • Loading branch information
riadelimemmedov committed Mar 24, 2024
1 parent cdcd7ba commit e9e5bdc
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 160 deletions.
Empty file.
3 changes: 0 additions & 3 deletions backend/apps/authentication/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions backend/apps/authentication/apps.py

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions backend/apps/authentication/models.py

This file was deleted.

24 changes: 0 additions & 24 deletions backend/apps/authentication/serializers.py

This file was deleted.

3 changes: 0 additions & 3 deletions backend/apps/authentication/tests.py

This file was deleted.

56 changes: 0 additions & 56 deletions backend/apps/authentication/urls.py

This file was deleted.

23 changes: 0 additions & 23 deletions backend/apps/authentication/views.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/apps/user_profile/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class ProfileAdmin(admin.ModelAdmin):
list_display = [
"user",
"full_name",
"country",
"city",
"adress",
"slug",
"created",
"modified",
"wallet_address",
]
list_display_links = ["user", "wallet_address"]
list_display_links = ["user", "full_name"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.1 on 2024-03-24 15:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("user_profile", "0002_remove_profile_full_name_profile_wallet_address"),
]

operations = [
migrations.RemoveField(
model_name="profile",
name="wallet_address",
),
migrations.AddField(
model_name="profile",
name="full_name",
field=models.CharField(
blank=True, max_length=150, verbose_name="Full name"
),
),
]
35 changes: 14 additions & 21 deletions backend/apps/user_profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from abstract.constants import Genders, Status, Types
from apps.users.models import CustomUser
from config.helpers import is_valid_wallet_address, setFullName
from config.helpers import setFullName

# Create your models here.

Expand Down Expand Up @@ -52,23 +52,14 @@ class Profile(TimeStampedModel):
_("First name"), max_length=150, blank=True, null=True
)
last_name = models.CharField(_("Last name"), max_length=150, blank=True, null=True)
# full_name = models.CharField(_("Full name"), max_length=150, blank=True)
full_name = models.CharField(_("Full name"), max_length=150, blank=True)
profile_key = RandomCharField(
_("Profile key"), length=12, unique=True, blank=True, include_alpha=True
)
country = models.CharField(verbose_name=_("Country"), max_length=50, blank=True)
city = models.CharField(_("City"), max_length=50, null=True, blank=True)
adress = models.CharField(_("Adress"), max_length=50, null=True, blank=True)
additional_information = models.TextField(_("Additional Information"), blank=True)
wallet_address = models.CharField(
_("Wallet address"),
unique=True,
db_index=True,
max_length=100,
blank=True,
null=True,
validators=[is_valid_wallet_address],
)
is_active = models.BooleanField(_("Is active"), default=False)

objects = ProfileManager()
Expand Down Expand Up @@ -106,22 +97,24 @@ class Meta:
verbose_name_plural = _("Profiles")

def save(self, *args, **kwargs):
if not self.user.username:
is_exists = __class__.objects.filter(user=self.user.username).exists()
if not self.full_name:
full_name = setFullName(
self.first_name if self.first_name is not None else "",
self.last_name if self.last_name is not None else "",
)
is_exists = __class__.objects.filter(full_name=full_name).exists()
if is_exists:
self.user.username = f"{self.user.username}_{self.profile_key}"
self.full_name = f"{full_name}_{self.profile_key}"
else:
self.user.username = f"{self.user.username}"
self.slug = slugify(self.user.username)
else:
self.slug = slugify(self.user.username)
self.full_name = f"{full_name}"
self.slug = slugify(self.full_name)
super(Profile, self).save(*args, **kwargs)

def get_user_name(self):
return self.user.username
def get_full_name(self):
return self.full_name

def __str__(self):
return self.user.username
return self.full_name


# create_user_profile
Expand Down
10 changes: 10 additions & 0 deletions backend/apps/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from apps.user_profile.models import Profile

from .forms import CustomUserChangeForm, CustomUserCreationForm
from .models import CustomUser

# Register your models here.


# !ProfileInline
class ProfileInline(admin.StackedInline):
model = Profile
can_delete = False
verbose_name_plural = "Profiles"


# !CustomUserAdmin
class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
Expand Down Expand Up @@ -52,6 +61,7 @@ class CustomUserAdmin(UserAdmin):
)
search_fields = ("email",)
ordering = ("email",)
inlines = (ProfileInline,)


admin.site.register(CustomUser, CustomUserAdmin)
4 changes: 2 additions & 2 deletions backend/apps/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = CustomUser
exclude = ("email",)
fields = ("email",)


# !CustomUserChangeForm
class CustomUserChangeForm(UserChangeForm):
class Meta:
model = CustomUser
exclude = ("email",)
fields = ("email",)
16 changes: 16 additions & 0 deletions backend/apps/users/migrations/0006_delete_customuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 5.0.1 on 2024-03-24 14:30

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("users", "0005_customuser_email"),
]

operations = [
migrations.DeleteModel(
name="CustomUser",
),
]
Loading

0 comments on commit e9e5bdc

Please sign in to comment.