diff --git a/stude/accounts/migrations/0001_initial.py b/stude/accounts/migrations/0001_initial.py index 7d6b2c1..afd21e8 100644 --- a/stude/accounts/migrations/0001_initial.py +++ b/stude/accounts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.2 on 2023-06-26 11:43 +# Generated by Django 4.2.2 on 2023-06-26 12:08 import django.contrib.auth.models import django.contrib.auth.validators @@ -31,8 +31,8 @@ class Migration(migrations.Migration): ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), ('is_student', models.BooleanField(default=True)), ('is_banned', models.BooleanField(default=False)), - ('year_level', models.CharField(blank=True, max_length=50, null=True)), - ('semester', models.CharField(blank=True, max_length=50, null=True)), + ('year_level', models.CharField(choices=[('1st', '1st year'), ('2nd', '2nd year'), ('3rd', '3rd year'), ('4th', '4th year'), ('5th', '5th Year'), ('Irreg', 'Irregular')], max_length=50)), + ('semester', models.CharField(choices=[('1st', '1st semester'), ('2nd', '2nd semester')], max_length=50)), ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), ], diff --git a/stude/accounts/migrations/0002_customuser_is_studying_alter_customuser_first_name_and_more.py b/stude/accounts/migrations/0002_customuser_is_studying_alter_customuser_first_name_and_more.py new file mode 100644 index 0000000..1c76ccc --- /dev/null +++ b/stude/accounts/migrations/0002_customuser_is_studying_alter_customuser_first_name_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.2 on 2023-06-26 12:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='customuser', + name='is_studying', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='customuser', + name='first_name', + field=models.CharField(max_length=100), + ), + migrations.AlterField( + model_name='customuser', + name='last_name', + field=models.CharField(max_length=100), + ), + ] diff --git a/stude/accounts/migrations/0003_customuser_avatar.py b/stude/accounts/migrations/0003_customuser_avatar.py new file mode 100644 index 0000000..6ec8b03 --- /dev/null +++ b/stude/accounts/migrations/0003_customuser_avatar.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2023-06-26 12:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0002_customuser_is_studying_alter_customuser_first_name_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='customuser', + name='avatar', + field=models.ImageField(null=True, upload_to='images'), + ), + ] diff --git a/stude/accounts/models.py b/stude/accounts/models.py index 6dc3a0d..5921b2d 100644 --- a/stude/accounts/models.py +++ b/stude/accounts/models.py @@ -3,8 +3,30 @@ from django.db import models class CustomUser(AbstractUser): + YEAR_LEVELS = ( + ('1st', '1st year'), + ('2nd', '2nd year'), + ('3rd', '3rd year'), + ('4th', '4th year'), + ('5th', '5th Year'), + ('Irreg', 'Irregular'), + ) + SEMESTERS = ( + ('1st', '1st semester'), + ('2nd', '2nd semester'), + ) + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + # Email inherited from base user class + # Username inherited from base user class + # Password inherited from base user class + # is_admin inherited from base user class is_student = models.BooleanField(default=True) + is_studying = models.BooleanField(default=False) is_banned = models.BooleanField(default=False) - year_level = models.CharField(max_length=50, null=True, blank=True) - semester = models.CharField(max_length=50, null=True, blank=True) + year_level = models.CharField( + max_length=50, choices=YEAR_LEVELS) + semester = models.CharField( + max_length=50, choices=SEMESTERS) + avatar = models.ImageField(upload_to='images', null=True) pass diff --git a/stude/accounts/serializers.py b/stude/accounts/serializers.py index cbcdb0f..c9a3c0c 100644 --- a/stude/accounts/serializers.py +++ b/stude/accounts/serializers.py @@ -11,5 +11,5 @@ class CustomUserSerializer(BaseUserSerializer): class UserRegistrationSerializer(BaseUserRegistrationSerializer): class Meta(BaseUserRegistrationSerializer.Meta): - fields = ('is_student', - 'is_banned', 'year_level', 'semester') + fields = ('username', 'email', 'password', + 'is_student', 'year_level', 'semester', 'avatar') diff --git a/stude/config/settings.py b/stude/config/settings.py index 1e7f837..11be9fd 100644 --- a/stude/config/settings.py +++ b/stude/config/settings.py @@ -31,11 +31,27 @@ DEBUG = True ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] +# Email credentials +EMAIL_HOST = '' +EMAIL_HOST_USER = '' +EMAIL_HOST_PASSWORD = '' +EMAIL_PORT = '' + +if (DEBUG == True): + EMAIL_HOST = str(os.getenv('DEV_EMAIL_HOST')) + EMAIL_HOST_USER = str(os.getenv('DEV_EMAIL_HOST_USER')) + EMAIL_HOST_PASSWORD = str(os.getenv('DEV_EMAIL_HOST_PASSWORD')) + EMAIL_PORT = str(os.getenv('DEV_EMAIL_PORT')) +else: + EMAIL_HOST = str(os.getenv('PROD_EMAIL_HOST')) + EMAIL_HOST_USER = str(os.getenv('PROD_EMAIL_HOST_USER')) + EMAIL_HOST_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD')) + EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT')) + # Application definition INSTALLED_APPS = [ - 'accounts', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -45,6 +61,7 @@ INSTALLED_APPS = [ 'rest_framework', 'djoser', 'rest_framework.authtoken', + 'accounts', ] @@ -108,19 +125,6 @@ DJOSER = { }, } - -# Email credentials -if (DEBUG == True): - EMAIL_HOST = str(os.getenv('DEV_EMAIL_HOST')) - EMAIL_HOST_USER = str(os.getenv('DEV_EMAIL_HOST_USER')) - EMAIL_HOST_PASSWORD = str(os.getenv('DEV_EMAIL_HOST_PASSWORD')) - EMAIL_PORT = str(os.getenv('DEV_EMAIL_PORT')) -else: - EMAIL_HOST = str(os.getenv('PROD_EMAIL_HOST')) - EMAIL_HOST_USER = str(os.getenv('PROD_EMAIL_HOST_USER')) - EMAIL_HOST_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD')) - EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT')) - # Password validation # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators