diff --git a/base/accounts.py b/base/accounts.py index 0e0027f2af..f6057a6381 100644 --- a/base/accounts.py +++ b/base/accounts.py @@ -209,10 +209,14 @@ class RegistrationBackend(object): else: site = RequestSite(request) - new_user = RegistrationProfile.objects.create_inactive_user(username, email, - password, site, - send_email=settings.REGISTRATION_SEND_MAIL) - + new_user = RegistrationProfile.objects.create_active_user(username, email, + password, site, + send_email=settings.REGISTRATION_SEND_MAIL) + + # login the user + new_user.backend='auth.backends.ModelBackend' + login(request, new_user) + userid = kwargs['userid'] if userid: ccnet_rpc.add_binding(new_user.username, userid) diff --git a/base/registration_urls.py b/base/registration_urls.py index c1d147d149..9d892f02d2 100644 --- a/base/registration_urls.py +++ b/base/registration_urls.py @@ -7,7 +7,6 @@ from registration.views import register from seahub.base.accounts import RegistrationForm - urlpatterns = patterns('', url(r'^activate/complete/$', direct_to_template, @@ -24,7 +23,9 @@ urlpatterns = patterns('', url(r'^register/$', register, { 'backend': 'seahub.base.accounts.RegistrationBackend', - 'form_class': RegistrationForm }, + 'form_class': RegistrationForm, + 'success_url': '/', + }, name='registration_register'), url(r'^register/complete/$', direct_to_template, diff --git a/settings.py b/settings.py index 1c2b74188c..362d82a2f4 100644 --- a/settings.py +++ b/settings.py @@ -113,7 +113,9 @@ AUTHENTICATION_BACKENDS = ( ACCOUNT_ACTIVATION_DAYS = 7 -REGISTRATION_SEND_MAIL = True +# this value should be false, since user will be activated after registration +# since 0.9.2 +REGISTRATION_SEND_MAIL = False # seafile httpserver address and port HTTP_SERVER_ROOT = "http://localhost:8082" diff --git a/templates/registration/registration_form.html b/templates/registration/registration_form.html index 942f862b09..1d37ee1353 100644 --- a/templates/registration/registration_form.html +++ b/templates/registration/registration_form.html @@ -4,7 +4,7 @@

用户注册

- {{ form.email }}(我们将给您发送帐号激活邮件.) + {{ form.email }} {% if form.email.errors %} {{ form.email.errors }} {% endif %}
diff --git a/templates/useradmin.html b/templates/useradmin.html index c96c17c671..5a12403507 100644 --- a/templates/useradmin.html +++ b/templates/useradmin.html @@ -26,23 +26,13 @@ {% else %} {% endif %} - {% if user.profile %} {% endif %} + {% if not user.is_self %} + {% endif %} {% endfor %} diff --git a/thirdpart/auth/__init__.py b/thirdpart/auth/__init__.py index 7efe320744..c88774cfa3 100644 --- a/thirdpart/auth/__init__.py +++ b/thirdpart/auth/__init__.py @@ -3,7 +3,7 @@ from warnings import warn from django.core.exceptions import ImproperlyConfigured from django.utils.importlib import import_module -SESSION_KEY = '_auth_user_id' +SESSION_KEY = '_auth_user_name' BACKEND_SESSION_KEY = '_auth_user_backend' REDIRECT_FIELD_NAME = 'next' diff --git a/thirdpart/registration/models.py b/thirdpart/registration/models.py index 51fa9b561e..914a2a9112 100644 --- a/thirdpart/registration/models.py +++ b/thirdpart/registration/models.py @@ -61,9 +61,9 @@ class RegistrationManager(models.Manager): profile.save() return ccnetuser return False - - def create_inactive_user(self, username, email, password, - site, send_email=True): + + def create_email_user(self, username, email, password, + site, send_email=True, is_active=False): """ Create a new, inactive ``User``, generate a ``RegistrationProfile`` and email its activation key to the @@ -73,11 +73,10 @@ class RegistrationManager(models.Manager): user. To disable this, pass ``send_email=False``. """ - from seahub.base.accounts import CcnetUser ccnetuser = CcnetUser.objects.create_user(username, password, False, False) - ccnetuser.is_active = False + ccnetuser.is_active = is_active ccnetuser.save() registration_profile = self.create_profile(ccnetuser) @@ -86,6 +85,19 @@ class RegistrationManager(models.Manager): registration_profile.send_activation_email(site) return ccnetuser + + def create_inactive_user(self, username, email, password, + site, send_email=True): + + return self.create_email_user(username, email, password, site, + send_email, is_active=False) + create_inactive_user = transaction.commit_on_success(create_inactive_user) + + def create_active_user(self, username, email, password, + site, send_email=True): + + return self.create_email_user(username, email, password, site, + send_email, is_active=True) create_inactive_user = transaction.commit_on_success(create_inactive_user) def create_profile(self, user): diff --git a/views.py b/views.py index e86038c54c..efadcce8bd 100644 --- a/views.py +++ b/views.py @@ -382,13 +382,9 @@ def useradmin(request): users = ccnet_rpc.get_emailusers(-1,-1) for user in users: - try: - user.userid_list = get_binding_userids(user.get_email()) -# user.ccnet_user = ccnet_rpc.get_user(user.profile.ccnet_user_id) -# user.role_list = user.ccnet_user.props.role_list.split(',') - except: - user.ccnet_user = None - + if user.props.id == request.user.id: + user.is_self = True + return render_to_response( 'useradmin.html', { 'users': users,