1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 06:34:40 +00:00

Fixed bug when ACTIVATE_AFTER_REGISTRATION set to False on registraion complete.

This commit is contained in:
zhengxie
2013-07-18 16:52:23 +08:00
parent a3d32fe8e9
commit cbee63dcba
5 changed files with 39 additions and 14 deletions

16
seahub/base/generic.py Normal file
View File

@@ -0,0 +1,16 @@
from django.views.generic import TemplateView
class DirectTemplateView(TemplateView):
"""
Extend Django ``TemplateView`` to accept extra contexts.
"""
extra_context = None
def get_context_data(self, **kwargs):
context = super(self.__class__, self).get_context_data(**kwargs)
if self.extra_context is not None:
for key, value in self.extra_context.items():
if callable(value):
context[key] = value()
else:
context[key] = value
return context

View File

@@ -7,6 +7,7 @@ from registration.views import activate
from registration.views import register
from seahub.base.accounts import RegistrationForm
from seahub.base.generic import DirectTemplateView
reg_dict = { 'backend': 'seahub.base.accounts.RegistrationBackend',
'form_class': RegistrationForm,
@@ -42,12 +43,11 @@ if ENABLE_SIGNUP:
register,
reg_dict,
name='registration_register'),
# Refer http://stackoverflow.com/questions/11005733/moving-from-direct-to-template-to-new-templateview-in-django to migrate direct_to_template with extra_context.
# url(r'^register/complete/$',
# TemplateView.as_view(
# template_name='registration/registration_complete.html',
# extra_context={ 'send_mail': settings.REGISTRATION_SEND_MAIL } ),
# name='registration_complete'),
url(r'^register/complete/$',
DirectTemplateView.as_view(
template_name='registration/registration_complete.html',
extra_context={ 'send_mail': settings.REGISTRATION_SEND_MAIL } ),
name='registration_complete'),
url(r'^register/closed/$',
TemplateView.as_view(template_name='registration/registration_closed.html'),
name='registration_disallowed'),

View File

@@ -242,10 +242,11 @@ MAX_UPLOAD_FILE_NAME_LEN = 255
MAX_FILE_NAME = MAX_UPLOAD_FILE_NAME_LEN
MAX_PATH = 4096
# Set to True when user will be activaed after registration,
# and no email sending
# Whether or not activate user when registration complete.
# If set to ``False``, new user will be activated by admin or via activate link.
ACTIVATE_AFTER_REGISTRATION = True
# In order to use email sending, `ACTIVATE_AFTER_REGISTRATION` must set to False
# Whether or not send activation Email to user when registration complete.
# This option will be ignored if ``ACTIVATE_AFTER_REGISTRATION`` set to ``True``.
REGISTRATION_SEND_MAIL = False
# Seafile-applet address and port, used in repo download

View File

@@ -1,11 +1,14 @@
{% extends "myhome_base.html" %}
{% block title %}感谢注册{% endblock %}
{% load i18n %}
{% block title %}{% trans "Registration complete" %}{% endblock %}
{% block main_panel %}
<div class="text-panel">
{% if send_mail %}
<p>感谢注册,激活邮件已发往您的邮箱,请查收。如果您在收件箱里没找到,请检查下是否被当成垃圾邮件了。</p>
<p>{% trans "An activation email has been sent. Please check your email and click on the link to activate your account." %}</p>
{% else %}
<p>感谢注册,请等待管理员激活你的帐号。</p>
<p>{% trans "Registration complete, please wait for administrator to activate your account." %}</p>
{% endif %}
</div>
{% endblock %}

View File

@@ -231,10 +231,15 @@ def user_activate(request, user_id):
user = User.objects.get(id=int(user_id))
user.is_active = True
user.save()
messages.success(request, _(u'Successfully activated "%s".') % user.email)
except User.DoesNotExist:
pass
messages.success(request, _(u'Failed to activate: user does not exist.'))
return HttpResponseRedirect(reverse('sys_useradmin'))
next = request.META.get('HTTP_REFERER', None)
if not next:
next = reverse('sys_useradmin')
return HttpResponseRedirect(next)
def send_user_reset_email(request, email, password):
"""