Email Login, and more generally issues with non-Mayan Apps used by Mayan

25 views
Skip to first unread message

Devin Ceartas

unread,
Jul 24, 2014, 11:51:53 AM7/24/14
to mayan...@googlegroups.com
I've run across something which I needed to tweak in order to get working. 

With my level of experience, I'd say the chances are good I haven't tweaked it in the correct place. 

It seems as if this issue is wholly the purview of other apps Mayan makes use of, and not Mayan code per se. I could be wrong about this, of course. But generally speaking, what is the best way to deal with issues like this? The issue just posted to GitHub at https://github.com/mayan-edms/mayan-edms/issues/23#issuecomment-50024998 seems as if it might fit into this category as well. With an issue arising from the interaction between two non-Mayan apps used by Mayan-EDMS, how should I track down where the issue should be resolved, and how do I track down the appropriate place to suggest my patch? 

The issue: 

I want to use email addresses instead of usernames. There is mention of a way to do this around line 423 in docs/topics/settings.rst, as well as a fairly straight-forward "how to" in docs/releases/0.8.2.rst of the Mayan-EDMS documents. 

Problem is doing that causes an exception. 

The issue is that around line 180 of django/contrib/auth/forms.py the code expects a "username" field but using the suggested settings (to use emails instead of username) seems to produce a form lacking a "username" field. The short version of the exception produced is: 

KeyError at /login/

u'username'
Request Method:GET
Request URL:http://54.88.239.64/login/
Django Version:1.6.5
Exception Type:KeyError
Exception Value:
u'username'
Exception Location:/home/ubuntu/venv/lib/python2.7/site-packages/django/contrib/auth/forms.py in __init__, line 180
Python Executable:/usr/bin/python
Python Version:2.7.6
Python Path:
['/var/mayan-edms',
 '/var/mayan-edms/mayan',
 '/home/ubuntu/venv/lib/python2.7/site-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/var/mayan-edms/mayan/apps',
 '/home/ubuntu/venv/lib/python2.7/site-packages/git/ext/gitdb',
 '/home/ubuntu/venv/lib/python2.7/site-packages/gitdb/ext/async',
 '/home/ubuntu/venv/lib/python2.7/site-packages/gitdb/ext/smmap']
Server time:Thu, 24 Jul 2014 15:47:35 +0000



A patch which appears obvious to me but may be naive is: 

--- /home/ubuntu/venv/lib/python2.7/site-packages/django/contrib/auth/forms.py~ 2014-07-13 17:57:21.299758695 +0000
+++ /home/ubuntu/venv/lib/python2.7/site-packages/django/contrib/auth/forms.py 2014-07-23 14:47:18.866324000 +0000
@@ -177,7 +177,7 @@
         # Set the label for the "username" field.
         UserModel = get_user_model()
         self.username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD)
-        if self.fields['username'].label is None:
+        if 'username' in self.fields and self.fields['username'].label is None:
             self.fields['username'].label = capfirst(self.username_field.verbose_name)

Would welcome any feedback. 

-- devin

Roberto Rosario

unread,
Jul 27, 2014, 5:11:01 PM7/27/14
to mayan...@googlegroups.com
My guess is that this is related to the User model updates (Mayan went from Django 1.3 to Django 1.6) so hopefully a quick update in how Mayan does the authentication will fix it.

The patch included goes directly against Django so that is something that cannot be included in Mayan itself.

Devin Ceartas

unread,
Jul 27, 2014, 5:26:18 PM7/27/14
to mayan...@googlegroups.com
Thanks. I have started looking at the pages about the User model change you pointed out in the other thread. 

It is confusing to me -- if Django made this change, why are other parts of Django not updated to be consistent? I think the file I patched was under the "/contrib/" directory, so maybe it's not core Django? Is there any hope of tracking down the correct place for the patch and submitting it there, or will I just need to maintain a private patch set? If there is a patch set for things Mayan suggests are possible, we may need a place to collect those? 

Or are you suggesting we can somehow side-step this issue by changing something about Mayan? It looked to me like all the authentication was pretty much handled outside of the Mayan code? 

devin
--
Use unique, strong passwords! https://www.nacredata.com/password.php








On Jul 27, 2014, at 9:11 PM, Roberto Rosario <roberto.rosa...@gmail.com> wrote:

My guess is that this is related to the User model updates (Mayan went from Django 1.3 to Django 1.6) so hopefully a quick update in how Mayan does the authentication will fix it.

The patch included goes directly against Django so that is something that cannot be included in Mayan itself.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Mayan EDMS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mayan-edms/q1sh1IVzmuw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mayan-edms+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roberto Rosario

unread,
Jul 28, 2014, 3:42:17 AM7/28/14
to mayan...@googlegroups.com
Fixed: https://github.com/mayan-edms/mayan-edms/commit/0d3ce55f390a7c390a946b5d78c334ec590fdcc1

Previously the EmailAuthenticationForm form inherited from Django's AuthenticationForm, which is inherently made to work only with username/password login combination and was more or less being monkey-patched (https://en.wikipedia.org/wiki/Monkey_patch) (https://stackoverflow.com/questions/5626193/what-is-monkey-patch) for email/password login. At the end this approach fell victim to this:

"They can lead to upgrade problems when the patch makes assumptions about the patched object that are no longer true; if the product you have changed changes with a new release it may very well break your patch."
To unsubscribe from this group and all its topics, send an email to mayan-edms+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages