diff --git a/apps/authentication/backends/ldap.py b/apps/authentication/backends/ldap.py index f802b5307..b35903420 100644 --- a/apps/authentication/backends/ldap.py +++ b/apps/authentication/backends/ldap.py @@ -88,7 +88,10 @@ class LDAPUser(_LDAPUser): def _populate_user_from_attributes(self): super()._populate_user_from_attributes() if not hasattr(self._user, 'email') or '@' not in self._user.email: - email = '{}@{}'.format(self._user.username, settings.EMAIL_SUFFIX) + if '@' not in self._user.username: + email = '{}@{}'.format(self._user.username, settings.EMAIL_SUFFIX) + else: + email = self._user.username setattr(self._user, 'email', email) diff --git a/apps/jumpserver/conf.py b/apps/jumpserver/conf.py index ea9e9915e..ee6dcdbfd 100644 --- a/apps/jumpserver/conf.py +++ b/apps/jumpserver/conf.py @@ -193,7 +193,7 @@ class Config(dict): if self.root_path: filename = os.path.join(self.root_path, filename) try: - with open(filename) as f: + with open(filename, 'rt', encoding='utf8') as f: obj = yaml.load(f) except IOError as e: if silent and e.errno in (errno.ENOENT, errno.EISDIR): diff --git a/apps/ops/celery/__init__.py b/apps/ops/celery/__init__.py index 04f48299e..b64e20f01 100644 --- a/apps/ops/celery/__init__.py +++ b/apps/ops/celery/__init__.py @@ -6,12 +6,15 @@ from celery import Celery # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jumpserver.settings') - -from django.conf import settings +from jumpserver import settings +# from django.conf import settings app = Celery('jumpserver') +configs = {k: v for k, v in settings.__dict__.items() if k.startswith('CELERY')} # Using a string here means the worker will not have to # pickle the object when using Windows. -app.config_from_object('django.conf:settings', namespace='CELERY') +# app.config_from_object('django.conf:settings', namespace='CELERY') +app.namespace = 'CELERY' +app.conf.update(configs) app.autodiscover_tasks(lambda: [app_config.split('.')[0] for app_config in settings.INSTALLED_APPS]) diff --git a/apps/orgs/views.py b/apps/orgs/views.py index 5a363df0a..29bd231a7 100644 --- a/apps/orgs/views.py +++ b/apps/orgs/views.py @@ -14,8 +14,12 @@ class SwitchOrgView(DetailView): pk = kwargs.get('pk') self.object = Organization.get_instance(pk) request.session['oid'] = self.object.id.__str__() - referer = request.META.get('HTTP_REFERER', reverse('index')) - return redirect(referer) + host = request.get_host() + referer = request.META.get('HTTP_REFERER') + if referer.find(host) != -1: + return redirect(referer) + else: + return redirect('index') class SwitchToAOrgView(View):