def signup(self, request): """ 使用 username, email, password 进行注册 """ # 不太优雅的写法 # username = request.data.get('username') # if not username: # return Response("username required", status=400) # password = request.data.get('password') # if not password: # return Response("password required", status=400) # if User.objects.filter(username=username).exists(): # return Response("password required", status=400) serializer = SignupSerializer(data=request.data) if not serializer.is_valid(): return Response( { 'success': False, 'message': "Please check input", 'errors': serializer.errors, }, status=400) user = serializer.save() # Create UserProfile object user.profile django_login(request, user) return Response({ 'success': True, 'user': UserSerializer(user).data, }, status=201)
def signup(self, request): """ username, email, password to signup :param request: :return: """ serializer = SignupSerializer(data=request.data) if not serializer.is_valid(): return Response( { 'success': False, 'message': "Please check input", 'errors': serializer.errors, }, status=400) user = serializer.save() # create UserProfile object user.profile django_login(request, user) return Response({ 'success': True, 'user': UserSerializer(user).data, })
def signup(self, request): serializer = SignupSerializer(data=request.data) if not serializer.is_valid(): return Response( { 'success': False, 'message': 'Please check input', 'errors': serializer.errors }, status=400) user = serializer.save() # create a new profile for the new user user.profile # automatically login django_login(request, user) return Response( { 'success': True, 'user': UserSerializer(instance=user).data }, status=201)
def post(self, request, format='json'): serializer = SignupSerializer(data=request.data) if serializer.is_valid(): user = serializer.save() if user: token = Token.objects.create(user=user) json = serializer.data json['token'] = token.key return Response(json, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def signup(self, request): serializer = SignupSerializer(data=request.data) if not serializer.is_valid(): return Response({ 'success': False, 'message': "Please check input", 'errors': serializer.errors, }, status = 400) user = serializer.save() django_login(request, user) return Response({ 'success': True, 'user': UserSerializer(user).data, })
def signup(self, request): serializer = SignupSerializer(data=request.data) if not serializer.is_valid(): return Response( { "success": False, "message": "Please check input.", "errors": serializer.errors, }, status=400) user = serializer.save() django_login(request, user) return Response({ "success": True, "user": UserSerializer(user).data, }, status=201)
def signup(self, request): """ use username, email, pwd to registration. """ serializer = SignupSerializer(data=request.data) if not serializer.is_valid(): return Response( { 'success': False, 'message': "Please check input", 'errors': serializer.errors }, status=400) user = serializer.save() django_login(request, user) return Response({ 'success': True, 'user': UserSerializer(user).data }, status=201)
def signup(self, request): serializer = SignupSerializer(data=request.data) # check if serializer is valid if not serializer.is_valid(): return Response( { "success": False, "message": "Please check input", "errors": serializer.errors, }, status=400) user = serializer.save() # Create UserProfile object user.profile django_login(request, user) return Response({ 'success': True, 'user': UserSerializer(user).data, }, status=201)