mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-22 16:56:57 +00:00
optimize org saml (#5555)
* optimize org saml * optimize log level * optimize code
This commit is contained in:
parent
a6c49ad604
commit
aa47faa7d1
@ -90,7 +90,7 @@ def gen_org_url_prefix(max_trial=None, length=20):
|
|||||||
Url prefix if succed, otherwise, ``None``.
|
Url prefix if succed, otherwise, ``None``.
|
||||||
"""
|
"""
|
||||||
def _gen_prefix():
|
def _gen_prefix():
|
||||||
url_prefix = 'org_' + get_random_string(
|
url_prefix = 'org-' + get_random_string(
|
||||||
length, allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789')
|
length, allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789')
|
||||||
if ccnet_api.get_org_by_url_prefix(url_prefix) is not None:
|
if ccnet_api.get_org_by_url_prefix(url_prefix) is not None:
|
||||||
logger.error("org url prefix, %s is duplicated" % url_prefix)
|
logger.error("org url prefix, %s is duplicated" % url_prefix)
|
||||||
|
@ -475,14 +475,21 @@ def multi_adfs_sso(request):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
org_saml_config = OrgSAMLConfig.objects.get_config_by_domain(domain)
|
org_saml_config = OrgSAMLConfig.objects.get_config_by_domain(domain)
|
||||||
|
if not org_saml_config:
|
||||||
|
render_data['error_msg'] = "Cannot find a SAML/ADFS config for the organization related to domain %s." % domain
|
||||||
|
return render(request, template_name, render_data)
|
||||||
org_id = org_saml_config.org_id
|
org_id = org_saml_config.org_id
|
||||||
org = ccnet_api.get_org_by_id(org_id)
|
org = ccnet_api.get_org_by_id(org_id)
|
||||||
|
if not org:
|
||||||
|
render_data['error_msg'] = 'Cannot find an organization related to domain %s.' % domain
|
||||||
|
return render(request, template_name, render_data)
|
||||||
|
url_prefix = org.url_prefix
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
render_data['error_msg'] = 'Error, please contact administrator.'
|
render_data['error_msg'] = 'Error, please contact administrator.'
|
||||||
return render(request, template_name, render_data)
|
return render(request, template_name, render_data)
|
||||||
|
|
||||||
return HttpResponseRedirect('/org/custom/%s/saml2/login/' % org.url_prefix)
|
return HttpResponseRedirect('/org/custom/%s/saml2/login/' % url_prefix)
|
||||||
|
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render(request, template_name, render_data)
|
return render(request, template_name, render_data)
|
||||||
|
@ -154,7 +154,7 @@ def gen_org_url_prefix(max_trial=None):
|
|||||||
Url prefix if succed, otherwise, ``None``.
|
Url prefix if succed, otherwise, ``None``.
|
||||||
"""
|
"""
|
||||||
def _gen_prefix():
|
def _gen_prefix():
|
||||||
url_prefix = 'org_' + get_random_string(
|
url_prefix = 'org-' + get_random_string(
|
||||||
6, allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789')
|
6, allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789')
|
||||||
if get_org_by_url_prefix(url_prefix) is not None:
|
if get_org_by_url_prefix(url_prefix) is not None:
|
||||||
logger.info("org url prefix, %s is duplicated" % url_prefix)
|
logger.info("org url prefix, %s is duplicated" % url_prefix)
|
||||||
|
Loading…
Reference in New Issue
Block a user