Skip to content

Commit

Permalink
create returns token
Browse files Browse the repository at this point in the history
  • Loading branch information
Re-Krass committed Jun 12, 2018
1 parent eba86f5 commit da9c343
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions djangoblockchained_backend/skbrest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
from django.conf import settings
# Email Stuff E

jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

class UserSerializer(serializers.ModelSerializer):
password = serializers.CharField(write_only=True)
token = serializers.SerializerMethodField()
print("token:", token)

def get_token(self, obj):
return jwt_encode_handler(jwt_payload_handler(obj))

def create(self, validated_data):

Expand All @@ -35,8 +42,7 @@ def create(self, validated_data):
student.save()

uid = urlsafe_base64_encode(force_bytes(user.pk)).decode()
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER


payload = jwt_payload_handler(user)
token = jwt_encode_handler(payload)
Expand All @@ -62,7 +68,7 @@ def create(self, validated_data):

class Meta:
model = User
fields = ["password", "username", "email"]
fields = ["password", "username", "email", "token"]


class CourseSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit da9c343

Please sign in to comment.