-
Couldn't load subscription status.
- Fork 294
Allow more advanced, custom password logic #115
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,8 @@ def change_password(): | |
| db_adapter = user_manager.db_adapter | ||
|
|
||
| # Initialize form | ||
| form = user_manager.change_password_form(request.form) | ||
| form = user_manager.change_password_form(request.form, user=current_user) | ||
|
|
||
| form.next.data = request.args.get('next', _endpoint_url(user_manager.after_change_password_endpoint)) # Place ?next query param in next form field | ||
|
|
||
| # Process valid POST | ||
|
|
@@ -580,7 +581,7 @@ def reset_password(token): | |
| user_email.confirmed_at = datetime.utcnow() | ||
|
|
||
| # Initialize form | ||
| form = user_manager.reset_password_form(request.form) | ||
| form = user_manager.reset_password_form(request.form, user=user) | ||
|
|
||
| # Process valid POST | ||
| if request.method=='POST' and form.validate(): | ||
|
|
@@ -590,9 +591,7 @@ def reset_password(token): | |
|
|
||
| # Change password | ||
| hashed_password = user_manager.hash_password(form.new_password.data) | ||
| user_auth = user.user_auth if db_adapter.UserAuthClass and hasattr(user, 'user_auth') else user | ||
| db_adapter.update_object(user_auth, password=hashed_password) | ||
| db_adapter.commit() | ||
| user_manager.update_password(user, hashed_password) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change also minimizes the assumption that |
||
|
|
||
| # Send 'password_changed' email | ||
| if user_manager.enable_email and user_manager.send_password_changed_email: | ||
|
|
@@ -733,5 +732,3 @@ def _endpoint_url(endpoint): | |
| if endpoint: | ||
| url = url_for(endpoint) | ||
| return url | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change minimizes the assumption that
passwordis a field on the user entity. In reality,verify_passwordshould never be returningTrueif the user has no password at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For heterogeneous authorization systems, some users do not have a local
password(such as those users relying on an external OAuth server). Without a defined password, anattribute erroris raised when trying to passself.password.dataintoverify_password- thus mandating the extra check.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.password.datais on the form itself. I don't know how that could fail unless you're overriding thepasswordinput on the form, in which case you can override thevalidatemethod as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pbugni I see now that you added that check. I'm confused why you needed it. With my change (and the way it was before), you can always check
user.passwordwithin the body ofuser_manager.verify_passwordif you override that method on theUserManager.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
self.passworddoes not exist, then you have clearly changed the original form class and it would make sense that you need to also override the form'svalidatemethod to accomodate your changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@3noch - Your assertions are correct about form data - the problem is that when a user doesn't have a password and then they attempt to log in - an error is raised in the call to user_manager.verify_password. I'd forgotten the details when replying earlier today, but it's easy to reproduce - clear the db password for a user and attempt to log in - at the bottom of the error stack:
The point of this check is clear - if the user doesn't have a password, don't bother trying to verify. Yes, you could alternatively patch the lower level checks, but this seemed like the clean work around to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can re-add that check to the default implementation of
verify_password. Do you think that would solve your case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - that'd be great. I can test your branch when it's ready. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pbugni Ok, I added that check to
verify_password.