Skip to content

Commit

Permalink
make sso login superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
4-dash committed Jan 17, 2025
1 parent da2e704 commit ec6af02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/feedback/views/intern/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from feedback.models import Veranstaltung

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

@user_passes_test(lambda u: u.is_superuser)
@require_http_methods(('HEAD', 'GET', 'POST'))
Expand Down Expand Up @@ -54,6 +55,17 @@ def rechte_zuruecknehmen(request):
return HttpResponseRedirect(reverse('feedback:intern-index'))


class CustomSocialAccountAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
super().pre_social_login(request, sociallogin)
user = sociallogin.user

if user.id:
user.is_superuser = True
user.is_staff = True
user.save()


def auth_user(request) :
if request.method == "POST" :
username = request.POST.get("username")
Expand Down
4 changes: 4 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/'

SOCIALACCOUNT_ADAPTER = 'feedback.views.intern.auth.CustomSocialAccountAdapter'

SOCIALACCOUNT_PROVIDERS = {
"openid_connect": {
"APPS": [
Expand Down

0 comments on commit ec6af02

Please sign in to comment.