taiga-contrib-ldap-auth
taiga-contrib-ldap-auth copied to clipboard
Login failed at the second time
When i login to taiga successfully(with ldap user/password), then l logout. but when i try to login again, the server returned 500 error code, please find the details below:
api response: {"error": "Server application error"}
the backend log:
MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Django] ERROR (EXTERNAL IP): Internal Server Error: /api/v1/auth From: [email protected] To: [email protected] Date: Tue, 04 Aug 2015 10:48:43 -0000 Message-ID: [email protected]
Internal Server Error: /api/v1/auth Traceback (most recent call last): File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py", line 41, in ldap_register user = user_model.objects.get(username=username) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 357, in get self.model._meta.object_name) taiga.users.models.DoesNotExist: User matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) psycopg2.IntegrityError: duplicate key value violates unique constraint "users_user_email_6a1bbd04b7b1e907_uniq" DETAIL: Key (email)=([email protected]) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/core/handlers/base.py", line 111, in get_response response = wrapped_callback(request, _callback_args, *_callback_kwargs) File "/home/taiga/taiga-back/taiga/base/api/viewsets.py", line 81, in view return self.dispatch(request, _args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(_args, *_kwargs) File "/home/taiga/taiga-back/taiga/base/api/views.py", line 420, in dispatch response = self.handle_exception(exc) File "/home/taiga/taiga-back/taiga/base/api/views.py", line 417, in dispatch response = handler(request, _args, *_kwargs) File "/home/taiga/taiga-back/taiga/auth/api.py", line 142, in create data = auth_plugins[login_type]'login_func' File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py", line 58, in ldap_login_func user = ldap_register(username=username, email=email, full_name=full_name) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/transaction.py", line 394, in inner return func(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py", line 47, in ldap_register full_name=full_name) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 372, in create obj.save(force_insert=True, using=self.db) File "/home/taiga/taiga-back/taiga/users/models.py", line 162, in save super().save(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 589, in save force_update=force_update, update_fields=update_fields) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 617, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 698, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/base.py", line 731, in _do_insert using=using, raw=raw) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, *_kwargs) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/query.py", line 921, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 921, in execute_sql cursor.execute(sql, params) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/utils.py", line 94, in exit six.reraise(dj_exc_type, dj_exc_value, traceback) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise raise value.with_traceback(tb) File "/home/taiga/.virtualenvs/taiga/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) django.db.utils.IntegrityError: duplicate key value violates unique constraint "users_user_email_6a1bbd04b7b1e907_uniq" DETAIL: Key (email)=([email protected]) already exists.
Request repr():
<WSGIRequest
path:/api/v1/auth,
GET:<QueryDict: {}>,
POST:
'wsgi.version': (1, 0)}>
i found why the error occurred. because the prefix of email address contain a '.' character, but when the first login succeed the saved username in the database lost the '.' character, for example :
the saved user info:
email username [email protected] xxyy
but i don't known how to fix it, any one can help me?
may be this is a bug of taiga?
I have the same issue.
A quick fix is to correct the username from the taiga db.
SELECT id,username FROM users_user;
update users_user set username='user.with.dot' where id=XX;
@Tetelu yes, this is what i do. but we need to do this for every user. Thanks for your share!
@rawbean Well I took some time and made some local fixes in ./.virtualenvs/taiga/lib/python3.4/site-packages/taiga_contrib_ldap_auth/services.py
# Create a new user
# emails in AD have upper and lower case and it didn't match with what was in DB. I made it lower case
email=email.lower()
# slugify_uniquely - deleted the dot, so I didn't use it anymore, just replaced it with username
username_unique = slugify_uniquely(username, user_model, slugfield="username")
user = user_model.objects.create(email=email,
username=username,
full_name=full_name)
I had to do the same @Tetelu did. @Tetelu why don't you create a Pull Request on this. I could create it if you like. :)
@pjcuadra @Tetelu please create a pull request if you guys already have a solution. Thanks~ :)
Thanks @Tetelu ! It helps a lot.
Don't forget to drop the oraginal DB "taiga" and recreate it. Follow this or simply excute ./ regenerate.sh in /home/taiga/taiga-back.
Hi,
I had the same problem, the first login is ok but failed after a logout. This is because my login in ldap contain a character "." and the fucntion slugify_uniquely delete the dot when the user is registred. To fix this, I change in file services.py the line : user = user_model.objects.get(username=username)
by : user = user_model.objects.get(username=username.replace('.', ''))
It works fine for me.
Same issue here, our AD login look like [email protected], hence first connection & user creation OK, next one KO.
Went with @omauger solution.
This issue could be closed in favour to issue #45, and PR #43.
Hi! Welcome to 2019. This is still a bug.
@filhocf #45 is a duplication of this one -- so if anything, close #45