Skip to content

Commit

Permalink
add token to current user
Browse files Browse the repository at this point in the history
  • Loading branch information
muremwa committed Dec 19, 2022
1 parent 7ed835d commit faba5d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Meta:
def validate(self, data):
if re.search(r'@', data.get('username', '')):
raise ValidationError(_('no @ signs on username'), code="at_sign")

if data.get('email', None) is None:
raise ValidationError(_('Email field is missing'), code='email-mia')

Expand Down Expand Up @@ -67,10 +67,18 @@ class Meta:
class ApiUserSerializer(serializers.ModelSerializer):
full_name = serializers.CharField(source='get_full_name')
profile = serializers.ImageField(source='profile.image')
token = serializers.CharField(source='auth_token.key')

class Meta:
model = User
fields = ('id', 'username', 'full_name', 'profile')
fields = ('id', 'username', 'full_name', 'profile', 'token')

def __init__(self, *args, **kwargs):
if kwargs.get('token'):
kwargs.pop('token')
else:
self.fields.pop('token')
super().__init__(*args, **kwargs)


class ApiProfileSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class AllCommentsV2(views.APIView, CommentProcessor):
def get(self, *args, **kwargs):
note = Note.objects.get(pk=kwargs.get('note_pk'))
return Response({
'current_user': ApiUserSerializer(self.request.user).data,
'current_user': ApiUserSerializer(self.request.user, token=True).data,
'notes_info': ApiNoteSerializer(note).data
})

Expand Down

0 comments on commit faba5d6

Please # to comment.