I implemented django oauth toolkit to my project so I can handle to login a user and get the access token, but I have no idea how to register a user and then create a new access token. Can anybody help me creating the registration view?
client type: confidential
grant type: password
serializers.py
class UserRegisterSerializer(serializers.ModelSerializer):
confirm_password = serializers.CharField()
class Meta:
model = user_models.User
fields = [
'username',
'first_name',
'last_name',
'email',
'password',
'confirm_password',
]
extra_kwargs = {
'confirm_password': {'read_only': True}
}
def validate(self, data):
try:
user = user_models.User.objects.filter(
username=data.get('username'))
if user.exists():
raise serializers.ValidationError(_('Username already exists'))
except user_models.User.DoesNotExist:
pass
if not data.get('password') or not data.get('confirm_password'):
raise serializers.ValidationError(_('Empty password'))
if data.get('password') != data.get('confirm_password'):
raise serializers.ValidationError(_('Password mismatch'))
return data