Passwords, TODO++
This commit is contained in:
1 parent
9bbfea8971
commit
26bce8af7f
6 files changed
+55
-6
No files matched your search
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dpdapi', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='alias',
|
||||
options={'verbose_name_plural': 'aliases'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='domain',
|
||||
name='name',
|
||||
field=models.CharField(unique=True, max_length=1000),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='email',
|
||||
field=models.EmailField(unique=True, max_length=75),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
||||
+2
-2
@@ -24,14 +24,14 @@ class Alias(BaseModel):
|
||||
|
||||
|
||||
class Domain(BaseModel):
|
||||
name = models.CharField(max_length=1000)
|
||||
name = models.CharField(max_length=1000, unique=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
email = models.EmailField()
|
||||
email = models.EmailField(unique=True)
|
||||
password = models.CharField(max_length=109)
|
||||
domain = models.ForeignKey('dpdapi.Domain')
|
||||
|
||||
|
||||
+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