Files
postgres-web/pgweb/account/models.py
Magnus Hagander c1fb5de080 Implement synchronization for community authentication
This adds the concept of an apiurl to each site that uses community
authentication, that the main website server can make calls to and send
updates. This URL will receive POSTs from the main website when a user
account that has been used on this site gets updated, and can then
optionally update it's local entries with it (the django plugin sample
is updated to handle this fully).

Updates are only sent for users that have a history of having logged
into the specific site -- this way we avoid braodcasting user
information to sites requiring specific constent that the user hasn't
given, and also decreases the amount of updates that have to be sent.

Updates are queued by the system in a table and using listen/notify a
daemon that's running picks up what needs to be updated and posts it to
the endpoints. If this daemon is not running, obviously nothing gets
sent.

Updates are tracked using triggers in the database which push
information into this queue.
2020-08-11 11:33:46 +02:00

52 lines
2.5 KiB
Python

from django.db import models
from django.contrib.auth.models import User
class CommunityAuthOrg(models.Model):
orgname = models.CharField(max_length=100, null=False, blank=False,
help_text="Name of the organisation")
require_consent = models.BooleanField(null=False, blank=False, default=True)
def __str__(self):
return self.orgname
class CommunityAuthSite(models.Model):
name = models.CharField(max_length=100, null=False, blank=False,
help_text="Note that the value in this field is shown on the login page, so make sure it's user-friendly!")
redirecturl = models.URLField(max_length=200, null=False, blank=False)
apiurl = models.URLField(max_length=200, null=False, blank=True)
cryptkey = models.CharField(max_length=100, null=False, blank=False,
help_text="Use tools/communityauth/generate_cryptkey.py to create a key")
comment = models.TextField(null=False, blank=True)
org = models.ForeignKey(CommunityAuthOrg, null=False, blank=False, on_delete=models.CASCADE)
cooloff_hours = models.IntegerField(null=False, blank=False, default=0,
help_text="Number of hours a user must have existed in the systems before allowed to log in to this site")
push_changes = models.BooleanField(null=False, blank=False, default=False,
help_text="Supports receiving http POSTs with changes to accounts")
push_ssh = models.BooleanField(null=False, blank=False, default=False,
help_text="Wants to receive SSH keys in push changes")
def __str__(self):
return self.name
class CommunityAuthConsent(models.Model):
user = models.ForeignKey(User, null=False, blank=False, on_delete=models.CASCADE)
org = models.ForeignKey(CommunityAuthOrg, null=False, blank=False, on_delete=models.CASCADE)
consentgiven = models.DateTimeField(null=False, blank=False)
class Meta:
unique_together = (('user', 'org'), )
class SecondaryEmail(models.Model):
user = models.ForeignKey(User, null=False, blank=False, on_delete=models.CASCADE)
email = models.EmailField(max_length=75, null=False, blank=False, unique=True)
confirmed = models.BooleanField(null=False, blank=False, default=False)
token = models.CharField(max_length=100, null=False, blank=False)
sentat = models.DateTimeField(null=False, blank=False, auto_now=True)
class Meta:
ordering = ('email', )