-
-
-
- {% endif %}
- {% if SETTINGS.REGISTRATION_OPEN %}
-
-
- {% endif %}
-
- {% get_providers as socialaccount_providers %}
- {% include "socialaccount/snippets/provider_list.html" with process="login" %}
+
+
+ {% include "socialaccount/provider_list.html" with process="login" %}
+
+
+ {% if SETTINGS.RESET_USER_PASSWORD %}
+
+
+ {% endif %}
+ {% if SETTINGS.REGISTRATION_OPEN %}
+
+ {% endif %}
+
{% include 'include/login_page_version.html' %}
diff --git a/g3w-admin/usersmanage/templates/socialaccount/provider_list.html b/g3w-admin/usersmanage/templates/socialaccount/provider_list.html
new file mode 100644
index 000000000..b3b60307a
--- /dev/null
+++ b/g3w-admin/usersmanage/templates/socialaccount/provider_list.html
@@ -0,0 +1,22 @@
+{% load allauth socialaccount %}
+{% load i18n %}
+{% get_providers as socialaccount_providers %}
+{% if socialaccount_providers %}
+
+ {% 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 %}
+
+ {% endfor %}
+
+{% endif %}
diff --git a/g3w-admin/usersmanage/vendors/allauth/adapter.py b/g3w-admin/usersmanage/vendors/allauth/adapter.py
index fe6774ba5..343d169e6 100644
--- a/g3w-admin/usersmanage/vendors/allauth/adapter.py
+++ b/g3w-admin/usersmanage/vendors/allauth/adapter.py
@@ -10,16 +10,33 @@
__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
+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
+ # Social account already exists, so this is just a login
if sociallogin.is_existing:
return
@@ -27,14 +44,9 @@ def pre_social_login(self, request, sociallogin):
if not sociallogin.email_addresses:
return
try:
- print('pass')
existing_user = User.objects.get(email=sociallogin.email_addresses[0].email)
-
- AuthGroup.objects.get(name=G3W_VIEWER1).user_set.add(existing_user)
- #todo: se non hai ruoli aggiungere il ruolo di defauul, backend!!!!!!!
- # controllare che ci sia almeno un gruppo
+ self._set_user_role_backend(existing_user)
except ObjectDoesNotExist:
- print('non esiste')
return
# if it does, connect this new social login to the existing user
@@ -42,6 +54,5 @@ def pre_social_login(self, request, sociallogin):
def save_user(self, request, sociallogin, form=None):
user = super(G3WSocialAccountAdapter, self).save_user(request, sociallogin, form=form)
- AuthGroup.objects.get(name=G3W_VIEWER1).user_set.add(user)
- #todo: aggiungere ruolo
+ self._set_user_role_backend(user)
return user
\ No newline at end of file