Commit 1463659a authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

enable moderation in SimpleBackend

Refs: #1990
parent e015e9e6
...@@ -39,6 +39,7 @@ from django.utils.translation import ugettext as _ ...@@ -39,6 +39,7 @@ from django.utils.translation import ugettext as _
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.contrib import messages from django.contrib import messages
from django.db import transaction from django.db import transaction
from django.core.urlresolvers import reverse
from smtplib import SMTPException from smtplib import SMTPException
from urllib import quote from urllib import quote
...@@ -46,7 +47,7 @@ from urllib import quote ...@@ -46,7 +47,7 @@ from urllib import quote
from astakos.im.models import AstakosUser, Invitation from astakos.im.models import AstakosUser, Invitation
from astakos.im.forms import * from astakos.im.forms import *
from astakos.im.util import get_invitation from astakos.im.util import get_invitation
from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, MODERATION_ENABLED
import socket import socket
import logging import logging
...@@ -221,16 +222,18 @@ class SimpleBackend(object): ...@@ -221,16 +222,18 @@ class SimpleBackend(object):
* DEFAULT_CONTACT_EMAIL: service support email * DEFAULT_CONTACT_EMAIL: service support email
* DEFAULT_FROM_EMAIL: from email * DEFAULT_FROM_EMAIL: from email
""" """
user = None user = form.save()
try: status = messages.SUCCESS
user = form.save() if MODERATION_ENABLED:
status = messages.SUCCESS message = _('Registration completed. You will receive an email upon your account\'s activation.')
_send_verification(self.request, user, email_template_name) else:
message = _('Verification sent to %s' % user.email) try:
except (SMTPException, socket.error) as e: _send_verification(self.request, user, email_template_name)
status = messages.ERROR message = _('Verification sent to %s' % user.email)
name = 'strerror' except (SMTPException, socket.error) as e:
message = getattr(e, name) if hasattr(e, name) else e status = messages.ERROR
name = 'strerror'
message = getattr(e, name) if hasattr(e, name) else e
# rollback in case of error # rollback in case of error
if status == messages.ERROR: if status == messages.ERROR:
...@@ -243,8 +246,9 @@ def _send_verification(request, user, template_name): ...@@ -243,8 +246,9 @@ def _send_verification(request, user, template_name):
site = Site.objects.get_current() site = Site.objects.get_current()
baseurl = request.build_absolute_uri('/').rstrip('/') baseurl = request.build_absolute_uri('/').rstrip('/')
url = '%s%s?auth=%s&next=%s' % (baseurl, url = '%s%s?auth=%s&next=%s' % (baseurl,
reverse('astakos.im.target.activate'), reverse('astakos.im.views.activate'),
quote(user.auth_token)) quote(user.auth_token),
quote(baseurl))
message = render_to_string(template_name, { message = render_to_string(template_name, {
'user': user, 'user': user,
'url': url, 'url': url,
......
...@@ -45,6 +45,9 @@ COOKIE_DOMAIN = getattr(settings, 'ASTAKOS_COOKIE_DOMAIN', None) ...@@ -45,6 +45,9 @@ COOKIE_DOMAIN = getattr(settings, 'ASTAKOS_COOKIE_DOMAIN', None)
IM_STATIC_URL = getattr(settings, 'ASTAKOS_IM_STATIC_URL', '/im/static/im/') IM_STATIC_URL = getattr(settings, 'ASTAKOS_IM_STATIC_URL', '/im/static/im/')
# If set to False and invitations not enabled newly created user will be automatically accepted
MODERATION_ENABLED = getattr(settings, 'ASTAKOS_MODERATION_ENABLED', True)
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL). # SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
BACKEND_DB_MODULE = getattr(settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy') BACKEND_DB_MODULE = getattr(settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy')
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION', 'sqlite:///' + join(PROJECT_PATH, 'backend.db')) BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION', 'sqlite:///' + join(PROJECT_PATH, 'backend.db'))
......
...@@ -16,9 +16,11 @@ ...@@ -16,9 +16,11 @@
<li class="{% if not tab %}active{% endif %}"> <li class="{% if not tab %}active{% endif %}">
<a href="{% url django.contrib.auth.views.password_change %}">Change password</a> <a href="{% url django.contrib.auth.views.password_change %}">Change password</a>
</li> </li>
{% if invitations_enabled %}
<li class="{% if tab == "im/invitations" %}active{% endif %}"> <li class="{% if tab == "im/invitations" %}active{% endif %}">
<a href="{% url astakos.im.views.invite %}">Invitations</a> <a href="{% url astakos.im.views.invite %}">Invitations</a>
</li> </li>
{% endif %}
<li class="{% if tab == "im/feedback" %}active{% endif %}"> <li class="{% if tab == "im/feedback" %}active{% endif %}">
<a href="{% url astakos.im.views.send_feedback %}">Send feedback</a> <a href="{% url astakos.im.views.send_feedback %}">Send feedback</a>
</li> </li>
......
...@@ -273,6 +273,7 @@ def edit_profile(request, template_name='im/profile.html', extra_context={}): ...@@ -273,6 +273,7 @@ def edit_profile(request, template_name='im/profile.html', extra_context={}):
extra_context, extra_context,
user=request.user)) user=request.user))
@requires_anonymous
def signup(request, on_failure='im/signup.html', on_success='im/signup_complete.html', extra_context={}, backend=None): def signup(request, on_failure='im/signup.html', on_success='im/signup_complete.html', extra_context={}, backend=None):
""" """
Allows a user to create a local account. Allows a user to create a local account.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment