From 13677ef97a24fea19fe8df1cce4812c18623d88f Mon Sep 17 00:00:00 2001
From: Rasmus Larsson
Date: Sat, 9 Jul 2011 15:12:00 +0200
Subject: [PATCH 1/3] Added configuration variable to toggle registrations, if
disabled the registration page redirects to index and no link to register is
shown
---
mediagoblin.ini | 3 +++
mediagoblin/auth/views.py | 6 ++++++
mediagoblin/config_spec.ini | 5 ++++-
mediagoblin/templates/mediagoblin/root.html | 2 ++
mediagoblin/views.py | 4 +++-
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/mediagoblin.ini b/mediagoblin.ini
index 596107dc..e889646a 100644
--- a/mediagoblin.ini
+++ b/mediagoblin.ini
@@ -8,6 +8,9 @@ email_sender_address = "notice@mediagoblin.example.org"
# set to false to enable sending notices
email_debug_mode = true
+# Set to false to disable registrations
+allow_registration = true
+
## Uncomment this to put some user-overriding templates here
#local_templates = %(here)s/user_dev/templates/
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
index 2450023f..a6ae1407 100644
--- a/mediagoblin/auth/views.py
+++ b/mediagoblin/auth/views.py
@@ -19,6 +19,7 @@ import uuid
from webob import exc
from mediagoblin import messages
+from mediagoblin import mg_globals
from mediagoblin.util import render_to_response, redirect
from mediagoblin.db.util import ObjectId
from mediagoblin.auth import lib as auth_lib
@@ -30,6 +31,11 @@ def register(request):
"""
Your classic registration view!
"""
+
+ # Redirects to indexpage if registrations are disabled
+ if not mg_globals.app_config["allow_registration"]:
+ return redirect(request, "index")
+
register_form = auth_forms.RegistrationForm(request.POST)
if request.method == 'POST' and register_form.validate():
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index aadf5c21..b6356b0e 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -21,6 +21,9 @@ direct_remote_path = string(default="/mgoblin_static/")
email_debug_mode = boolean(default=True)
email_sender_address = string(default="notice@mediagoblin.example.org")
+# Set to false to disable registrations
+allow_registration = boolean(default=True)
+
# By default not set, but you might want something like:
# "%(here)s/user_dev/templates/"
local_templates = string()
@@ -73,4 +76,4 @@ celeryd_eta_scheduler_precision = float()
# known lists
celery_routes = string_list()
-celery_imports = string_list()
\ No newline at end of file
+celery_imports = string_list()
diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html
index 5b744999..ad9aabcb 100644
--- a/mediagoblin/templates/mediagoblin/root.html
+++ b/mediagoblin/templates/mediagoblin/root.html
@@ -29,10 +29,12 @@
If you have an account, you can
Login.
+ {% if allow_registration %}
If you don't have an account, please
Register.
+ {% endif %}
{% endif %}
{# temporarily, an "image gallery" that isn't one really ;) #}
diff --git a/mediagoblin/views.py b/mediagoblin/views.py
index 5b6d9773..6145484b 100644
--- a/mediagoblin/views.py
+++ b/mediagoblin/views.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
+from mediagoblin import mg_globals
from mediagoblin.util import render_to_response
from mediagoblin.db.util import DESCENDING
@@ -23,7 +24,8 @@ def root_view(request):
return render_to_response(
request, 'mediagoblin/root.html',
- {'media_entries': media_entries})
+ {'media_entries': media_entries,
+ 'allow_registration': mg_globals.app_config["allow_registration"]})
def simple_template_render(request):
From 13bb1d676e3363605d87acd34bdb6b701ec467dd Mon Sep 17 00:00:00 2001
From: Rasmus Larsson
Date: Sat, 9 Jul 2011 15:19:55 +0200
Subject: [PATCH 2/3] Updated the loginpage to not show a link to register if
registrations are disabled
---
mediagoblin/auth/views.py | 3 ++-
mediagoblin/templates/mediagoblin/auth/login.html | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
index a6ae1407..01bfc066 100644
--- a/mediagoblin/auth/views.py
+++ b/mediagoblin/auth/views.py
@@ -104,7 +104,8 @@ def login(request):
'mediagoblin/auth/login.html',
{'login_form': login_form,
'next': request.GET.get('next') or request.POST.get('next'),
- 'login_failed': login_failed})
+ 'login_failed': login_failed,
+ 'allow_registration': mg_globals.app_config["allow_registration"]})
def logout(request):
diff --git a/mediagoblin/templates/mediagoblin/auth/login.html b/mediagoblin/templates/mediagoblin/auth/login.html
index 2303ce5c..ebf5200a 100644
--- a/mediagoblin/templates/mediagoblin/auth/login.html
+++ b/mediagoblin/templates/mediagoblin/auth/login.html
@@ -35,7 +35,9 @@
{% endif %}
+ {% if allow_registration %}
Don't have an account yet?
Create one here!
+ {% endif %}
{% endblock %}
From 5647d641a27b1ebd9f9de4c8b6c452d80be0f4a2 Mon Sep 17 00:00:00 2001
From: Rasmus Larsson
Date: Sat, 9 Jul 2011 15:52:30 +0200
Subject: [PATCH 3/3] Updated spacings in code for better readability
---
mediagoblin/templates/mediagoblin/auth/login.html | 2 +-
mediagoblin/templates/mediagoblin/root.html | 8 ++++----
mediagoblin/views.py | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/mediagoblin/templates/mediagoblin/auth/login.html b/mediagoblin/templates/mediagoblin/auth/login.html
index ebf5200a..e25783ea 100644
--- a/mediagoblin/templates/mediagoblin/auth/login.html
+++ b/mediagoblin/templates/mediagoblin/auth/login.html
@@ -36,7 +36,7 @@
style="display: none;"/>
{% endif %}
{% if allow_registration %}
- Don't have an account yet?
Create one here!
+ Don't have an account yet?
Create one here!
{% endif %}
diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html
index ad9aabcb..bae033c4 100644
--- a/mediagoblin/templates/mediagoblin/root.html
+++ b/mediagoblin/templates/mediagoblin/root.html
@@ -30,10 +30,10 @@
Login.
{% if allow_registration %}
-
- If you don't have an account, please
- Register.
-
+
+ If you don't have an account, please
+ Register.
+
{% endif %}
{% endif %}
diff --git a/mediagoblin/views.py b/mediagoblin/views.py
index 6145484b..e7d9dbdd 100644
--- a/mediagoblin/views.py
+++ b/mediagoblin/views.py
@@ -25,7 +25,7 @@ def root_view(request):
return render_to_response(
request, 'mediagoblin/root.html',
{'media_entries': media_entries,
- 'allow_registration': mg_globals.app_config["allow_registration"]})
+ 'allow_registration': mg_globals.app_config["allow_registration"]})
def simple_template_render(request):