Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User matching query does not exist. #100

Open
ksvoboda opened this issue Jun 17, 2020 · 6 comments
Open

User matching query does not exist. #100

ksvoboda opened this issue Jun 17, 2020 · 6 comments
Assignees

Comments

@ksvoboda
Copy link

Hi,
So, I am trying to get this working, but one thing is not working for me. When I reset password, I get response "OK", but when I try to login I get error: "User matching query does not exist."
I really can't figure out why I get this error. I think I did everything right by the guide, only difference is that I don't send email, but I only print it in console.
It looks like it make the user unaccesible, I still see the user in django admin.
Let me know if/what code you need.

Has anyone any idea?
Thanks

@jamehii
Copy link

jamehii commented Jun 28, 2020

That's because your User model now has a new related field "password_reset_tokens" added.

I believe all your pre-existing users in your database were created before you using this package, those users don't have the related field included. Hence, when you are querying for the users from database, no user is matching to your current new User model with the related field.

To solve this, probably deleting all your pre-existing users in database and start fresh would be the easier way ONLY if you don't wanna keep those users anymore.

@ksvoboda
Copy link
Author

Thanks for your reply, but I actually deleted the whole database and migrated again before using it. I did it multiple times, but it didn’t help.

Any other idea please? Thanks

@jamehii
Copy link

jamehii commented Jun 29, 2020

@ksvoboda

There are 2 ways:

1st way
Unregister your User model in the admin, then register again

If that doesn't work, then 2nd way:

Did you explicitly create ResetPasswordToken and link it to each of your "User" model instance ?
If you didn't, that probably would cause login issue.

You can do it with "post_save" signal:

from django.db.models.signals import post_save
from django.dispatch import receiver
from django_rest_passwordreset.models import ResetPasswordToken

@reciever(post_save, sender=settings.AUTH_USER_MODEL)
on_user_post_save(sender, instance, created, **kwargs):
    if created:
        # Only do this once on each creation of user instance
        ResetPasswordToken.objects.create(user=instance)

Again, you might need to clean up your database and migrate again. Then you can try to login see if it works.

@ksvoboda
Copy link
Author

ksvoboda commented Jun 29, 2020

So, if I understand it right, I just deleted User model in admin.py and then put it back. That didn't help.
And the second way I just pasted your code in signals.py (I think you forgot def before on_user_post_save), still getting same error. Also VSCode is warning me that
Class 'ResetPasswordToken' has no 'objects' member

But now, out of nowhere I get different error, now in console when trying to run the app.

File "/Users/krystofsvoboda/Documents/GitHub/project-tracker-api/myvenv/lib/python3.7/site-packages/django/core/urlresolvers.py", line 320
  except Resolver404, e:
                    ^
SyntaxError: invalid syntax

I wasn't able to fing any working solution on Google to this problem.

Thanks

@jamehii
Copy link

jamehii commented Jun 29, 2020

To unregister meaning in your admin.py, you will will have something below:

#unregister first
admin.site.unregister(YourUserModel)

#then register again
admin.site.register(YourUserModel)

@ghost ghost assigned anx-cbenke Jul 30, 2020
@anx-cbenke
Copy link
Contributor

@ksvoboda have you been able to resolve this issue with @jamehii's help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants