Initial commit that merge both the front end and the API in the same repository
This commit is contained in:
commit
76f98b74dd
285 changed files with 51318 additions and 0 deletions
34
api/funkwhale_api/users/views.py
Normal file
34
api/funkwhale_api/users/views.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from rest_framework.response import Response
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import list_route
|
||||
|
||||
from rest_auth.registration.views import RegisterView as BaseRegisterView
|
||||
from allauth.account.adapter import get_adapter
|
||||
|
||||
from . import models
|
||||
from . import serializers
|
||||
|
||||
|
||||
class RegisterView(BaseRegisterView):
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
if not self.is_open_for_signup(request):
|
||||
r = {
|
||||
'detail': 'Registration has been disabled',
|
||||
}
|
||||
return Response(r, status=403)
|
||||
return super().create(request, *args, **kwargs)
|
||||
|
||||
def is_open_for_signup(self, request):
|
||||
return get_adapter().is_open_for_signup(request)
|
||||
|
||||
|
||||
class UserViewSet(viewsets.GenericViewSet):
|
||||
queryset = models.User.objects.all()
|
||||
serializer_class = serializers.UserSerializer
|
||||
|
||||
@list_route(methods=['get'])
|
||||
def me(self, request, *args, **kwargs):
|
||||
"""Return information about the current user"""
|
||||
serializer = self.serializer_class(request.user)
|
||||
return Response(serializer.data)
|
||||
Loading…
Add table
Add a link
Reference in a new issue