Passwords, TODO++
This commit is contained in:
1 parent
9bbfea8971
commit
26bce8af7f
6 files changed
+55
-6
No files matched your search
+15
-2
@@ -1,5 +1,5 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from passlib.hash import sha512_crypt
|
||||
from .models import Alias, Domain, User
|
||||
|
||||
|
||||
@@ -21,4 +21,17 @@ class DomainSerializer(serializers.ModelSerializer):
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
model = User
|
||||
extra_kwargs = {'password': {'write_only': True}}
|
||||
|
||||
def _hash_password(self, raw_password):
|
||||
return sha512_crypt.encrypt(raw_password)
|
||||
|
||||
def create(self, validated_data):
|
||||
user = User(
|
||||
email=validated_data['email'],
|
||||
domain=validated_data['domain'],
|
||||
password=self._hash_password(validated_data['password'])
|
||||
)
|
||||
user.save()
|
||||
return user
|
||||
Reference in new issue
Block a user