Skip to content

Commit

Permalink
google oAuth2 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii committed Feb 1, 2024
1 parent 0849a95 commit 3fba2bb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
44 changes: 44 additions & 0 deletions web/auth_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.2.9 on 2024-02-01 21:30

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='SocialAccount',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uid', models.CharField(blank=True, max_length=40, null=True, unique=True)),
('provider', models.CharField(choices=[('google', 'Google')], max_length=20)),
('connected', models.DateTimeField(auto_now_add=True)),
(
'user',
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name='social_account',
to=settings.AUTH_USER_MODEL,
),
),
],
options={
'indexes': [models.Index(fields=['provider', 'uid'], name='auth_app_so_provide_03d647_idx')],
},
),
migrations.AddConstraint(
model_name='socialaccount',
constraint=models.UniqueConstraint(fields=('user', 'provider'), name='unique_user_provider'),
),
migrations.AddConstraint(
model_name='socialaccount',
constraint=models.UniqueConstraint(fields=('provider', 'uid'), name='unique_uid_provider'),
),
]
Empty file.
21 changes: 21 additions & 0 deletions web/auth_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import models


class SocialAccountChoice(models.TextChoices):
GOOGLE = 'google',


class SocialAccount(models.Model):
user = models.OneToOneField('main.User', on_delete=models.CASCADE, related_name='social_account')
uid = models.CharField(max_length=40, blank=True, null=True, unique=True)
provider = models.CharField(max_length=20, choices=SocialAccountChoice.choices)
connected = models.DateTimeField(auto_now_add=True)

class Meta:
constraints = [
models.UniqueConstraint(fields=('user', 'provider'), name='unique_user_provider'),
models.UniqueConstraint(fields=('provider', 'uid'), name='unique_uid_provider'),
]
indexes = [
models.Index(fields=('provider', 'uid')),
]

0 comments on commit 3fba2bb

Please sign in to comment.