forked from django/django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #34429 -- Allowed setting unusable passwords for users in the a…
…uth forms. Co-authored-by: Natalia <[email protected]>
- Loading branch information
Showing
12 changed files
with
581 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -328,6 +328,7 @@ answer newbie questions, and generally made Django that much better: | |
Eugene Lazutkin <http://lazutkin.com/blog/> | ||
Evan Grim <https://github.com/egrim> | ||
Fabian Büchler <[email protected]> | ||
Fabian Braun <[email protected]> | ||
Fabrice Aneche <[email protected]> | ||
Faishal Manzar <https://github.com/faishal882> | ||
Farhaan Bukhsh <[email protected]> | ||
|
19 changes: 19 additions & 0 deletions
19
django/contrib/admin/static/admin/css/unusable_password_field.css
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Hide warnings fields if usable password is selected */ | ||
form:has(#id_usable_password input[value="true"]:checked) .messagelist { | ||
display: none; | ||
} | ||
|
||
/* Hide password fields if unusable password is selected */ | ||
form:has(#id_usable_password input[value="false"]:checked) .field-password1, | ||
form:has(#id_usable_password input[value="false"]:checked) .field-password2 { | ||
display: none; | ||
} | ||
|
||
/* Select appropriate submit button */ | ||
form:has(#id_usable_password input[value="true"]:checked) input[type="submit"].unset-password { | ||
display: none; | ||
} | ||
|
||
form:has(#id_usable_password input[value="false"]:checked) input[type="submit"].set-password { | ||
display: none; | ||
} |
29 changes: 29 additions & 0 deletions
29
django/contrib/admin/static/admin/js/unusable_password_field.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
// Fallback JS for browsers which do not support :has selector used in | ||
// admin/css/unusable_password_fields.css | ||
// Remove file once all supported browsers support :has selector | ||
try { | ||
// If browser does not support :has selector this will raise an error | ||
document.querySelector("form:has(input)"); | ||
} catch (error) { | ||
console.log("Defaulting to javascript for usable password form management: " + error); | ||
// JS replacement for unsupported :has selector | ||
document.querySelectorAll('input[name="usable_password"]').forEach(option => { | ||
option.addEventListener('change', function() { | ||
const usablePassword = (this.value === "true" ? this.checked : !this.checked); | ||
const submit1 = document.querySelector('input[type="submit"].set-password'); | ||
const submit2 = document.querySelector('input[type="submit"].unset-password'); | ||
const messages = document.querySelector('#id_unusable_warning'); | ||
document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword; | ||
document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword; | ||
if (messages) { | ||
messages.hidden = usablePassword; | ||
} | ||
if (submit1 && submit2) { | ||
submit1.hidden = !usablePassword; | ||
submit2.hidden = usablePassword; | ||
} | ||
}); | ||
option.dispatchEvent(new Event('change')); | ||
}); | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.