-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add settings and urls * Login template * Update requirements.txt * Add setting fo socialaccount * Add pre_social_login signal receiver * Fix connect user socialaccount * Update base settings * Update settings * Management fo role and backend of user logged by socialaccount * Update requirements.txt * Typo * Add ACCOUNT_EMAIL_VERIFICATION = 'none' * Change login backend order --------- Co-authored-by: wlorenzetti <[email protected]> (cherry picked from commit d62c141) Co-authored-by: Walter Lorenzetti <[email protected]>
- Loading branch information
1 parent
37f1226
commit e729dbf
Showing
10 changed files
with
159 additions
and
48 deletions.
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
g3w-admin/usersmanage/templates/socialaccount/provider_list.html
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,22 @@ | ||
{% load allauth socialaccount %} | ||
{% load i18n %} | ||
{% get_providers as socialaccount_providers %} | ||
{% if socialaccount_providers %} | ||
<div class="col-xs-12" style="text-align: center;"> | ||
<p>- {% trans 'OR' %} -</p> | ||
</div> | ||
{% for provider in socialaccount_providers %} | ||
{% if provider.id == "openid" %} | ||
{% for brand in provider.get_brands %} | ||
{% provider_login_url provider openid=brand.openid_url process=process as href %} | ||
{% element provider name=brand.name provider_id=provider.id href=href %} | ||
{% endelement %} | ||
{% endfor %} | ||
{% endif %} | ||
{% provider_login_url provider process=process scope=scope auth_params=auth_params as href %} | ||
<div class="col-xs-12"> | ||
<a class="btn btn-default btn-block btn-flat" href="{{ href }}">{{ provider.name }}</a> | ||
</div> | ||
{% endfor %} | ||
<div class="col-xs-12" style="margin-bottom: 20px;"></div> | ||
{% endif %} |
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,58 @@ | ||
# coding=utf-8 | ||
"""" | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the Mozilla Public License 2.0. | ||
""" | ||
|
||
__author__ = '[email protected]' | ||
__date__ = '2024-12-17' | ||
__copyright__ = 'Copyright 2015 - 2024, Gis3w' | ||
__license__ = 'MPL 2.0' | ||
|
||
from django.conf import settings | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter | ||
from allauth.account.models import EmailAddress | ||
from usersmanage.models import User, Group as AuthGroup, Userbackend, USER_BACKEND_DEFAULT | ||
from usersmanage.configs import G3W_EDITOR1, G3W_EDITOR2, G3W_VIEWER1 | ||
|
||
class G3WSocialAccountAdapter(DefaultSocialAccountAdapter): | ||
|
||
def _set_user_role_backend(self, user): | ||
""" | ||
Set the role and the backend for the user login by social | ||
""" | ||
|
||
# Role to se from settings | ||
role = settings.SOCIALACCOUNT_USER_ROLE \ | ||
if settings.SOCIALACCOUNT_USER_ROLE in (G3W_EDITOR1, G3W_EDITOR2, G3W_VIEWER1) else G3W_VIEWER1 | ||
|
||
AuthGroup.objects.get(name=role).user_set.add(user) | ||
|
||
# Backend | ||
if not hasattr(user, 'userbackend'): | ||
Userbackend(user=user, backend=USER_BACKEND_DEFAULT).save() | ||
|
||
def pre_social_login(self, request, sociallogin): | ||
|
||
# Social account already exists, so this is just a login | ||
if sociallogin.is_existing: | ||
return | ||
|
||
# some social logins don't have an email address | ||
if not sociallogin.email_addresses: | ||
return | ||
try: | ||
existing_user = User.objects.get(email=sociallogin.email_addresses[0].email) | ||
self._set_user_role_backend(existing_user) | ||
except ObjectDoesNotExist: | ||
return | ||
|
||
# if it does, connect this new social login to the existing user | ||
sociallogin.connect(request, existing_user) | ||
|
||
def save_user(self, request, sociallogin, form=None): | ||
user = super(G3WSocialAccountAdapter, self).save_user(request, sociallogin, form=form) | ||
self._set_user_role_backend(user) | ||
return 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