Login#
This app handles the user authentication using django allauth and implements a user profile that provide an overview on tables and helps to manage the datasets draft or published state. Additionally the profile pages include the permission groups to manage data table resource access permissions as group with other users. The last feature is the user profile, including a view showing the api token with functionality to reset it as well as a Form to provide additional user data like adding a user image.
Setup#
First make sure to install django allauth package and install it into the existing project:
-
install latest requirements.txt in the python environment
pip install -r requirements.txt
-
run python migrations to setup the new django allauth models (tables)
python manage.py migrate
- check your iptables setting on the server to enable server to server connection using the service static ip address. Don`t forget to restart the iptables service to apply the updates.
Now edit your securitysettings.py and update it with the content form the securitysettings.py.default template file to setup the social provider used for 3rd Party Login flow. We use openIDConnect that is implemented by django allauth:
Note
Filling out the values in the dictionary depends on your Provider. They should provide documentation or provide you with the relevant credentials. In some cases the provider_id must be in line with the specification of the provider in others you can choose your own name here. The client_id & secret should also be provided as well as the server_url.
SOCIALACCOUNT_PROVIDERS = {
"openid_connect": {
# For each OAuth based provider, either add a ``SocialApp``
# (``socialaccount`` app) containing the required client
# credentials, or list them here:
"APPS": [{
"provider_id": "",
"name": "",
"client_id": "",
"secret": "",
"VERIFIED_EMAIL": True,
"EMAIL_AUTHENTICATION": True,
"settings": {"server_url": ""},
}]
}
}
App Components#
The components of each app implement the django app structure and implement a MVVM pattern for web applications. This includes the files model.py, views.py, urls.py, Then there are migrations that specify the django table structure and is also a core django feature. The templates include all HTML page payouts including django template syntax to render pages with dynamic server data and JavaScript. Additionally there might be other folders and python modules available.w
Views#
EditUserView ::: login.views
Forms#
3rd party Signup ::: login.forms.UserSocialSignupForm
Default Signup ::: login.forms.CreateUserForm
Edit existing user data ::: login.forms.EditUserForm
Adapters#
SPDX-FileCopyrightText: 2024 Jonas Huber https://github.com/jh-RLI © Reiner Lemoine Institut SPDX-License-Identifier: AGPL-3.0-or-later
AccountAdapter
#
Bases: DefaultAccountAdapter
Handles default logins
Source code in login/adapters.py
21 22 23 24 25 26 27 | |
SocialAccountAdapter
#
Bases: DefaultSocialAccountAdapter
Handles logins via 3rd party organizations like ORCID.
Source code in login/adapters.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
populate_user(request, sociallogin, data)
#
Populates user information from social provider info.
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?#creating-and-populating-user-instances # noqa
Source code in login/adapters.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
Models#
The user manager that handles oeplatform users and their system role ::: login.models.OEPUserManager
The user model of a oeplatform user ::: login.models.myuser