Skip to content

Commit ecb529c

Browse files
authored
Merge pull request #6 from lumpy72006/password-toggle
password visibility toggle
2 parents 4dc99f2 + bfbb654 commit ecb529c

5 files changed

Lines changed: 65 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Password visibility toggle on login page (dashboard#46)
13+
814
## [1.3.2] - 2025-12-11
915

1016
### Fixed

src/adminui/templates/auth/login.html

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{% extends "raw_base.html" %}
22

3+
{# import the macro file to use the password function #}
4+
{% from "macros.html" import password_input %}
5+
36
{% block theme %}light{% endblock %}
47
{% block title %}Sign into Kiwix Admin{% endblock %}
58

@@ -56,6 +59,8 @@
5659
--bs-link-hover-color-rgb: 227,130,14;
5760
text-decoration: none;
5861
}
62+
63+
.password-toggle, .password-toggle:hover, .password-toggle:focus { border-color: var(--bs-border-color); }
5964
</style>
6065
{% endblock %}
6166

@@ -71,15 +76,35 @@
7176
<label class="form-label" for="username">Username</label>
7277
<input type="text" class="form-control{% if is_incorrect %} is-invalid{% endif %}" name="username" placeholder="Usually “admin”" />
7378
</div>
74-
<div class="mb-3">
75-
<label class="form-label" for="password">Password</label>
76-
<input type="password" class="form-control{% if is_incorrect %} is-invalid{% endif %}" name="password" aria-describedby="credentialsFeedback">
77-
{% if is_incorrect and message_content %}<div id="credentialsFeedback" class="invalid-feedback">{{ message_content }}</div>{% endif %}
78-
</div>
79+
{{ password_input(name="password", error=message_content if is_incorrect else None) }}
7980
<div class="d-flex flex-row-reverse">
8081
<input type="submit" class="btn btn-primary" value="Sign-in" />
8182
</div>
8283
</form>
8384
</div>
8485
<div class="mt-1 mb-1 p-3"><a class="returnlink" href="http://{{ ctx.fqdn }}"><i class="fa-solid fa-arrow-left"></i> Return to the Hotspot</a></div>
8586
{% endblock %}
87+
88+
{% block javascript %}
89+
<script type="text/javascript">
90+
function run() {
91+
live('.password-toggle', 'click', function (elem, event) {
92+
// Find the input that lives in the same group as this button
93+
const input = elem.parentElement.querySelector('.password-input');
94+
const iconShow = elem.querySelector('.icon-show');
95+
const iconHide = elem.querySelector('.icon-hide');
96+
97+
if (input.getAttribute('type') === 'password') {
98+
input.setAttribute('type', 'text');
99+
iconShow.style.display = 'none';
100+
iconHide.style.display = 'block';
101+
} else {
102+
input.setAttribute('type', 'password');
103+
iconShow.style.display = 'block';
104+
iconHide.style.display = 'none';
105+
}
106+
});
107+
}
108+
</script>
109+
</script>
110+
{% endblock %}
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

src/adminui/templates/macros.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% macro password_input(name, label="Password", placeholder="", error=None) %}
2+
<div class="mb-3">
3+
<label class="form-label" for="{{ name }}">{{ label }}</label>
4+
<div class="input-group">
5+
<input type="password"
6+
class="form-control password-input {% if error %}is-invalid{% endif %}"
7+
name="{{ name }}"
8+
id="{{ name }}"
9+
placeholder="{{ placeholder }}"
10+
{% if error %}aria-describedby="{{ name }}Feedback"{% endif %}>
11+
12+
<button class="btn password-toggle" type="button">
13+
{% include "icons/eye.svg" %}
14+
{% include "icons/eye-slash.svg" %}
15+
</button>
16+
17+
{% if error %}<div id="{{ name }}Feedback" class="invalid-feedback">{{ error }}</div>{% endif %}
18+
</div>
19+
</div>
20+
{% endmacro %}

0 commit comments

Comments
 (0)