-
Notifications
You must be signed in to change notification settings - Fork 6
Ensure default password for TigaUser #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Generated by Django 3.2.25 on 2025-10-28 14:49 | ||
|
|
||
| from django.db import migrations, models | ||
| import tigaserver_app.models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('tigaserver_app', '0086_auto_20251016_1353'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='tigauser', | ||
| name='password', | ||
| field=models.CharField(default=tigaserver_app.models.get_default_password_hash, max_length=128, verbose_name='password'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| from django.conf import settings | ||
| from django.contrib.auth import get_user_model | ||
| from django.contrib.auth.hashers import make_password | ||
| from django.contrib.auth.models import AbstractBaseUser, AnonymousUser | ||
| from django.contrib.gis.db import models | ||
| from django.contrib.gis.db.models.functions import Distance as DistanceFunction | ||
|
|
@@ -170,14 +171,17 @@ class RankingData(models.Model): | |
| score_v2 = models.IntegerField() | ||
| last_update = models.DateTimeField(help_text="Last time ranking data was updated", null=True, blank=True) | ||
|
|
||
| def get_default_password_hash(): | ||
| return make_password(settings.DEFAULT_TIGAUSER_PASSWORD) | ||
|
|
||
| class TigaUser(UserRolePermissionMixin, AbstractBaseUser, AnonymousUser): | ||
| AVAILABLE_LANGUAGES = [ | ||
| (standarize_language_tag(code), Language.get(code).autonym().title()) for code, _ in settings.LANGUAGES | ||
| ] | ||
|
|
||
| USERNAME_FIELD = 'pk' | ||
|
|
||
| password = models.CharField(_('password'), max_length=128, null=True, blank=True) | ||
| password = models.CharField(_('password'), max_length=128, default=get_default_password_hash) | ||
|
||
|
|
||
| user_UUID = models.CharField(max_length=36, primary_key=True, default=uuid.uuid4, editable=False, help_text='UUID randomly generated on ' | ||
| 'phone to identify each unique user. Must be exactly 36 ' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,9 @@ | |||||||||
|
|
||||||||||
| SECRET_KEY = 'h0v(25z3u9yquh+01+#%tj@7iyk*raq!-6)jwz+0ac^h2grd0@' | ||||||||||
|
|
||||||||||
| # Change this in prod | ||||||||||
| DEFAULT_TIGAUSER_PASSWORD = 'TEST_PASSWORD' | ||||||||||
|
Comment on lines
+35
to
+36
|
||||||||||
| # Change this in prod | |
| DEFAULT_TIGAUSER_PASSWORD = 'TEST_PASSWORD' | |
| # Set this via environment variable in production | |
| DEFAULT_TIGAUSER_PASSWORD = os.environ.get('DEFAULT_TIGAUSER_PASSWORD') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called every time a TigaUser instance is created, hashing the same password repeatedly. Since the default password is static, consider caching the hash result to avoid unnecessary computation on each user creation.