Skip to content

Commit c4713ac

Browse files
committed
feat(passport): add disable register function
1 parent aeb2842 commit c4713ac

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

charts/passport/values.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ database_url: ""
1212
# can be specified as key-value pairs under environment
1313
# this is usually a non required setting.
1414
environment:
15+
## General settings
16+
# DRYCC_DEBUG: False
17+
# ADMIN_ENABLED: False
18+
# REGISTER_ENABLED: False
1519
## LDAP setting
1620
# LDAP_ENDPOINT: ""
1721
# LDAP_BIND_DN: ""
@@ -37,7 +41,6 @@ environment:
3741
# EMAIL_HOST_PASSWORD: ""
3842
# EMAIL_USE_TLS: ""
3943
# EMAIL_USE_SSL: ""
40-
# DEFAULT_FROM_EMAIL: ""
4144
# Used to create Django admin users
4245
admin_username: "admin"
4346
admin_password: "admin"

rootfs/api/settings/production.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1616
# SECURITY WARNING: don't run with debug turned on in production!
17-
DEBUG = bool(os.environ.get('DRYCC_DEBUG', True))
17+
DEBUG = bool(os.environ.get('DRYCC_DEBUG', False))
1818

1919
# If set to True, Django's normal exception handling of view functions
2020
# will be suppressed, and exceptions will propagate upwards
2121
# https://docs.djangoproject.com/en/2.2/ref/settings/#debug-propagate-exceptions
2222
DEBUG_PROPAGATE_EXCEPTIONS = True
2323
# Enable Django admin
2424
ADMIN_ENABLED = bool(os.environ.get('ADMIN_ENABLED', False))
25+
# Enable Register
26+
# If this function is enabled, please set Django email related parameters
27+
REGISTER_ENABLED = bool(os.environ.get('REGISTER_ENABLED', False))
2528
# Silence two security messages around SSL as router takes care of them
2629
# https://docs.djangoproject.com/en/2.2/ref/checks/#security
2730
SILENCED_SYSTEM_CHECKS = [
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends 'user/message.html' %}
2+
{% block title %}Register fail{% endblock %}
3+
{% block message %}
4+
The registration function of drycc passport is not enabled. Please contact the administrator to register.
5+
{% endblock %}

rootfs/api/views.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.contrib.auth.models import User
77
from django.contrib.auth import views
88
from django.db.models import Q
9-
from django.shortcuts import redirect, get_object_or_404
9+
from django.shortcuts import redirect, get_object_or_404, render
1010
from django.template.loader import render_to_string
1111
from django.http import HttpResponse
1212
from django.utils.encoding import force_bytes, force_text
@@ -65,10 +65,14 @@ class RegisterView(CreateView):
6565
template_name = 'user/register.html'
6666
success_url = reverse_lazy('register_done')
6767

68+
def get(self, request, *args, **kwargs):
69+
if settings.LDAP_ENDPOINT or not settings.REGISTER_ENABLED:
70+
return render(request, template_name='user/register_fail.html')
71+
return CreateView.get(self, request, *args, **kwargs)
72+
6873
def post(self, request, *args, **kwargs):
69-
if settings.LDAP_ENDPOINT:
70-
raise DryccException(
71-
"You cannot register user when ldap is enabled.")
74+
if settings.LDAP_ENDPOINT or not settings.REGISTER_ENABLED:
75+
return render(request, template_name='user/register_fail.html')
7276
form = self.form_class(request.POST)
7377
self.object = None
7478
if form.is_valid():

0 commit comments

Comments
 (0)