Created
June 13, 2020 16:18
-
-
Save tmirza-dinCloud/1313c006eb238483e3310d65dcadb507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from demo.models import User | |
from rest_framework import serializers | |
import pyotp | |
class UserSerializer(serializers.ModelSerializer): | |
password = serializers.CharField(write_only=True) | |
class Meta: | |
model = User | |
fields = ('first_name', 'last_name', 'email', 'password', 'mfa_hash') | |
def create(self, validated_data): | |
user = User.objects.create(**validated_data) | |
user.set_password(validated_data['password']) | |
user.mfa_hash = pyotp.random_base32() | |
user.save() | |
return user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment