Hello,
The restructuring of the folder structure in the project between my
patch submission
and now changed significantly. So I believe it is only a problem of paths.
I'm attaching here the patch with updated paths.
- ./auth is now ./pootle/auth, etc
The path for the ldap_backend is now wrong also. Just add "pootle.".
Good testing,
Flávio Martins
2009/5/31 Amos Jeffries <[email protected]>:
> Flávio Martins wrote:
>>
>> Hi,
>>
>> 2009/4/10 Amos Jeffries <[email protected]>:
>>>
>>> Is there a way to (optinally) cleanly erase the obsolete info from the
>>> prefs
>>> file as it goes? That would help migrating admin know where things are
>>> during this process which might take many weeks/months.
>>>
>>> AYJ
>>>
>>>
>>
>> Amos, the new attached patch adds that ability.
>> I yanked the file saving from users.py from Pootle 1.2.1.
>>>
>>> From my tests it seems to work great.
>>
>> Tell me what you think.
>>
>> Flávio Martins
>
> Finally getting to test this out.
>
> After making sure the new pootle runs properly etc.
> I've added that patch, and the login results change from can't login (with
> details from old users.prefs) to an error loading the auth backend.
>
> The URL below is public, so if you want access go ahead. (If you get the CDN
> non-exist page it just means the testing PootleServer has died for some
> reason. Seems to die during the morning log rotations)
>
> Environment:
>
> Request Method: POST
> Request URL: http://pootle.treenet.co.nz/login.html
> Django Version: 1.0.2 final
> Python Version: 2.5.4
> Installed Applications:
> ['django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.admin',
> 'pootle_app',
> 'pootle_misc',
> 'pootle_store']
> Installed Middleware:
> ('pootle_misc.middleware.baseurl.BaseUrlMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.middleware.transaction.TransactionMiddleware',
> 'pootle.middleware.check_cookies.CheckCookieMiddleware',
> 'pootle.middleware.locale.LocaleMiddleware',
> 'pootle.middleware.profile.ProfilerMiddleware')
>
>
> Traceback:
> File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py" in
> get_response
> 86. response = callback(request, *callback_args,
> **callback_kwargs)
> File
> "/home/www/treehouse/projects/pootle/Pootle/local_apps/pootle_app/views/index/login.py"
> in view
> 51. if form.is_valid():
> File "/usr/lib/pymodules/python2.5/django/forms/forms.py" in is_valid
> 120. return self.is_bound and not bool(self.errors)
> File "/usr/lib/pymodules/python2.5/django/forms/forms.py" in _get_errors
> 111. self.full_clean()
> File "/usr/lib/pymodules/python2.5/django/forms/forms.py" in full_clean
> 241. self.cleaned_data = self.clean()
> File "/usr/lib/pymodules/python2.5/django/contrib/auth/forms.py" in clean
> 78. self.user_cache = authenticate(username=username,
> password=password)
> File "/usr/lib/pymodules/python2.5/django/contrib/auth/__init__.py" in
> authenticate
> 34. for backend in get_backends():
> File "/usr/lib/pymodules/python2.5/django/contrib/auth/__init__.py" in
> get_backends
> 27. backends.append(load_backend(backend_path))
> File "/usr/lib/pymodules/python2.5/django/contrib/auth/__init__.py" in
> load_backend
> 14. raise ImproperlyConfigured, 'Error importing authentication
> backend %s: "%s"' % (module, e)
>
> Exception Type: ImproperlyConfigured at /login.html
> Exception Value: Error importing authentication backend auth.prefs_backend:
> "No module named auth.prefs_backend"
>
Index: pootle/auth/prefs_backend.py
===================================================================
--- pootle/auth/prefs_backend.py (revision 0)
+++ pootle/auth/prefs_backend.py (revision 0)
@@ -0,0 +1,67 @@
+from django.conf import settings
+from django.contrib.auth.models import User
+from django.forms.fields import email_re
+from jToolkit import prefs
+from jToolkit.web import session
+
+class PrefsBackend(object):
+ """
+ Authenticate against a Pootle installation users.prefs file.
+
+ Uses the login name and a hash of the password.
+
+ This authentication backend can be used for migration purposes
+ since it adds the authenticated user to the database.
+
+ """
+
+ def saveprefs(self, prefsparser):
+ """saves changed preferences back to disk"""
+ # TODO: this is a hack, fix it up nicely :-)
+ # Yanked from users.py with some changes
+ prefsfile = prefsparser.__root__.__dict__["_setvalue"].im_self
+ prefsfile.savefile()
+
+ def check_password(self, raw_password, enc_password):
+ return session.md5hexdigest(raw_password) == enc_password
+
+ def is_valid_email(self, email):
+ return True if email_re.match(email) else False
+
+ def authenticate(self, username=None, password=None):
+ p = prefs.PrefsParser()
+ p.parsefile(settings.USERSPREFSFILE)
+ login_valid = p.__hasattr__(username)
+ if login_valid:
+ if p.__getattr__(username).__hasattr__('passwdhash'):
+ pwd_valid = self.check_password(password,
+ p.__getattr__(username).__getattr__('passwdhash'))
+ if pwd_valid:
+ # User/Password combo matches. We will check if
+ # the user exists, and if it does not we will add him.
+ try:
+ user = User.objects.get(username=username)
+ except User.DoesNotExist:
+ # Create a new user. Note that we can set password
+ # to anything. We will set the password to be the
+ # same as the one in the prefs since the hash matches.
+ email = ''
+ if p.__getattr__(username).__hasattr__('email'):
+ email = p.__getattr__(username).__getattr__('email')
+ if not self.is_valid_email(email):
+ email = '[email protected]'
+ user = User.objects.create_user(username, email, password)
+ # TODO: We can migrate other attributes here
+ user.save()
+ # We can remove the user from users.prefs now.
+ if settings.USERSPREFS_CLEANUP:
+ p.removekey(username)
+ self.saveprefs(p)
+ return user
+ return None
+
+ def get_user(self, user_id):
+ try:
+ return User.objects.get(pk=user_id)
+ except User.DoesNotExist:
+ return None
Index: pootle/settings.py
===================================================================
--- pootle/settings.py (revision 11248)
+++ pootle/settings.py (working copy)
@@ -150,6 +150,8 @@
PREFSFILE = pootle_home('pootle.prefs')
+USERSPREFSFILE = pootle_home('users.prefs')
+
PODIRECTORY = pootle_home('po')
# Use the commented definition to authenticate first with Mozilla's LDAP system and then to fall back
@@ -157,6 +159,12 @@
#AUTHENTICATION_BACKENDS = ('auth.ldap_backend.LdapBackend', 'django.contrib.auth.backends.ModelBackend',)
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
+# Use this commented definition if you want to accept the login information from a previous version of Pootle.
+# The user information will be migrated from the old users.prefs file to the database.
+#AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend', 'pootle.auth.prefs_backend.PrefsBackend',)
+# If you set the following True, the users migrated using the above backend will be removed from the users.prefs.
+#USERSPREFS_CLEANUP = False
+
# LDAP Setup
# The LDAP server. Format: protocol://hostname:port
AUTH_LDAP_SERVER = ''
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
Translate-pootle mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/translate-pootle