This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
people/src/backend/mailbox_oauth2/serializers.py
Quentin BEY db6cdadd72 (oidc) add django-oauth-toolkit w/ configuration
This allows to use `people` as an identity provider using
OIDC and local users.
This commit is partial, because it does not manage a way to
create "local" users and the login page is the admin one, which
can't be used for non staff users or login with email.
2025-03-03 12:24:43 +01:00

49 lines
1.4 KiB
Python

"""
Serializers for the mailbox_oauth2 app.
"""
from django.contrib.auth import authenticate
from rest_framework import serializers
class LoginSerializer(serializers.Serializer):
"""
Serializer for user login authentication.
Validates the email and password fields required for user authentication.
"""
email = serializers.EmailField(
help_text="User's email address for authentication",
required=True,
)
password = serializers.CharField(
write_only=True,
help_text="User's password for authentication",
required=True,
)
def create(self, validated_data):
"""Do not allow creating instances from this serializer."""
raise RuntimeError("LoginSerializer does not support create method")
def update(self, instance, validated_data):
"""Do not allow updating instances from this serializer."""
raise RuntimeError("LoginSerializer does not support update method")
def validate(self, attrs):
"""
Validate the email and password fields.
"""
email = attrs.get("email")
password = attrs.get("password")
if not (email and password):
raise serializers.ValidationError('Must include "email" and "password"')
attrs["user"] = authenticate(
self.context["request"], email=email, password=password
)
return attrs