Open chayapan opened 8 months ago
See this notes:
Use the standard Django auth module from https://docs.djangoproject.com/en/5.0/topics/auth/default/#all-authentication-views
Use BaseUserCreationForm to register new accounts. https://docs.djangoproject.com/en/5.0/topics/auth/default/#django.contrib.auth.forms.BaseUserCreationForm
We might explore how to use JWT and see if we can add it to the project.
This project seem promising https://github.com/humanitec/django-oauth-toolkit-jwt
But this is a distraction...
Add messages framework to pass message between web session
The simplest and most up to date is https://stackoverflow.com/questions/16857450/how-to-register-users-in-django-rest-framework
from rest_framework import serializers
from django.contrib.auth import get_user_model # If used custom user model
UserModel = get_user_model()
class UserSerializer(serializers.ModelSerializer):
password = serializers.CharField(write_only=True)
def create(self, validated_data):
user = UserModel.objects.create_user(
username=validated_data['username'],
password=validated_data['password'],
)
return user
class Meta:
model = UserModel
# Tuple of serialized model fields (see link [2])
fields = ( "id", "username", "password", )
from rest_framework import permissions
from rest_framework.generics import CreateAPIView
from django.contrib.auth import get_user_model # If used custom user model
from .serializers import UserSerializer
class CreateUserView(CreateAPIView):
model = get_user_model()
permission_classes = [
permissions.AllowAny # Or anon users can't register
]
serializer_class = UserSerializer
Use password less signup for Django provided by this library. drfpasswordless https://github.com/aaronn/django-rest-framework-passwordless
As a User: I want to register an account on the FavLinks website.
Objective: To create a new user account with a unique username and secure password.
Expectations: