Example #1
0
    def validate(self, attrs):
        data = super().validate(attrs)
        serializer = UserSerializerWithToken(self.user).data

        for k, v in serializer.items():
            data[k] = v

        return data
Example #2
0
    def validate(self, attrs):
        data = super().validate(attrs)

        # data['username'] = self.user.username
        # data['email'] = self.user.email
        serializer = UserSerializerWithToken(self.user).data

        for k, v in serializer.items():
            data[k] = v

        return data
Example #3
0
def registerUser(request):
    data = request.data

    try:
        user = User.objects.create(first_name=data['name'],
                                   username=data['email'],
                                   email=data['email'],
                                   password=make_password(data['password']))
        serializer = UserSerializerWithToken(user, many=False)
        return Response(serializer.data)
    except:
        message = {'detail': 'user with this mail already exist'}
        return Response(message, status=status.HTTP_400_BAD_REQUEST)
Example #4
0
def updateUserProfile(request):
    user = request.user
    serializer = UserSerializerWithToken(user, many=False)
    data = request.data
    user.first_name = data['name']
    user.username = data['email']
    user.email = data['email']

    if data['password'] != '':
        user.password = make_password(data['password'])

    user.save()

    return Response(serializer.data)
Example #5
0
def updateUserProfile(request):
    user = request.user
    serializer = UserSerializerWithToken(user, many=False)
    data = request.data
    if data["name"] != "":
        fullname = data['name'].split(" ")
        if len(fullname) == 1:
            user.first_name = fullname[0]

        if len(fullname) == 2:
            user.first_name = fullname[0]
            user.last_name = fullname[1]

    if data["email"] != "":
        user.username = data["email"]
        user.email = data["email"]

    if (data)['password'] != '':
        user.password = make_password(str(data["password"]))

    user.save()

    return Response(serializer.data)
Example #6
0
def updateUserProfile(request):
    user = request.user
    serializer = UserSerializerWithToken(user, many=False)

    data = request.data
    user.first_name = data['name']
    user.username = data['email']
    user.email = data['email']
    user.isFarmer = data['isFarmer']
    user.locationX = data['locationX']
    user.locationY = data['locationY']
    user.farmName = data['farmName']
    user.address = data['address']
    user.description = data['description']
    user.farmerPoint = data['farmerPoint']
    user.numReviews = data['numReviews']

    if data['password'] != '':
        user.password = make_password(data['password'])

    user.save()

    return Response(serializer.data)