Skip to content

Commit

Permalink
Merge b7c094e into 98f2842
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKimpatrick committed Sep 13, 2018
2 parents 98f2842 + b7c094e commit 47051d4
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 6 deletions.
4 changes: 2 additions & 2 deletions authors/apps/authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.1 on 2018-09-10 12:16
# Generated by Django 2.1 on 2018-09-12 18:34

import authors.apps.social_auth.utils
from django.db import migrations, models
Expand All @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(db_index=True, max_length=255, unique=True)),
('email', models.EmailField(db_index=True, max_length=254, unique=True)),
('is_active', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('is_email_verified', models.BooleanField(default=False)),
('is_staff', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
Expand Down
1 change: 0 additions & 1 deletion authors/apps/authentication/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def render(self, data, media_type=None, renderer_context=None):
# rendering errors.
return super(UserJSONRenderer, self).render(data)


# Finally, we can render our data under the "user" namespace.
return json.dumps({
'user': data
Expand Down
1 change: 0 additions & 1 deletion authors/apps/authentication/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
from .models import User

import os

from django.shortcuts import get_object_or_404

Expand Down
5 changes: 5 additions & 0 deletions authors/apps/authentication/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
path('user/', UserRetrieveUpdateAPIView.as_view()),
path('users/', RegistrationAPIView.as_view()),
path('users/login/', LoginAPIView.as_view()),

path('users/reset/password', InvokePasswordResetAPIView.as_view()),
path('user/reset-password/<token>', UserRetrieveUpdateAPIView.as_view()),
path('users/activate_account/<uid>/<token>/',
ActivateAccountView.as_view(), name='activate_account'),

path('users/reset/password/', InvokePasswordResetAPIView.as_view()),
path('user/reset-password/<token>/', UserRetrieveUpdateAPIView.as_view())

]
4 changes: 2 additions & 2 deletions authors/apps/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def retrieve(self, request, *args, **kwargs):

return Response(serializer.data, status=status.HTTP_200_OK)

def update(self, request, *args, **kwargs):
def update(self, request, pk=None, **kwargs):
serializer_data = request.data.get('user', {})

# Here is that serialize, validate, save pattern we talked about
Expand Down Expand Up @@ -118,7 +118,7 @@ def post(self, request):
serializer.is_valid(raise_exception=True)

# call send email function
send_password_reset_email(user['email'], serializer.data['email'], current_site)
send_password_reset_email(user['email'], serializer.data['email'], request.get_host())

return Response({"message": "Check your email for a link"}, status=status.HTTP_200_OK)

Expand Down
3 changes: 3 additions & 0 deletions authors/apps/profiles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


default_app_config = 'authors.apps.profiles.apps.MyAppConfig'
9 changes: 9 additions & 0 deletions authors/apps/profiles/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.apps import AppConfig


class MyAppConfig(AppConfig):
name = 'authors.apps.profiles'

def ready(self):
import authors.apps.profiles.signals

6 changes: 6 additions & 0 deletions authors/apps/profiles/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework.exceptions import APIException


class UserProfileDoesNotExist(APIException):
status_code = 400
default_detail = "The requested profile does not exist"
32 changes: 32 additions & 0 deletions authors/apps/profiles/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 2.1 on 2018-09-12 18:34

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bio', models.TextField(blank=True, null=True)),
('avatar', models.URLField(blank=True, null=True)),
('first_name', models.CharField(blank=True, max_length=50, null=True)),
('last_name', models.CharField(blank=True, max_length=50, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('birth_date', models.DateField(blank=True, null=True)),
('location', models.CharField(blank=True, max_length=100, null=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
23 changes: 23 additions & 0 deletions authors/apps/profiles/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.db import models
from authors.apps.authentication.models import User


class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.TextField(blank=True, null=True)
avatar = models.URLField(blank=True, null=True)
first_name = models.CharField(max_length=50, blank=True, null=True)
last_name = models.CharField(max_length=50, blank=True, null=True)

# A timestamp representing when this object was created.
created_at = models.DateTimeField(auto_now_add=True)
birth_date = models.DateField(null=True, blank=True)
location = models.CharField(max_length=100, null=True, blank=True)

# A timestamp representing when this object was last updated.
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return self.first_name


21 changes: 21 additions & 0 deletions authors/apps/profiles/renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import json
from datetime import datetime

from django.conf.global_settings import DATETIME_FORMAT
from rest_framework.renderers import JSONRenderer


class AHJSONRenderer(JSONRenderer):
charset = 'utf-8'
object_label = 'object'

def render(self, data, media_type=None, renderer_context=None):

return json.dumps({
self.object_label: data
})


class ProfileJSONRenderer(AHJSONRenderer):
object_label = 'profile'
19 changes: 19 additions & 0 deletions authors/apps/profiles/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from rest_framework import serializers

from authors.apps.profiles.models import UserProfile


class RetrieveUserProfileSerializer(serializers.ModelSerializer):

username = serializers.CharField(source='user.username')
bio = serializers.CharField(allow_blank=True, required=False)
first_name = serializers.CharField(allow_blank=True, required=False)
last_name = serializers.CharField(allow_blank=True, required=False)
location = serializers.CharField(allow_blank=True, required='False')

class Meta:
model = UserProfile
fields = ('username', 'bio', 'first_name', 'last_name', 'location')
read_only_fields = ('username',)
extra_kwargs = {'token': {'read_only': True}}

12 changes: 12 additions & 0 deletions authors/apps/profiles/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.dispatch import receiver
from django.db.models.signals import post_save

from .models import *


@receiver(post_save, sender=User)
def build_profile_on_user_creation(sender, instance, created, **kwargs):
if created:
""" Check if user is created """
profile = UserProfile(user=instance)
profile.save()
Empty file.
31 changes: 31 additions & 0 deletions authors/apps/profiles/tests/base_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
This module contains data used by other test modules
"""


class BaseTest():
"""
This class contains data required for testing by test classes.
"""

def __init__(self):
self.user_name = "iroq"
self.user_email = "iroq@sims.andela"
self.password = "teamiroq1"
self.superuser_name = "iroquois"
self.superuser_email = "iroq@sims1.andela"
self.superuserpassword = "teamiroq"
self.user_data = {"user": {"username": self.user_name, "email": self.user_email,
"password": self.password,
}
}
self.login_data = {"user": {"email": self.user_email, "password": self.password,
}
}

self.second_user = {"user": {"username": "second_user", "email": "second@exists.com",
"password": self.password,
}
}


Loading

0 comments on commit 47051d4

Please sign in to comment.