Passwords, TODO++

This commit is contained in:
nikolark committed 2015-01-07 03:11:35 +01:00
1 parent 9bbfea8971
commit 26bce8af7f
6 files changed
+55 -6

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
# TODO
- Fabfile with deploy task
- Alias should only allow unique (source,destination) tuples
# TODO later
- Create domain dir for dovecot?
@@ -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
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -4,8 +4,8 @@ from django.views.generic import RedirectView
urlpatterns = patterns(
'',
url(r'^api/', include('dpdapi.urls')),
url(r'^$', RedirectView.as_view(pattern_name='api-root')),
url(r'^api/', include('dpdapi.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
+1 -1
View File
@@ -2,4 +2,4 @@ Django>=1.7,<1.8
django-extensions==1.4.9
django-filter==0.9.1
djangorestframework>=3.0,<3.1
passlib==1.6.2