diff --git a/base/accounts.py b/base/accounts.py
index 4f64b92ddf..f26a901c64 100644
--- a/base/accounts.py
+++ b/base/accounts.py
@@ -9,7 +9,7 @@ from django.contrib.sites.models import Site
from auth.models import get_hexdigest, check_password
from auth import authenticate, login
from registration import signals
-from registration.forms import RegistrationForm
+#from registration.forms import RegistrationForm
from registration.models import RegistrationProfile
from seaserv import ccnet_rpc, get_ccnetuser
@@ -29,13 +29,15 @@ def convert_to_ccnetuser(emailuser):
ccnetuser.is_staff = emailuser.props.is_staff
ccnetuser.is_active = emailuser.props.is_active
ccnetuser.ctime = emailuser.props.ctime
-
+ ccnetuser.org = emailuser.org
+
return ccnetuser
class CcnetUser(object):
is_staff = False
is_active = False
objects = UserManager()
+ org = None
def __init__(self, username, raw_password):
self.username = username
@@ -225,12 +227,6 @@ class RegistrationBackend(object):
# login the user
activated.backend='auth.backends.ModelBackend'
login(request, activated)
- # TODO: user.user_id should be change
- try:
- if request.user.user_id:
- ccnet_rpc.add_client(ccnet_user_id)
- except:
- pass
return activated
@@ -323,3 +319,146 @@ class RegistrationForm(forms.Form):
raise forms.ValidationError(_("The two password fields didn't match."))
return self.cleaned_data
+class OrgRegistrationForm(RegistrationForm):
+ """
+ Form for registering a business user account.
+
+ Validates that the requested email is not already in use, and
+ requires the password to be entered twice to catch typos.
+ """
+
+ org_name = forms.CharField(max_length=256,
+ widget=forms.TextInput(),
+ label=_("Organization Name"))
+ url_prefix = forms.RegexField(label=_("Url Prefix"), max_length=20,
+ regex=r'^[a-z0-9]+$',
+ error_message=_("This value must contain only letters or numbers."))
+
+ def clean_url_prefix(self):
+ url_prefix = self.cleaned_data['url_prefix']
+ org = ccnet_rpc.get_org_by_url_prefix(url_prefix)
+ if not org:
+ return url_prefix
+ else:
+ raise forms.ValidationError(_("A organization with this url prefix already"))
+
+class OrgRegistrationBackend(object):
+ def register(self, request, **kwargs):
+ """
+ Given a username, email address and password, register a new
+ user account, which will initially be inactive.
+
+ Along with the new ``User`` object, a new
+ ``registration.models.RegistrationProfile`` will be created,
+ tied to that ``User``, containing the activation key which
+ will be used for this account.
+
+ An email will be sent to the supplied email address; this
+ email should contain an activation link. The email will be
+ rendered using two templates. See the documentation for
+ ``RegistrationProfile.send_activation_email()`` for
+ information about these templates and the contexts provided to
+ them.
+
+ After the ``User`` and ``RegistrationProfile`` are created and
+ the activation email is sent, the signal
+ ``registration.signals.user_registered`` will be sent, with
+ the new ``User`` as the keyword argument ``user`` and the
+ class of this backend as the sender.
+
+ """
+ email, password = kwargs['email'], kwargs['password1']
+ username = email
+ org_name, url_prefix = kwargs['org_name'], kwargs['url_prefix']
+
+ if Site._meta.installed:
+ site = Site.objects.get_current()
+ else:
+ site = RequestSite(request)
+
+
+ if settings.ACTIVATE_AFTER_REGISTRATION:
+ # since user will be activated after registration,
+ # so we will not use email sending, just create acitvated user
+ new_user = RegistrationProfile.objects.create_active_user(username, email,
+ password, site,
+ send_email=False)
+ # create orgnization account
+ try:
+ ccnet_rpc.create_org(org_name, url_prefix, username)
+ except SearpcError, e:
+ pass
+ else:
+ # login the user
+ new_user.backend='auth.backends.ModelBackend'
+ login(request, new_user)
+ else:
+ # create inactive user, user can be activated by admin, or through activated email
+ new_user = RegistrationProfile.objects.create_inactive_user(username, email,
+ password, site,
+ send_email=settings.REGISTRATION_SEND_MAIL)
+
+ signals.user_registered.send(sender=self.__class__,
+ user=new_user,
+ request=request)
+ return new_user
+
+ def activate(self, request, activation_key):
+ """
+ Given an an activation key, look up and activate the user
+ account corresponding to that key (if possible).
+
+ After successful activation, the signal
+ ``registration.signals.user_activated`` will be sent, with the
+ newly activated ``User`` as the keyword argument ``user`` and
+ the class of this backend as the sender.
+
+ """
+ activated = RegistrationProfile.objects.activate_user(activation_key)
+ if activated:
+ signals.user_activated.send(sender=self.__class__,
+ user=activated,
+ request=request)
+ # login the user
+ activated.backend='auth.backends.ModelBackend'
+ login(request, activated)
+
+ return activated
+
+ def registration_allowed(self, request):
+ """
+ Indicate whether account registration is currently permitted,
+ based on the value of the setting ``REGISTRATION_OPEN``. This
+ is determined as follows:
+
+ * If ``REGISTRATION_OPEN`` is not specified in settings, or is
+ set to ``True``, registration is permitted.
+
+ * If ``REGISTRATION_OPEN`` is both specified and set to
+ ``False``, registration is not permitted.
+
+ """
+ return getattr(settings, 'REGISTRATION_OPEN', True)
+
+ def get_form_class(self, request):
+ """
+ Return the default form class used for user registration.
+
+ """
+ return RegistrationForm
+
+ def post_registration_redirect(self, request, user):
+ """
+ Return the name of the URL to redirect to after successful
+ user registration.
+
+ """
+ return ('registration_complete', (), {})
+
+ def post_activation_redirect(self, request, user):
+ """
+ Return the name of the URL to redirect to after successful
+ account activation.
+
+ """
+ return ('myhome', (), {})
diff --git a/base/context_processors.py b/base/context_processors.py
index 772989ec9f..4944bf1b6e 100644
--- a/base/context_processors.py
+++ b/base/context_processors.py
@@ -15,5 +15,6 @@ def base(request):
"""
return {
'seafile_version': settings.SEAFILE_VERSION,
- 'seahub_title': settings.SEAHUB_TITLE,
+ 'seahub_title': settings.SEAHUB_TITLE,
+ 'account_type': settings.ACCOUNT_TYPE,
}
diff --git a/base/middleware.py b/base/middleware.py
index 490d62859b..2a146c640e 100644
--- a/base/middleware.py
+++ b/base/middleware.py
@@ -47,4 +47,3 @@ class InfobarMiddleware(object):
def process_response(self, request, response):
return response
-
diff --git a/base/registration_urls.py b/base/registration_urls.py
index 07c9eac8fc..5987dd8649 100644
--- a/base/registration_urls.py
+++ b/base/registration_urls.py
@@ -6,13 +6,20 @@ from registration.views import activate
from registration.views import register
from seahub.base.accounts import RegistrationForm
+from seahub.base.accounts import OrgRegistrationForm
reg_dict = { 'backend': 'seahub.base.accounts.RegistrationBackend',
'form_class': RegistrationForm,
}
+org_reg_dict = { 'backend': 'seahub.base.accounts.OrgRegistrationBackend',
+ 'form_class': OrgRegistrationForm,
+ 'template_name': 'registration/org_registration_form.html',
+ }
+
if settings.ACTIVATE_AFTER_REGISTRATION == True:
reg_dict['success_url'] = settings.SITE_ROOT
+ org_reg_dict['success_url'] = settings.SITE_ROOT
urlpatterns = patterns('',
url(r'^activate/complete/$',
@@ -40,5 +47,11 @@ urlpatterns = patterns('',
direct_to_template,
{ 'template': 'registration/registration_closed.html' },
name='registration_disallowed'),
+
+ url(r'^business/register/$',
+ register,
+ org_reg_dict,
+ name='registration_register'),
+
(r'', include('registration.auth_urls')),
)
diff --git a/contacts/templates/contacts/contact_edit.html b/contacts/templates/contacts/contact_edit.html
index c5b57413d2..868cacd443 100644
--- a/contacts/templates/contacts/contact_edit.html
+++ b/contacts/templates/contacts/contact_edit.html
@@ -8,7 +8,7 @@