Skip to content

#M00. As a User, I would like to register an account. - Auxfuse#83

Merged
stefdworschak merged 33 commits intoCode-Institute-Community:masterfrom
auxfuse:user-auth-auxfuse
Oct 21, 2020
Merged

#M00. As a User, I would like to register an account. - Auxfuse#83
stefdworschak merged 33 commits intoCode-Institute-Community:masterfrom
auxfuse:user-auth-auxfuse

Conversation

@auxfuse
Copy link
Contributor

@auxfuse auxfuse commented Oct 19, 2020

Description:

This PR adds the ability for any type of user (participant, staff, admin) to use an extended Django allauth Signup Form to register onto the site.

Extending allauth Signup Form

Fields added to Signup Form:
  • First Name (CharField)
  • Last Name (CharField)
  • Slack Display Name (CharField)
  • Current LMS Module (ChoiceField: choices pulling from lms_modules imported from lists.py file)
  • User Type (ChoiceField: choices pulling from user_types imported from lists.py file)

Field autofocus reset added to set email as the default autofocus field on page load over username with custom logic to validate additional fields to the form listed above.

Profile Model Creation

Profile model created to host additional custom fields to be stored in the DB to match the additional fields added to the SignupForm, with a One-to-One relationship to the AUTH_USER_MODEL. Profile Model includes save function to save via form/via the admin panel.

user_signed_up signal from allauth used to listen for user signup and then allow check on form field user_type and the value selected by the user.

User Type Logic:
  • If User selects 'participant' user type, then is_active permission flag in User object set to True and normal flow ensues.
  • If User selects 'staff' user type, then is_active permission flag in User object set to False and is_staff permission set to True, needing direct intervention from Site Administrator to Approve User before login onto the site can occur.
  • If User selects 'staff' user type, then is_active permission flag in User object set to False and is_staff / is_superuser permissions set to True, needing direct intervention from Site Administrator to Approve User before login onto the site/admin panel can occur.

Additonal functionality includes backwards deletion of a User from Profile >> User Model using post_delete signal and using the Profile model as the default sender.

Testing:

All testing was done manually throughout per user_type.

Screenshots:

See below gif of a user signup, selecting Staff as their account type, and a demonstration of checking the user is_active permission boolean in the admin panel to show the approval flow has worked.

signup

Additional Information:

When attempting to return the Profile Model data to the Profile.html template, the developer will need to decalre the expression as {{ user.profile.<<field_name>> }} where <<field_name>> could equal user_type for example. See additional screenshot.

django_template_use

Sean Murphy helped me immensly in understanding the required steps to access the form values for the Approval flow to work. Also assisted in providing the code for the Profile Model and Admin definition for same, including sitting in on calls and continuing to work on the project in tandem to my learning whilst implementing multiple experimental solutions, and even outside of my development hours. Man's a legend!

…b/allauth package into root templates directory
…moved to lists.py and imported where necessary to reduce duplicate code fragments
Copy link
Member

@stefdworschak stefdworschak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@auxfuse really good pull request here and I do like the approach with the profile!

Just have a look at the comments below and let me know if you have any questions.

…registration and login to only reference email instead of username, and separated imports into 3rd party and local blocks
… per Django documentation and reflected email login use over username in str object
…itional trailing blank line to see if Github picks them up
@Eventyret
Copy link
Contributor

Nice thanks for adding docstrings @auxfuse LGTM 🥇

Copy link
Member

@stefdworschak stefdworschak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I don't want to hold this up any longer, but could you please raise a small follow-up PR for this? The follow-up PR should 1) add a line to log the exception you are catching in your Profile.save() and 2) add the links the auth pages (e.g. signup, login, etc) to the navbar menu. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted Accepted PR during Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#M00. As a User, I would like to register an account.

3 participants

Comments