-
Notifications
You must be signed in to change notification settings - Fork 39
#M00. As a User, I would like to register an account. - Auxfuse #83
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
Merged
stefdworschak
merged 33 commits into
Code-Institute-Community:master
from
auxfuse:user-auth-auxfuse
Oct 21, 2020
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
0788830
Initial branch commit
auxfuse 34fc3fd
Test commit
auxfuse 7c504ab
.idea/ added to gitignore
auxfuse d93ccf9
Removed incorrectly pushed Pycharm default .idea folder from repo
auxfuse 365720f
Setup default allauth via settings.py additional allauth settings and…
auxfuse db72f44
Copied allauth account/socialaccount/base.html template files from Li…
auxfuse d3d6df3
Default signup Allauth form extended with required fields as per user…
auxfuse cccd554
Added ommitted spacing around `=` operator in accounts/forms.py file
auxfuse 65d590b
User signup is_active permission set to False using user_signed_up si…
auxfuse db15842
Fixed merge conflicts
auxfuse 9061b39
Fixed merge conflicts, removed conflict markers and updated gitignore
auxfuse 87cbfb9
Checked form data using request object in forms.py with if..elif..els…
auxfuse 640655d
Set autofocus from username to email field in forms.py for signup tem…
auxfuse 0d7e90c
Up-to-date migrations pushed through
auxfuse 7fb14e9
Updated models/forms/admin.py files of accounts app to suit Profile m…
auxfuse 15f238d
Upstream Master pull to update file directory
auxfuse 15a20ce
Manually added migrations files ommited from latest git pull upstream…
auxfuse d375e11
accounts app files updated with comments throughout, dependant lists …
auxfuse 1598733
Re-added 0001-inital.py hackathon migration file to solve Operational…
auxfuse 2ac3a44
Merge branch 'master' of https://github.com/Code-Institute-Community/…
auxfuse f7db244
Refactored accounts .py files to change lists to constants, set user …
auxfuse 0d8968d
Updated accounts/models.py file with CharField null value to be '' as…
auxfuse 8ebdf18
Removed unnecessary comment from accounts/admin.py file and added add…
auxfuse ada3d30
Default Django allauth authentication templates formatted with IDE fo…
auxfuse ce4cc3e
Formatted allauth socialAccount templates with IDE formatter includin…
auxfuse de75a0c
Formatted Django allauth base.html template with default IDE formatter
auxfuse af7de06
Django allauth email & messages .txt template files formatted manuall…
auxfuse 1fa6f5c
Django allauth socialaccounts messages .txt file templates manually f…
auxfuse 929ec6b
Docstrings added and single line comments removed where necessary to …
auxfuse 62cc59b
.gitignore file updated to include Pycharm default folder of .idea/ a…
auxfuse 2b1ff12
Refactored models.py Profile fields with default='' instead of Null=''
auxfuse f4d3e52
Migrations made to suit new Profile models.py changes in field attrib…
auxfuse 9366513
Added explicit except catch error in the form of KeyError in the Prof…
auxfuse 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,4 +9,6 @@ env.py | |
| *.sqlite3 | ||
| settings.json | ||
| .gitpod.yml | ||
| setup.* | ||
| setup.* | ||
| venv/ | ||
| .idea/ | ||
Empty file.
This file contains hidden or 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 django.contrib import admin | ||
|
|
||
| from .models import Profile | ||
|
|
||
|
|
||
| class ProfileAdmin(admin.ModelAdmin): | ||
| """ | ||
| Profile Model Admin Panel setup. | ||
| Returning and displaying the three custom fields from the extended | ||
| allauth signup form. | ||
| """ | ||
| fields = ( | ||
| 'slack_display_name', | ||
| 'user_type', | ||
| 'current_lms_module', | ||
| ) | ||
|
|
||
|
|
||
| admin.site.register(Profile, ProfileAdmin) | ||
auxfuse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
This file contains hidden or 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 AccountsConfig(AppConfig): | ||
| name = 'accounts' |
This file contains hidden or 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 @@ | ||
| from django import forms | ||
| from allauth.account.forms import SignupForm | ||
|
|
||
| from .lists import USER_TYPES_CHOICES, LMS_MODULES_CHOICES | ||
|
|
||
|
|
||
| class ExtendedSignupForm(SignupForm): | ||
| """ | ||
| Extending default Django allauth Signup Form to include fields to capture: | ||
| - first name/last name/slack display name/user type/current lms module | ||
| """ | ||
| first_name = forms.CharField(max_length=20) | ||
| last_name = forms.CharField(max_length=20) | ||
| slack_display_name = forms.CharField(max_length=25) | ||
| user_type = forms.ChoiceField( | ||
| choices=USER_TYPES_CHOICES | ||
| ) | ||
| current_lms_module = forms.ChoiceField( | ||
| choices=LMS_MODULES_CHOICES | ||
| ) | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
auxfuse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Setting unique attribute of the class instance and calling the parent | ||
| class. | ||
| Resetting the form autofocus to 'email' as the first displayed field. | ||
| """ | ||
| super().__init__(*args, **kwargs) | ||
| self.fields['email'].widget.attrs['autofocus'] = True | ||
|
|
||
| def custom_signup(self, request, user): | ||
auxfuse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Custom logic to ensure clean data via the form response. | ||
| """ | ||
| user.first_name = self.cleaned_data["first_name"] | ||
| user.last_name = self.cleaned_data["last_name"] | ||
| user.slack_display_name = self.cleaned_data["slack_display_name"] | ||
| user.user_type = self.cleaned_data["user_type"] | ||
| user.current_lms_module = self.cleaned_data["current_lms_module"] | ||
|
|
||
This file contains hidden or 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,28 @@ | ||
| # User types list passed into dropdown of same name for user selection used | ||
| # in models.py & forms.py | ||
| USER_TYPES_CHOICES = [ | ||
| ('', 'Select Post Category'), | ||
| ('participant', 'Participant'), | ||
| ('staff', 'Staff'), | ||
| ('admin', 'Admin'), | ||
| ] | ||
|
|
||
| # LMS Modules list passed into dropdown of same name for user selection used | ||
| # in modules.py & forms.py | ||
| LMS_MODULES_CHOICES = [ | ||
| ('', 'Select Learning Stage'), | ||
| ('programme_preliminaries', 'Programme Preliminaries'), | ||
| ('programming_paradigms', 'Programming Paradigms'), | ||
| ('html_fundamentals', 'HTML Fundamentals'), | ||
| ('css_fundamentals', 'CSS Fundamentals'), | ||
| ('user_centric_frontend_development', 'User Centric Frontend Development'), | ||
| ('javascript_fundamentals', 'Javascript Fundamentals'), | ||
| ('interactive_frontend_development', 'Interactive Frontend Development'), | ||
| ('python_fundamentals', 'Python Fundamentals'), | ||
| ('practical_python', 'Practical Python'), | ||
| ('data_centric_development', 'Data Centric Development'), | ||
| ('full_stack_frameworks with django', 'Full Stack Frameworks with Django'), | ||
| ('alumni', 'Alumni'), | ||
| ('staff', 'Staff'), | ||
| ] | ||
|
|
This file contains hidden or 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,27 @@ | ||
| # Generated by Django 3.1.1 on 2020-10-19 10:01 | ||
|
|
||
| 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='Profile', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('slack_display_name', models.CharField(max_length=80, null=True)), | ||
| ('user_type', models.CharField(choices=[('', 'Select Post Category'), ('participant', 'Participant'), ('staff', 'Staff'), ('admin', 'Admin')], max_length=20, null=True)), | ||
| ('current_lms_module', models.CharField(choices=[('', 'Select Learning Stage'), ('programme preliminaries', 'Programme Preliminaries'), ('programming paradigms', 'Programming Paradigms'), ('html fundamentals', 'HTML Fundamentals'), ('css fundamentals', 'CSS Fundamentals'), ('user centric frontend development', 'User Centric Frontend Development'), ('javascript fundamentals', 'Javascript Fundamentals'), ('interactive frontend development', 'Interactive Frontend Development'), ('python fundamentals', 'Python Fundamentals'), ('practical python', 'Practical Python'), ('data centric development', 'Data Centric Development'), ('full stack frameworks with django', 'Full Stack Frameworks with Django'), ('alumni', 'Alumni'), ('staff', 'Staff')], max_length=35, null=True)), | ||
| ('user', models.OneToOneField(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)), | ||
| ], | ||
| ), | ||
| ] |
This file contains hidden or 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,28 @@ | ||
| # Generated by Django 3.1.1 on 2020-10-20 19:42 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('accounts', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='profile', | ||
| name='current_lms_module', | ||
| field=models.CharField(choices=[('', 'Select Learning Stage'), ('programme_preliminaries', 'Programme Preliminaries'), ('programming_paradigms', 'Programming Paradigms'), ('html_fundamentals', 'HTML Fundamentals'), ('css_fundamentals', 'CSS Fundamentals'), ('user_centric_frontend_development', 'User Centric Frontend Development'), ('javascript_fundamentals', 'Javascript Fundamentals'), ('interactive_frontend_development', 'Interactive Frontend Development'), ('python_fundamentals', 'Python Fundamentals'), ('practical_python', 'Practical Python'), ('data_centric_development', 'Data Centric Development'), ('full_stack_frameworks with django', 'Full Stack Frameworks with Django'), ('alumni', 'Alumni'), ('staff', 'Staff')], default='', max_length=35), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='profile', | ||
| name='slack_display_name', | ||
| field=models.CharField(default='', max_length=80), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='profile', | ||
| name='user_type', | ||
| field=models.CharField(choices=[('', 'Select Post Category'), ('participant', 'Participant'), ('staff', 'Staff'), ('admin', 'Admin')], default='', max_length=20), | ||
| ), | ||
| ] |
Empty file.
This file contains hidden or 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,97 @@ | ||
| from django.dispatch import receiver | ||
| from django.contrib.auth.models import User | ||
| from django.db import models | ||
| from django.conf import settings | ||
| from django.db.models.signals import post_delete | ||
| from allauth.account.signals import user_signed_up | ||
|
|
||
| from .lists import USER_TYPES_CHOICES, LMS_MODULES_CHOICES | ||
|
|
||
|
|
||
| class Profile(models.Model): | ||
| """ | ||
| Define Profile Model with OneToOne relationship to AUTH_USER_MODEL and | ||
| custom fields to suit Signup Form Extending in forms.py replicating same | ||
| in DB. | ||
| Using "related_name" in the OneToOne relationship between the two models | ||
| specifies the reverse relationship to the User Model, allowing us to | ||
| target the custom fields for injection into the profile.html | ||
| template via `{{ user.profile.<<field_name>> }}`. | ||
| """ | ||
| user = models.OneToOneField( | ||
| settings.AUTH_USER_MODEL, default=1, | ||
| related_name='profile', | ||
| on_delete=models.CASCADE | ||
| ) | ||
| slack_display_name = models.CharField( | ||
| max_length=80, | ||
| blank=False, | ||
auxfuse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| default='' | ||
| ) | ||
| user_type = models.CharField( | ||
| max_length=20, | ||
| blank=False, | ||
| default='', | ||
| choices=USER_TYPES_CHOICES | ||
| ) | ||
| current_lms_module = models.CharField( | ||
| max_length=35, | ||
| blank=False, | ||
| default='', | ||
| choices=LMS_MODULES_CHOICES | ||
| ) | ||
|
|
||
| def save(self, *args, **kwargs): | ||
auxfuse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # when signup takes place | ||
| try: | ||
| self.slack_display_name = self.user.slack_display_name | ||
| self.user_type = self.user.user_type | ||
| self.current_lms_module = self.user.current_lms_module | ||
| # when saving via admin panel | ||
| except KeyError: | ||
| self.slack_display_name = self.user.profile.slack_display_name | ||
| self.user_type = self.user.profile.user_type | ||
| self.current_lms_module = self.user.profile.current_lms_module | ||
|
|
||
| super(Profile, self).save(*args, **kwargs) | ||
|
|
||
| def __str__(self): | ||
| """ | ||
| Return Class object to string via the user email value | ||
| """ | ||
| return self.user.email | ||
|
|
||
|
|
||
| @receiver(user_signed_up) | ||
| def user_signed_up(request, user, **kwargs): | ||
| """ | ||
| Capture server request object in dict from QueryDict, to access form values. | ||
|
|
||
| Iterate over user_type field value to check for type and set permissions | ||
| based on user story and save user to User and Profile Models. | ||
| """ | ||
| form = dict(request.POST) | ||
|
|
||
| if form['user_type'][0] == 'participant': | ||
| user.is_active = True | ||
| elif form['user_type'][0] == 'staff': | ||
| user.is_active = False | ||
| user.is_staff = True | ||
| else: | ||
| user.is_active = False | ||
| user.is_staff = True | ||
| user.is_superuser = True | ||
| user.save() | ||
|
|
||
| # Save linked instance of user object to profile model | ||
| Profile.objects.create(user=user) | ||
|
|
||
|
|
||
| @receiver(post_delete, sender=Profile) | ||
| def post_delete_user(sender, instance, *args, **kwargs): | ||
| """ | ||
| admin - delete user at same time as profile deletion | ||
| """ | ||
| if instance: | ||
| instance.user.delete() | ||
|
|
||
This file contains hidden or 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 @@ | ||
| from django.test import TestCase |
This file contains hidden or 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 @@ | ||
| from django.shortcuts import render |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -73,4 +73,4 @@ class Migration(migrations.Migration): | |
| name='created', | ||
| field=models.DateTimeField(auto_now_add=True), | ||
| ), | ||
| ] | ||
| ] | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -15,4 +15,4 @@ class Migration(migrations.Migration): | |
| name='highest_score', | ||
| field=models.IntegerField(default=10), | ||
| ), | ||
| ] | ||
| ] | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,4 +20,4 @@ class Migration(migrations.Migration): | |
| name='min_score', | ||
| field=models.IntegerField(default=1), | ||
| ), | ||
| ] | ||
| ] | ||
This file contains hidden or 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
This file contains hidden or 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,10 @@ | ||
| {% extends "account/base.html" %} | ||
|
|
||
| {% load i18n %} | ||
|
|
||
| {% block head_title %}{% trans "Account Inactive" %}{% endblock %} | ||
|
|
||
| {% block content %} | ||
| <h1>{% trans "Account Inactive" %}</h1> | ||
| <p>{% trans "This account is inactive." %}</p> | ||
| {% endblock %} |
This file contains hidden or 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 @@ | ||
| {% extends "base.html" %} |
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.
Uh oh!
There was an error while loading. Please reload this page.