From 53201b105d757be266e087dca968ea8ebaf4b4cf Mon Sep 17 00:00:00 2001 From: zhengxie Date: Tue, 7 May 2013 10:33:26 +0800 Subject: [PATCH] Move auth from thirdpart to seahub --- seahub/api2/serializers.py | 2 +- {thirdpart => seahub}/auth/__init__.py | 6 +- {thirdpart => seahub}/auth/admin.py | 0 {thirdpart => seahub}/auth/decorators.py | 2 +- .../auth/fixtures/authtestdata.json | 0 {thirdpart => seahub}/auth/forms.py | 5 +- .../auth/handlers/modpython.py | 0 .../auth/locale/fr/LC_MESSAGES/django.po | 0 .../auth/locale/zh_CN/LC_MESSAGES/django.po | 0 .../auth/management/__init__.py | 0 .../management/commands/changepassword.py | 0 .../management/commands/createsuperuser.py | 0 {thirdpart => seahub}/auth/middleware.py | 2 +- {thirdpart => seahub}/auth/models.py | 2 +- {thirdpart => seahub}/auth/tests/__init__.py | 0 .../auth/tests/auth_backends.py | 0 {thirdpart => seahub}/auth/tests/basic.py | 0 .../auth/tests/decorators.py | 0 {thirdpart => seahub}/auth/tests/forms.py | 0 {thirdpart => seahub}/auth/tests/models.py | 0 .../auth/tests/remote_user.py | 0 .../tests/templates/registration/login.html | 0 .../registration/password_reset_complete.html | 0 .../registration/password_reset_confirm.html | 0 .../registration/password_reset_done.html | 0 .../registration/password_reset_email.html | 0 .../registration/password_reset_form.html | 0 {thirdpart => seahub}/auth/tests/tokens.py | 0 {thirdpart => seahub}/auth/tests/urls.py | 0 {thirdpart => seahub}/auth/tests/views.py | 0 {thirdpart => seahub}/auth/tokens.py | 0 {thirdpart => seahub}/auth/urls.py | 0 {thirdpart => seahub}/auth/views.py | 20 +++---- seahub/avatar/views.py | 2 +- seahub/base/accounts.py | 25 ++++++-- seahub/base/mixins.py | 2 +- seahub/contacts/views.py | 2 +- seahub/group/views.py | 2 +- seahub/notifications/views.py | 3 +- seahub/profile/views.py | 2 +- seahub/settings.py | 6 +- seahub/share/views.py | 2 +- .../registration/password_reset_email.html | 2 +- seahub/templates/user_add_email.html | 2 +- seahub/views/__init__.py | 8 +-- seahub/views/file.py | 2 +- seahub/views/search.py | 3 +- seahub/views/wiki.py | 4 +- thirdpart/auth/backends.py | 60 ------------------- thirdpart/auth/context_processors.py | 33 ---------- thirdpart/auth/create_superuser.py | 8 --- thirdpart/auth/i18n.sh.template | 7 --- thirdpart/registration/auth_urls.py | 2 +- 53 files changed, 60 insertions(+), 156 deletions(-) rename {thirdpart => seahub}/auth/__init__.py (96%) rename {thirdpart => seahub}/auth/admin.py (100%) rename {thirdpart => seahub}/auth/decorators.py (97%) rename {thirdpart => seahub}/auth/fixtures/authtestdata.json (100%) rename {thirdpart => seahub}/auth/forms.py (98%) rename {thirdpart => seahub}/auth/handlers/modpython.py (100%) rename {thirdpart => seahub}/auth/locale/fr/LC_MESSAGES/django.po (100%) rename {thirdpart => seahub}/auth/locale/zh_CN/LC_MESSAGES/django.po (100%) rename {thirdpart => seahub}/auth/management/__init__.py (100%) rename {thirdpart => seahub}/auth/management/commands/changepassword.py (100%) rename {thirdpart => seahub}/auth/management/commands/createsuperuser.py (100%) rename {thirdpart => seahub}/auth/middleware.py (98%) rename {thirdpart => seahub}/auth/models.py (99%) rename {thirdpart => seahub}/auth/tests/__init__.py (100%) rename {thirdpart => seahub}/auth/tests/auth_backends.py (100%) rename {thirdpart => seahub}/auth/tests/basic.py (100%) rename {thirdpart => seahub}/auth/tests/decorators.py (100%) rename {thirdpart => seahub}/auth/tests/forms.py (100%) rename {thirdpart => seahub}/auth/tests/models.py (100%) rename {thirdpart => seahub}/auth/tests/remote_user.py (100%) rename {thirdpart => seahub}/auth/tests/templates/registration/login.html (100%) rename {thirdpart => seahub}/auth/tests/templates/registration/password_reset_complete.html (100%) rename {thirdpart => seahub}/auth/tests/templates/registration/password_reset_confirm.html (100%) rename {thirdpart => seahub}/auth/tests/templates/registration/password_reset_done.html (100%) rename {thirdpart => seahub}/auth/tests/templates/registration/password_reset_email.html (100%) rename {thirdpart => seahub}/auth/tests/templates/registration/password_reset_form.html (100%) rename {thirdpart => seahub}/auth/tests/tokens.py (100%) rename {thirdpart => seahub}/auth/tests/urls.py (100%) rename {thirdpart => seahub}/auth/tests/views.py (100%) rename {thirdpart => seahub}/auth/tokens.py (100%) rename {thirdpart => seahub}/auth/urls.py (100%) rename {thirdpart => seahub}/auth/views.py (93%) delete mode 100644 thirdpart/auth/backends.py delete mode 100644 thirdpart/auth/context_processors.py delete mode 100644 thirdpart/auth/create_superuser.py delete mode 100755 thirdpart/auth/i18n.sh.template diff --git a/seahub/api2/serializers.py b/seahub/api2/serializers.py index 7d9a8aa84c..542e06787a 100644 --- a/seahub/api2/serializers.py +++ b/seahub/api2/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from auth import authenticate +from seahub.auth import authenticate class AuthTokenSerializer(serializers.Serializer): username = serializers.CharField() diff --git a/thirdpart/auth/__init__.py b/seahub/auth/__init__.py similarity index 96% rename from thirdpart/auth/__init__.py rename to seahub/auth/__init__.py index 76901f5266..312f59fc40 100644 --- a/thirdpart/auth/__init__.py +++ b/seahub/auth/__init__.py @@ -4,7 +4,7 @@ from django.core.exceptions import ImproperlyConfigured from django.utils.importlib import import_module SESSION_KEY = '_auth_user_name' -BACKEND_SESSION_KEY = '_auth_user_backend' +BACKEND_SESSION_KEY = '_auth_user_backend_2' REDIRECT_FIELD_NAME = 'next' def load_backend(path): @@ -93,11 +93,11 @@ def logout(request): from seahub.base.accounts import User if isinstance(request.user, User): request.user.remove_repo_passwds() - from auth.models import AnonymousUser + from seahub.auth.models import AnonymousUser request.user = AnonymousUser() def get_user(request): - from auth.models import AnonymousUser + from seahub.auth.models import AnonymousUser try: username = request.session[SESSION_KEY] backend_path = request.session[BACKEND_SESSION_KEY] diff --git a/thirdpart/auth/admin.py b/seahub/auth/admin.py similarity index 100% rename from thirdpart/auth/admin.py rename to seahub/auth/admin.py diff --git a/thirdpart/auth/decorators.py b/seahub/auth/decorators.py similarity index 97% rename from thirdpart/auth/decorators.py rename to seahub/auth/decorators.py index 509ceecd2e..634b82b883 100644 --- a/thirdpart/auth/decorators.py +++ b/seahub/auth/decorators.py @@ -3,7 +3,7 @@ try: except ImportError: from django.utils.functional import update_wrapper, wraps # Python 2.4 fallback. -from auth import REDIRECT_FIELD_NAME +from seahub.auth import REDIRECT_FIELD_NAME from django.http import HttpResponseRedirect, HttpResponse from django.utils.decorators import available_attrs from django.utils.http import urlquote diff --git a/thirdpart/auth/fixtures/authtestdata.json b/seahub/auth/fixtures/authtestdata.json similarity index 100% rename from thirdpart/auth/fixtures/authtestdata.json rename to seahub/auth/fixtures/authtestdata.json diff --git a/thirdpart/auth/forms.py b/seahub/auth/forms.py similarity index 98% rename from thirdpart/auth/forms.py rename to seahub/auth/forms.py index 3b88616ad5..39d4dde475 100644 --- a/thirdpart/auth/forms.py +++ b/seahub/auth/forms.py @@ -1,6 +1,3 @@ -from auth import authenticate -from auth.tokens import default_token_generator - from django.contrib.sites.models import Site from django.template import Context, loader from django import forms @@ -8,6 +5,8 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.http import int_to_base36 from seahub.base.accounts import User +from seahub.auth import authenticate +from seahub.auth.tokens import default_token_generator from seahub.utils import IS_EMAIL_CONFIGURED class AuthenticationForm(forms.Form): diff --git a/thirdpart/auth/handlers/modpython.py b/seahub/auth/handlers/modpython.py similarity index 100% rename from thirdpart/auth/handlers/modpython.py rename to seahub/auth/handlers/modpython.py diff --git a/thirdpart/auth/locale/fr/LC_MESSAGES/django.po b/seahub/auth/locale/fr/LC_MESSAGES/django.po similarity index 100% rename from thirdpart/auth/locale/fr/LC_MESSAGES/django.po rename to seahub/auth/locale/fr/LC_MESSAGES/django.po diff --git a/thirdpart/auth/locale/zh_CN/LC_MESSAGES/django.po b/seahub/auth/locale/zh_CN/LC_MESSAGES/django.po similarity index 100% rename from thirdpart/auth/locale/zh_CN/LC_MESSAGES/django.po rename to seahub/auth/locale/zh_CN/LC_MESSAGES/django.po diff --git a/thirdpart/auth/management/__init__.py b/seahub/auth/management/__init__.py similarity index 100% rename from thirdpart/auth/management/__init__.py rename to seahub/auth/management/__init__.py diff --git a/thirdpart/auth/management/commands/changepassword.py b/seahub/auth/management/commands/changepassword.py similarity index 100% rename from thirdpart/auth/management/commands/changepassword.py rename to seahub/auth/management/commands/changepassword.py diff --git a/thirdpart/auth/management/commands/createsuperuser.py b/seahub/auth/management/commands/createsuperuser.py similarity index 100% rename from thirdpart/auth/management/commands/createsuperuser.py rename to seahub/auth/management/commands/createsuperuser.py diff --git a/thirdpart/auth/middleware.py b/seahub/auth/middleware.py similarity index 98% rename from thirdpart/auth/middleware.py rename to seahub/auth/middleware.py index d9d965b285..c62567f64e 100644 --- a/thirdpart/auth/middleware.py +++ b/seahub/auth/middleware.py @@ -5,7 +5,7 @@ from django.core.exceptions import ImproperlyConfigured class LazyUser(object): def __get__(self, request, obj_type=None): if not hasattr(request, '_cached_user'): - from auth import get_user + from seahub.auth import get_user request._cached_user = get_user(request) return request._cached_user diff --git a/thirdpart/auth/models.py b/seahub/auth/models.py similarity index 99% rename from thirdpart/auth/models.py rename to seahub/auth/models.py index 93638eeceb..c9805c2a86 100644 --- a/thirdpart/auth/models.py +++ b/seahub/auth/models.py @@ -1,7 +1,7 @@ import datetime import urllib -import auth +# import auth from django.core.exceptions import ImproperlyConfigured from django.db import models from django.db.models.manager import EmptyManager diff --git a/thirdpart/auth/tests/__init__.py b/seahub/auth/tests/__init__.py similarity index 100% rename from thirdpart/auth/tests/__init__.py rename to seahub/auth/tests/__init__.py diff --git a/thirdpart/auth/tests/auth_backends.py b/seahub/auth/tests/auth_backends.py similarity index 100% rename from thirdpart/auth/tests/auth_backends.py rename to seahub/auth/tests/auth_backends.py diff --git a/thirdpart/auth/tests/basic.py b/seahub/auth/tests/basic.py similarity index 100% rename from thirdpart/auth/tests/basic.py rename to seahub/auth/tests/basic.py diff --git a/thirdpart/auth/tests/decorators.py b/seahub/auth/tests/decorators.py similarity index 100% rename from thirdpart/auth/tests/decorators.py rename to seahub/auth/tests/decorators.py diff --git a/thirdpart/auth/tests/forms.py b/seahub/auth/tests/forms.py similarity index 100% rename from thirdpart/auth/tests/forms.py rename to seahub/auth/tests/forms.py diff --git a/thirdpart/auth/tests/models.py b/seahub/auth/tests/models.py similarity index 100% rename from thirdpart/auth/tests/models.py rename to seahub/auth/tests/models.py diff --git a/thirdpart/auth/tests/remote_user.py b/seahub/auth/tests/remote_user.py similarity index 100% rename from thirdpart/auth/tests/remote_user.py rename to seahub/auth/tests/remote_user.py diff --git a/thirdpart/auth/tests/templates/registration/login.html b/seahub/auth/tests/templates/registration/login.html similarity index 100% rename from thirdpart/auth/tests/templates/registration/login.html rename to seahub/auth/tests/templates/registration/login.html diff --git a/thirdpart/auth/tests/templates/registration/password_reset_complete.html b/seahub/auth/tests/templates/registration/password_reset_complete.html similarity index 100% rename from thirdpart/auth/tests/templates/registration/password_reset_complete.html rename to seahub/auth/tests/templates/registration/password_reset_complete.html diff --git a/thirdpart/auth/tests/templates/registration/password_reset_confirm.html b/seahub/auth/tests/templates/registration/password_reset_confirm.html similarity index 100% rename from thirdpart/auth/tests/templates/registration/password_reset_confirm.html rename to seahub/auth/tests/templates/registration/password_reset_confirm.html diff --git a/thirdpart/auth/tests/templates/registration/password_reset_done.html b/seahub/auth/tests/templates/registration/password_reset_done.html similarity index 100% rename from thirdpart/auth/tests/templates/registration/password_reset_done.html rename to seahub/auth/tests/templates/registration/password_reset_done.html diff --git a/thirdpart/auth/tests/templates/registration/password_reset_email.html b/seahub/auth/tests/templates/registration/password_reset_email.html similarity index 100% rename from thirdpart/auth/tests/templates/registration/password_reset_email.html rename to seahub/auth/tests/templates/registration/password_reset_email.html diff --git a/thirdpart/auth/tests/templates/registration/password_reset_form.html b/seahub/auth/tests/templates/registration/password_reset_form.html similarity index 100% rename from thirdpart/auth/tests/templates/registration/password_reset_form.html rename to seahub/auth/tests/templates/registration/password_reset_form.html diff --git a/thirdpart/auth/tests/tokens.py b/seahub/auth/tests/tokens.py similarity index 100% rename from thirdpart/auth/tests/tokens.py rename to seahub/auth/tests/tokens.py diff --git a/thirdpart/auth/tests/urls.py b/seahub/auth/tests/urls.py similarity index 100% rename from thirdpart/auth/tests/urls.py rename to seahub/auth/tests/urls.py diff --git a/thirdpart/auth/tests/views.py b/seahub/auth/tests/views.py similarity index 100% rename from thirdpart/auth/tests/views.py rename to seahub/auth/tests/views.py diff --git a/thirdpart/auth/tokens.py b/seahub/auth/tokens.py similarity index 100% rename from thirdpart/auth/tokens.py rename to seahub/auth/tokens.py diff --git a/thirdpart/auth/urls.py b/seahub/auth/urls.py similarity index 100% rename from thirdpart/auth/urls.py rename to seahub/auth/urls.py diff --git a/thirdpart/auth/views.py b/seahub/auth/views.py similarity index 93% rename from thirdpart/auth/views.py rename to seahub/auth/views.py index b001692548..3ebb8e6527 100644 --- a/thirdpart/auth/views.py +++ b/seahub/auth/views.py @@ -13,12 +13,12 @@ from django.utils.http import urlquote, base36_to_int from django.utils.translation import ugettext as _ from django.views.decorators.cache import never_cache -from auth import REDIRECT_FIELD_NAME -from auth import login as auth_login -from auth.decorators import login_required -from auth.forms import AuthenticationForm -from auth.forms import PasswordResetForm, SetPasswordForm, PasswordChangeForm -from auth.tokens import default_token_generator +from seahub.auth import REDIRECT_FIELD_NAME +from seahub.auth import login as auth_login +from seahub.auth.decorators import login_required +from seahub.auth.forms import AuthenticationForm +from seahub.auth.forms import PasswordResetForm, SetPasswordForm, PasswordChangeForm +from seahub.auth.tokens import default_token_generator from seahub.base.accounts import User @@ -79,7 +79,7 @@ def login(request, template_name='registration/login.html', def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME): "Logs out the user and displays 'You are logged out' message." - from auth import logout + from seahub.auth import logout logout(request) if next_page is None: redirect_to = request.REQUEST.get(redirect_field_name, '') @@ -118,7 +118,7 @@ def password_reset(request, is_admin_site=False, template_name='registration/pas password_reset_form=PasswordResetForm, token_generator=default_token_generator, post_reset_redirect=None): if post_reset_redirect is None: - post_reset_redirect = reverse('auth.views.password_reset_done') + post_reset_redirect = reverse('auth_password_reset_done') if request.method == "POST": form = password_reset_form(request.POST) if form.is_valid(): @@ -160,7 +160,7 @@ def password_reset_confirm(request, uidb36=None, token=None, template_name='regi """ assert uidb36 is not None and token is not None # checked by URLconf if post_reset_redirect is None: - post_reset_redirect = reverse('auth.views.password_reset_complete') + post_reset_redirect = reverse('auth_password_reset_complete') try: uid_int = base36_to_int(uidb36) user = User.objects.get(id=uid_int) @@ -193,7 +193,7 @@ def password_reset_complete(request, template_name='registration/password_reset_ def password_change(request, template_name='registration/password_change_form.html', post_change_redirect=None, password_change_form=PasswordChangeForm): if post_change_redirect is None: - post_change_redirect = reverse('auth.views.password_change_done') + post_change_redirect = reverse('auth_password_change_done') if request.method == "POST": form = password_change_form(user=request.user, data=request.POST) if form.is_valid(): diff --git a/seahub/avatar/views.py b/seahub/avatar/views.py index be4077c042..7dfb732eac 100644 --- a/seahub/avatar/views.py +++ b/seahub/avatar/views.py @@ -17,7 +17,7 @@ from seahub.avatar.util import get_primary_avatar, get_default_avatar_url, \ from seahub.utils import render_error, render_permission_error, \ check_and_get_org_by_group -from auth.decorators import login_required +from seahub.auth.decorators import login_required from seaserv import ccnet_threaded_rpc, check_group_staff def _get_next(request): diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py index dd98907630..d67fdf5f4f 100644 --- a/seahub/base/accounts.py +++ b/seahub/base/accounts.py @@ -7,8 +7,8 @@ from django.conf import settings from django.contrib.sites.models import RequestSite from django.contrib.sites.models import Site -from auth.models import get_hexdigest, check_password -from auth import authenticate, login +from seahub.auth.models import get_hexdigest, check_password +from seahub.auth import login from registration import signals #from registration.forms import RegistrationForm from seaserv import ccnet_threaded_rpc, unset_repo_passwd, is_passwd_set @@ -183,6 +183,22 @@ class User(object): for r in passwd_setted_repos: unset_repo_passwd(r.id, self.email) +class AuthBackend(object): + def get_user(self, username): + try: + user = User.objects.get(email=username) + except User.DoesNotExist: + user = None + return user + + def authenticate(self, username=None, password=None): + try: + user = User.objects.get(email=username) + if user.check_password(password): + return user + except User.DoesNotExist: + return None + class RegistrationBackend(object): """ A registration backend which follows a simple workflow: @@ -261,7 +277,8 @@ class RegistrationBackend(object): password, site, send_email=False) # login the user - new_user.backend='auth.backends.ModelBackend' + new_user.backend=settings.AUTHENTICATION_BACKENDS[0] + login(request, new_user) else: # create inactive user, user can be activated by admin, or through activated email @@ -296,7 +313,7 @@ class RegistrationBackend(object): user=activated, request=request) # login the user - activated.backend='auth.backends.ModelBackend' + activated.backend=settings.AUTHENTICATION_BACKENDS[0] login(request, activated) return activated diff --git a/seahub/base/mixins.py b/seahub/base/mixins.py index 08881d0997..fa2afe2c6b 100644 --- a/seahub/base/mixins.py +++ b/seahub/base/mixins.py @@ -1,5 +1,5 @@ from django.utils.decorators import method_decorator -from auth.decorators import login_required +from seahub.auth.decorators import login_required # from base.decorators import ctx_switch_required diff --git a/seahub/contacts/views.py b/seahub/contacts/views.py index 0d86ad8f5a..13cd6a9dd0 100644 --- a/seahub/contacts/views.py +++ b/seahub/contacts/views.py @@ -5,13 +5,13 @@ from django.http import HttpResponse, HttpResponseBadRequest, \ from django.shortcuts import render_to_response, Http404 from django.core.urlresolvers import reverse from django.template import RequestContext -from django.contrib.auth.decorators import login_required from django.core.exceptions import ObjectDoesNotExist from django.forms.models import modelformset_factory from django.contrib import messages from django.utils.translation import ugettext as _ from models import Contact, ContactAddForm, ContactEditForm +from seahub.auth.decorators import login_required from seahub.utils import render_error from seaserv import ccnet_rpc, ccnet_threaded_rpc from seahub.views import is_registered_user diff --git a/seahub/group/views.py b/seahub/group/views.py index e7f9a3a2d2..96f943b94a 100644 --- a/seahub/group/views.py +++ b/seahub/group/views.py @@ -20,7 +20,7 @@ from django.utils.hashcompat import md5_constructor from django.utils.translation import ugettext as _ from django.utils.translation import ungettext -from auth.decorators import login_required +from seahub.auth.decorators import login_required import seaserv from seaserv import ccnet_threaded_rpc, seafserv_threaded_rpc, seafserv_rpc, \ web_get_access_token, \ diff --git a/seahub/notifications/views.py b/seahub/notifications/views.py index a564ab19fb..1bc5c12a83 100644 --- a/seahub/notifications/views.py +++ b/seahub/notifications/views.py @@ -4,8 +4,7 @@ from django.http import HttpResponseRedirect, Http404 from django.shortcuts import render_to_response from django.template import RequestContext -from auth.decorators import login_required - +from seahub.auth.decorators import login_required from seahub.notifications.models import Notification, NotificationForm from seahub.notifications.utils import refresh_cache diff --git a/seahub/profile/views.py b/seahub/profile/views.py index 73a8e0036f..f1fdba132a 100644 --- a/seahub/profile/views.py +++ b/seahub/profile/views.py @@ -5,7 +5,6 @@ from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response, get_object_or_404 from django.template import Context, RequestContext from django.contrib import messages -from django.contrib.auth.decorators import login_required from django.utils.translation import ugettext as _ from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_binding_peerids @@ -14,6 +13,7 @@ from pysearpc import SearpcError from forms import ProfileForm from models import Profile from utils import refresh_cache +from seahub.auth.decorators import login_required from seahub.utils import render_error from seahub.base.accounts import User from seahub.contacts.models import Contact diff --git a/seahub/settings.py b/seahub/settings.py index a8a376c25a..407eed00a7 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -103,7 +103,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - 'auth.middleware.AuthenticationMiddleware', + 'seahub.auth.middleware.AuthenticationMiddleware', 'seahub.base.middleware.BaseMiddleware', 'seahub.base.middleware.InfobarMiddleware', ) @@ -137,7 +137,7 @@ LANGUAGES = ( ) LOCALE_PATHS = ( os.path.join(os.path.dirname(__file__), 'locale'), - os.path.join(os.path.dirname(__file__), 'thirdpart/auth/locale'), + # os.path.join(os.path.dirname(__file__), 'thirdpart/auth/locale'), ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -170,7 +170,7 @@ INSTALLED_APPS = ( ) AUTHENTICATION_BACKENDS = ( - 'auth.backends.ModelBackend', + 'seahub.base.accounts.AuthBackend', ) ACCOUNT_ACTIVATION_DAYS = 7 diff --git a/seahub/share/views.py b/seahub/share/views.py index 267a979350..985ffd3b7f 100644 --- a/seahub/share/views.py +++ b/seahub/share/views.py @@ -11,7 +11,6 @@ from django.shortcuts import render_to_response from django.template import Context, loader, RequestContext from django.utils.translation import ugettext as _ -from auth.decorators import login_required from django.contrib import messages from django.contrib.sites.models import Site, RequestSite from pysearpc import SearpcError @@ -26,6 +25,7 @@ from forms import RepoShareForm, FileLinkShareForm from models import AnonymousShare from settings import ANONYMOUS_SHARE_COOKIE_TIMEOUT from tokens import anon_share_token_generator +from seahub.auth.decorators import login_required from seahub.contacts.signals import mail_sended from seahub.share.models import FileShare from seahub.views import validate_owner, is_registered_user diff --git a/seahub/templates/registration/password_reset_email.html b/seahub/templates/registration/password_reset_email.html index a6cab04296..ddeca4f607 100644 --- a/seahub/templates/registration/password_reset_email.html +++ b/seahub/templates/registration/password_reset_email.html @@ -3,7 +3,7 @@ {% trans "Please go to the following page and choose a new password:" %} {% block reset_link %} -{{ protocol }}://{{ domain }}{% url auth.views.password_reset_confirm uidb36=uid, token=token %} +{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %} {% endblock %} {% trans "Your username, in case you've forgotten:" %} {{ user.username }} diff --git a/seahub/templates/user_add_email.html b/seahub/templates/user_add_email.html index d546cb1804..8c1be426b4 100644 --- a/seahub/templates/user_add_email.html +++ b/seahub/templates/user_add_email.html @@ -9,7 +9,7 @@ {% blocktrans %}Password: {{ password }}{% endblocktrans %} {% trans "Please go to the following page and log in:" %} -{{ protocol }}://{{ domain }}{% url auth_login %} +{{ protocol }}://{{ domain }}{% url 'auth_login' %} {% trans "Thanks for using our site!" %} diff --git a/seahub/views/__init__.py b/seahub/views/__init__.py index 9e2226037d..7b1276041e 100644 --- a/seahub/views/__init__.py +++ b/seahub/views/__init__.py @@ -25,9 +25,9 @@ from django.template.loader import render_to_string from django.utils.hashcompat import md5_constructor from django.utils.translation import ugettext as _ -from auth.decorators import login_required -from auth import login as auth_login -from auth import authenticate +from seahub.auth.decorators import login_required +from seahub.auth import login as auth_login +from seahub.auth import authenticate import seaserv from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_repos, get_emailusers, \ get_repo, get_commits, get_branches, is_valid_filename, remove_group_user,\ @@ -73,7 +73,7 @@ from seahub.utils import render_permission_error, render_error, list_to_string, get_dir_files_last_modified, show_delete_days, HtmlDiff, \ TRAFFIC_STATS_ENABLED, get_user_traffic_stat from seahub.utils.paginator import get_page_range -import seahub.settings +import seahub.settings as settings try: from seahub.settings import DOCUMENT_CONVERTOR_ROOT if DOCUMENT_CONVERTOR_ROOT[-1:] != '/': diff --git a/seahub/views/file.py b/seahub/views/file.py index b314ec9bce..38736c1020 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -27,7 +27,7 @@ from seaserv import list_dir_by_path, get_repo, web_get_access_token, \ get_org_groups_by_repo, seafserv_rpc, seafserv_threaded_rpc from pysearpc import SearpcError -from auth.decorators import login_required +from seahub.auth.decorators import login_required from seahub.base.decorators import repo_passwd_set_required from seahub.base.models import UuidObjidMap from seahub.contacts.models import Contact diff --git a/seahub/views/search.py b/seahub/views/search.py index 463fd6a831..c6ee4ef9a7 100644 --- a/seahub/views/search.py +++ b/seahub/views/search.py @@ -1,8 +1,7 @@ from django.shortcuts import render_to_response from django.template import RequestContext -from auth.decorators import login_required - +from seahub.auth.decorators import login_required from seahub.utils.search import search_file_by_name @login_required diff --git a/seahub/views/wiki.py b/seahub/views/wiki.py index f8475dff00..f9092a40e5 100644 --- a/seahub/views/wiki.py +++ b/seahub/views/wiki.py @@ -24,12 +24,10 @@ from django.utils.hashcompat import md5_constructor from django.utils.http import urlquote from django.utils.translation import ugettext as _ -from auth.decorators import login_required - import seaserv from pysearpc import SearpcError - +from seahub.auth.decorators import login_required from seahub.wiki.models import PersonalWiki, WikiDoesNotExist, WikiPageMissing from seahub.wiki import get_personal_wiki_page, get_personal_wiki_repo, \ convert_wiki_link, get_wiki_pages diff --git a/thirdpart/auth/backends.py b/thirdpart/auth/backends.py deleted file mode 100644 index d5b6082780..0000000000 --- a/thirdpart/auth/backends.py +++ /dev/null @@ -1,60 +0,0 @@ -from django.db import connection - -from seahub.base.accounts import User - -class ModelBackend(object): - """ - Authenticates against django.contrib.auth.models.User. - """ - supports_object_permissions = False - supports_anonymous_user = True - - # TODO: Model, login attribute name and password attribute name should be - # configurable. - def authenticate(self, username=None, password=None): - try: - user = User.objects.get(email=username) - if user.check_password(password): - return user - except User.DoesNotExist: - return None - - def get_group_permissions(self, user_obj): - """ - Returns a set of permission strings that this user has through his/her - groups. - """ - if not hasattr(user_obj, '_group_perm_cache'): - perms = Permission.objects.filter(group__user=user_obj - ).values_list('content_type__app_label', 'codename' - ).order_by() - user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms]) - return user_obj._group_perm_cache - - def get_all_permissions(self, user_obj): - if user_obj.is_anonymous(): - return set() - if not hasattr(user_obj, '_perm_cache'): - user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()]) - user_obj._perm_cache.update(self.get_group_permissions(user_obj)) - return user_obj._perm_cache - - def has_perm(self, user_obj, perm): - return perm in self.get_all_permissions(user_obj) - - def has_module_perms(self, user_obj, app_label): - """ - Returns True if user_obj has any permissions in the given app_label. - """ - for perm in self.get_all_permissions(user_obj): - if perm[:perm.index('.')] == app_label: - return True - return False - - def get_user(self, username): - try: - user = User.objects.get(email=username) - except User.DoesNotExist: - user = None - return user - diff --git a/thirdpart/auth/context_processors.py b/thirdpart/auth/context_processors.py deleted file mode 100644 index 87d8331ee6..0000000000 --- a/thirdpart/auth/context_processors.py +++ /dev/null @@ -1,33 +0,0 @@ -from django.core.context_processors import PermWrapper -from django.utils.functional import lazy, memoize, SimpleLazyObject -from django.contrib import messages - -def auth(request): - """ - Returns context variables required by apps that use Django's authentication - system. - - If there is no 'user' attribute in the request, uses AnonymousUser (from - django.contrib.auth). - """ - # If we access request.user, request.session is accessed, which results in - # 'Vary: Cookie' being sent in every request that uses this context - # processor, which can easily be every request on a site if - # TEMPLATE_CONTEXT_PROCESSORS has this context processor added. This kills - # the ability to cache. So, we carefully ensure these attributes are lazy. - # We don't use django.utils.functional.lazy() for User, because that - # requires knowing the class of the object we want to proxy, which could - # break with custom auth backends. LazyObject is a less complete but more - # flexible solution that is a good enough wrapper for 'User'. - def get_user(): - if hasattr(request, 'user'): - return request.user - else: - from django.contrib.auth.models import AnonymousUser - return AnonymousUser() - - return { - 'user': SimpleLazyObject(get_user), - 'messages': messages.get_messages(request), - 'perms': lazy(lambda: PermWrapper(get_user()), PermWrapper)(), - } diff --git a/thirdpart/auth/create_superuser.py b/thirdpart/auth/create_superuser.py deleted file mode 100644 index 7b58678b78..0000000000 --- a/thirdpart/auth/create_superuser.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -Create a superuser from the command line. Deprecated; use manage.py -createsuperuser instead. -""" - -if __name__ == "__main__": - from django.core.management import call_command - call_command("createsuperuser") diff --git a/thirdpart/auth/i18n.sh.template b/thirdpart/auth/i18n.sh.template deleted file mode 100755 index 9dcbe0d14a..0000000000 --- a/thirdpart/auth/i18n.sh.template +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -django-admin.py makemessages -l zh_CN -e py,html - -django-admin.py makemessages -d djangojs -l zh_CN - -django-admin.py compilemessages diff --git a/thirdpart/registration/auth_urls.py b/thirdpart/registration/auth_urls.py index 5e82184334..6e8c3944a6 100644 --- a/thirdpart/registration/auth_urls.py +++ b/thirdpart/registration/auth_urls.py @@ -25,7 +25,7 @@ consult a specific backend's documentation for details. from django.conf.urls.defaults import * -from auth import views as auth_views +from seahub.auth import views as auth_views urlpatterns = patterns('', url(r'^login/$',