-
Notifications
You must be signed in to change notification settings - Fork 295
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
Open
3noch
wants to merge
1
commit into
lingthio:master
Choose a base branch
from
level12:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.