diff --git a/apps/common/apps.py b/apps/common/apps.py index 5fb85992a..18ed8a9a9 100644 --- a/apps/common/apps.py +++ b/apps/common/apps.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import os import sys from django.apps import AppConfig @@ -12,8 +13,11 @@ class CommonConfig(AppConfig): from . import signal_handlers # noqa from . import tasks # noqa from .signals import django_ready + excludes = ['migrate', 'compilemessages', 'makemigrations'] for i in excludes: if i in sys.argv: return - django_ready.send(CommonConfig) + + if not os.environ.get('DJANGO_DEBUG_SHELL'): + django_ready.send(CommonConfig) diff --git a/utils/activate_user.py b/utils/activate_user.py new file mode 100644 index 000000000..4f5170c45 --- /dev/null +++ b/utils/activate_user.py @@ -0,0 +1,42 @@ +import os +import sys + +import django + +if os.path.exists('../apps'): + sys.path.insert(0, '../apps') +elif os.path.exists('./apps'): + sys.path.insert(0, './apps') + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings") +os.environ.setdefault("DJANGO_DEBUG_SHELL", "1") +django.setup() + +from users.models import User +from django.utils import timezone + + +def activate_user(username): + user = User.objects.filter(username=username).first() + if not user: + print("Not found user: ", username) + return + + print("Activate user: ", username) + user.is_active = True + + if user.is_expired: + user.date_expired = timezone.now() + timezone.timedelta(days=365) + + if user.password_has_expired: + user.date_password_last_updated = timezone.now() + + user.save() + + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python activate_user.py ") + sys.exit(1) + username = sys.argv[1] + activate_user(username)