This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rest_framework import serializers | |
| from .models import Profile | |
| from Door.models import Door | |
| from Door.serializers import DoorSerializer | |
| class UserSerializer(serializers.ModelSerializer): | |
| password = serializers.CharField(style={'input_type':'password'},write_only=True,required=True) | |
| password2 = serializers.CharField(style={'input_type':'password'},write_only=True,required=True) | |
| profile_slug = serializers.SlugField(source='profile.slug',read_only=True) | |
| profile_image = serializers.ImageField(source='profile.image',read_only=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @receiver(post_save, sender=User) | |
| def create_user_profile(sender, instance, created, **kwargs): | |
| if created : | |
| profile_obj = Profile.objects.create(user=instance) | |
| @receiver(pre_save, sender=Profile) | |
| def set_profile_slug(sender, instance, **kwargs): | |
| if not instance.slug : | |
| instance.slug = unique_slug_generator(instance) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib import admin | |
| admin.site.register(Profile) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| class Profile(models.Model): | |
| user = models.OneToOneField(User,on_delete=models.CASCADE) | |
| image = models.ImageField(default='defaultProfile.png') | |
| slug = models.SlugField(blank=True,null=True) | |
| @property | |
| def owner(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib import admin | |
| from django.contrib.auth.models import Group | |
| from django.contrib.auth.admin import UserAdmin as BaseUserAdmin | |
| from .forms import UserAdminCreationForm, UserAdminChangeForm | |
| from .models import User | |
| class UserAdmin(BaseUserAdmin): | |
| form = UserAdminChangeForm | |
| add_form = UserAdminCreationForm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import forms | |
| from django.contrib.auth.forms import ReadOnlyPasswordHashField | |
| from .models import User | |
| class RegisterForm(forms.ModelForm): | |
| password = forms.CharField(widget=forms.PasswordInput) | |
| password2 = forms.CharField(label='Confirm password', widget=forms.PasswordInput) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| from django.contrib.auth.models import ( | |
| BaseUserManager, AbstractBaseUser | |
| ) | |
| class UserManager(BaseUserManager): | |
| def create_user(self, email, username, password=None): | |
| if not email: | |
| raise ValueError('Users must have an email address') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Porfile</title> | |
| </head> | |
| <body> | |
| <h2>Hello {{user.username}}</h2> | |
| <p><a href="{% url 'logout' %}">logout</a></p> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import render,redirect | |
| from django.contrib.auth import logout | |
| def logout_view(request): | |
| logout(request) | |
| return redirect('/') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Login</title> | |
| </head> | |
| <body> | |
| <form method='POST' > {% csrf_token %} | |
| {{form.as_p}} | |
| <input type='submit' name='login' /> | |
| </form> | |
| </body> |