forked from AngellusMortis/django_microsoft_auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
48 lines (36 loc) · 1.44 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
class UnicodeSpaceUsernameValidator(UnicodeUsernameValidator):
""" validator to allow spaces in username """
regex = r"^[\w\.@+\- ]+$"
# replace UnicodeUsernameValidator on User model...
User = get_user_model()
for field in User._meta.fields:
if field.name == "username":
for index, validator in enumerate(field.validators):
if isinstance(validator, UnicodeUsernameValidator):
field.validators[index] = UnicodeSpaceUsernameValidator()
class MicrosoftAccount(models.Model):
microsoft_id = models.CharField(_("microsoft account id"), max_length=64)
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
null=True,
related_name="microsoft_account",
)
def __str__(self):
return self.microsoft_id
class XboxLiveAccount(models.Model):
xbox_id = models.CharField(_("xbox user id"), max_length=32, unique=True)
gamertag = models.CharField(_("xbox live gamertag"), max_length=16)
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
null=True,
related_name="xbox_live_account",
)
def __str__(self):
return self.gamertag