import sys
from pgweb.util.misc import get_client_ip
+from pgweb.core.models import UserProfile
import logging
log = logging.getLogger(__name__)
return HttpResponseRedirect('/account/signup/oauth/')
log.info("Oauth signin of {0} using {1} from {2}.".format(email, provider, get_client_ip(request)))
+ if UserProfile.objects.filter(user=user).exists():
+ if UserProfile.objects.get(user=user).block_oauth:
+ log.warning("Account {0} ({1}) is blocked from OAuth login".format(user.username, email))
+ return HttpResponse("OAuth login not allowed to this account.")
user.backend = settings.AUTHENTICATION_BACKENDS[0]
django_login(request, user)
--- /dev/null
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.17 on 2019-02-10 13:21
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('core', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='userprofile',
+ name='block_oauth',
+ field=models.BooleanField(default=False, help_text='Disallow login to this account using OAuth providers like Google or Microsoft.', verbose_name='Block OAuth login'),
+ ),
+ ]
user = models.OneToOneField(User, null=False, blank=False, primary_key=True)
sshkey = models.TextField(null=False, blank=True, verbose_name="SSH key", help_text="Paste one or more public keys in OpenSSH format, one per line.", validators=[validate_sshkey, ])
lastmodified = models.DateTimeField(null=False, blank=False, auto_now=True)
+ block_oauth = models.BooleanField(null=False, blank=False, default=False,
+ verbose_name="Block OAuth login",
+ help_text="Disallow login to this account using OAuth providers like Google or Microsoft.")
# Notifications sent for any moderated content.