Skip to content

Commit

Permalink
Patch
Browse files Browse the repository at this point in the history
Better password changer
You don't need to type username when change the password now
fix redirect code
  • Loading branch information
EndermanPC committed May 12, 2024
1 parent a7efcb7 commit 9ac03cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 2 additions & 4 deletions app/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def login_form():
password = request.form.get('password')

login = get_user_authentication(cursor, username, password)

if User is None:
User = gettext('Account')

Expand Down Expand Up @@ -99,7 +99,6 @@ def login_form():
if username is not None or password is not None or login is not None:
return redirect(
'/account/me',
SITE_KEY=os.getenv('RECAPTCHA_SITE_KEY')
)
else:
return render_template(
Expand Down Expand Up @@ -207,7 +206,6 @@ def myaccount_form():
if username is None or password is None or login is None:
return redirect(
'/account/login',
SITE_KEY=os.getenv('RECAPTCHA_SITE_KEY')
)
else:
return render_template(
Expand All @@ -230,7 +228,7 @@ def myaccount_form():
if result['success']:
old_password = request.form.get('oldpassword')
new_password = request.form.get('newpassword')
username = request.form.get('username')
username = request.cookies.get('USERNAME')

login = get_user_authentication(cursor, username, old_password)

Expand Down
17 changes: 10 additions & 7 deletions app/frontend/account/me.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<form action="/account/me" method="POST">
<input type="password" name="oldpassword" id="oldpassword" placeholder="{% trans %}Old password{% endtrans %}"/><br><br>

<input type="password" name="newpassword" id="newpassword" placeholder="{% trans %}New password{% endtrans %}"/><br><br>
<input type="password" name="newpassword" id="newpassword" placeholder="{% trans %}New password{% endtrans %}"/><br>

<input type="text" name="username" id="username" placeholder="{% trans %}Username{% endtrans %}"/><br><br>
<input type="password" name="password_reinput" id="password_reinput" placeholder="{% trans %}Re-enter the password{% endtrans %}"/><br><br>

<div style="display: flex; justify-content: center;">
<div class="g-recaptcha" data-sitekey="{{SITE_KEY}}"></div>
Expand All @@ -32,9 +32,9 @@
</form><br>

<script>
var usernameInput = document.getElementById('username');
var oldpasswordInput = document.getElementById('oldpassword');
var newpasswordInput = document.getElementById('newpassword');
var repasswordInput = document.getElementById('password_reinput');
var changeButton = document.getElementById('change_button');

changeButton.disabled = true;
Expand All @@ -59,13 +59,16 @@
}
});

usernameInput.addEventListener('input', function() {
if (usernameInput.value != "") {
repasswordInput.addEventListener('input', function() {
if (repasswordInput.value == "") {
changeButton.disabled = true;
repasswordInput.style.border = "2px solid red";
} else if (repasswordInput.value == newpasswordInput.value) {
changeButton.disabled = false;
usernameInput.style.border = "2px solid green";
repasswordInput.style.border = "2px solid green";
} else {
changeButton.disabled = true;
usernameInput.style.border = "2px solid red";
repasswordInput.style.border = "2px solid red";
}
});
</script>
Expand Down

0 comments on commit 9ac03cc

Please sign in to comment.