Skip to content

Commit 02aa7be

Browse files
committed
password change refresh
1 parent cd2a899 commit 02aa7be

File tree

7 files changed

+97
-16
lines changed

7 files changed

+97
-16
lines changed

blueprints/auth/routes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ def change_password():
114114
return redirect(url_for('auth.login'))
115115

116116
if request.method == 'POST':
117+
full_name = request.form.get('full_name')
117118
new_password = request.form.get('new_password')
118119
confirm_password = request.form.get('confirm_password')
119120

120121
if new_password != confirm_password:
121122
flash('Passwords do not match', 'error')
122123
return render_template('change_password.html')
123124

125+
user.full_name = full_name
126+
_ensure_username_from_full_name(user, db.session)
127+
124128
user.password_hash = generate_password_hash(new_password)
125129
user.is_first_login = False
126130
db.session.commit()

blueprints/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ def _extract_first_name(full_name):
2323
full_name = full_name.strip()
2424
if not full_name:
2525
return None
26-
return full_name.split()[0][:64]
26+
27+
parts = full_name.split()
28+
if not parts:
29+
return None
30+
31+
if len(parts) > 1 and parts[0].lower() == 'mulla':
32+
return parts[1][:64]
33+
34+
return parts[0][:64]
2735

2836
def _make_unique_username(base, exclude_user_id=None):
2937
base = (base or '').strip()

static/script.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ function initializeApp() {
1111
// Initialize form validation
1212
initializeFormValidation();
1313

14+
// Initialize silent password matching
15+
initializeSilentPasswordMatching();
16+
1417
// Initialize offline functionality
1518
initializeOfflineSupport();
1619

@@ -27,6 +30,40 @@ function initializeApp() {
2730
saveCurrentPage();
2831
}
2932

33+
function initializeSilentPasswordMatching() {
34+
const newPassword = document.getElementById('new_password');
35+
const confirmPassword = document.getElementById('confirm_password');
36+
const statusDiv = document.getElementById('passwordMatchStatus');
37+
38+
if (!newPassword || !confirmPassword || !statusDiv) return;
39+
40+
function updateStatus() {
41+
const val1 = newPassword.value;
42+
const val2 = confirmPassword.value;
43+
44+
if (!val1 && !val2) {
45+
statusDiv.style.display = 'none';
46+
return;
47+
}
48+
49+
statusDiv.style.display = 'block';
50+
if (val1 === val2 && val1 !== '') {
51+
statusDiv.textContent = '✓ Passwords match';
52+
statusDiv.className = 'small mt-2 text-center py-1 rounded bg-success-subtle text-success border border-success';
53+
statusDiv.style.backgroundColor = '#d1e7dd';
54+
} else if (val2 === '') {
55+
statusDiv.style.display = 'none';
56+
} else {
57+
statusDiv.textContent = '✗ Passwords do not match';
58+
statusDiv.className = 'small mt-2 text-center py-1 rounded bg-danger-subtle text-danger border border-danger';
59+
statusDiv.style.backgroundColor = '#f8d7da';
60+
}
61+
}
62+
63+
newPassword.addEventListener('input', updateStatus);
64+
confirmPassword.addEventListener('input', updateStatus);
65+
}
66+
3067
// Theme Management
3168
function loadTheme() {
3269
const savedTheme = localStorage.getItem('theme');
@@ -68,7 +105,7 @@ function initializeFormValidation() {
68105
// Password confirmation validation
69106
const passwordInputs = document.querySelectorAll('input[name="confirm_password"]');
70107
passwordInputs.forEach(input => {
71-
input.addEventListener('input', validatePasswordMatch);
108+
// Validation moved to form submission to prevent premature error messages
72109
});
73110

74111
// Form submission validation
@@ -99,8 +136,19 @@ function validateEmailRealTime(event) {
99136
}
100137

101138
function validatePasswordMatch(event) {
139+
if (!event || !event.target) return true;
140+
102141
const confirmPassword = event.target.value;
103-
const password = document.querySelector('input[name="password"]').value;
142+
const passwordElement = document.querySelector('input[name="password"]') ||
143+
document.querySelector('input[name="new_password"]') ||
144+
document.getElementById('new_password');
145+
146+
if (!passwordElement) {
147+
console.warn('Password element not found for matching');
148+
return true;
149+
}
150+
151+
const password = passwordElement.value || '';
104152

105153
if (confirmPassword && password !== confirmPassword) {
106154
showFieldError(event.target, 'Passwords do not match');

static/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const CACHE_NAME = 'ajs-pantry-v1';
1+
const CACHE_NAME = 'ajs-pantry-v2';
22
const STATIC_ASSETS = [
33
'/',
44
'/static/style.css',

templates/change_password.html

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,38 @@
77
<h3 class="font-weight-light my-1">Change Initial Password</h3>
88
</div>
99
<div class="card-body p-4">
10-
<p class="text-muted small mb-4">You are logging in for the first time. Please set a new password to secure your account.</p>
11-
<form method="POST">
12-
<div class="form-group mb-3">
13-
<label class="small mb-1" for="new_password">New Password</label>
14-
<input class="form-control" name="new_password" type="password" placeholder="Enter new password" required />
10+
<p class="text-muted small mb-4">You are logging in for the first time. Please set your details to secure your account.</p>
11+
<form method="POST" id="changePasswordForm">
12+
<!-- Name Section -->
13+
<div class="p-3 mb-4 rounded border-start border-4 border-primary bg-light">
14+
<label class="fw-bold small mb-2 text-primary text-uppercase" style="letter-spacing: 1px;">Personal Information</label>
15+
<div class="form-group">
16+
<label class="small mb-1" for="full_name">Full Name</label>
17+
<input class="form-control form-control-lg shadow-sm" name="full_name" type="text" placeholder="e.g. Idris Laheri" required />
18+
<div class="form-text small text-muted">Please enter your real full name.</div>
19+
</div>
1520
</div>
16-
<div class="form-group mb-3">
17-
<label class="small mb-1" for="confirm_password">Confirm New Password</label>
18-
<input class="form-control" name="confirm_password" type="password" placeholder="Confirm new password" required />
21+
22+
<!-- Password Section -->
23+
<div class="p-3 mb-3 rounded border-start border-4 border-info bg-light">
24+
<label class="fw-bold small mb-2 text-info text-uppercase" style="letter-spacing: 1px;">Security Setup</label>
25+
<div class="form-group mb-3">
26+
<label class="small mb-1" for="new_password">New Password</label>
27+
<input class="form-control shadow-sm" id="new_password" name="new_password" type="password" placeholder="Enter new password" required />
28+
</div>
29+
<div class="form-group mb-2">
30+
<label class="small mb-1" for="confirm_password">Confirm New Password</label>
31+
<input class="form-control shadow-sm" id="confirm_password" name="confirm_password" type="password" placeholder="Confirm new password" required />
32+
</div>
33+
34+
<!-- Silent Match Indicator -->
35+
<div id="passwordMatchStatus" class="small mt-2 text-center py-1 rounded" style="display: none; transition: all 0.3s ease; font-weight: 500;">
36+
<!-- Indicator text will appear here -->
37+
</div>
1938
</div>
39+
2040
<div class="form-group d-flex align-items-center justify-content-between mt-4 mb-0">
21-
<button type="submit" class="btn btn-primary btn-block w-100 py-2">Update Password & Continue</button>
41+
<button type="submit" class="btn btn-primary btn-block w-100 py-2 shadow-sm fw-bold">Update Password & Continue</button>
2242
</div>
2343
</form>
2444
</div>

templates/login.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2 class="fw-bold mb-0 mt-2">Member Login</h2>
4141
<span class="input-group-text bg-light border-end-0"><i
4242
class="fas fa-key text-teal-light"></i></span>
4343
<input class="form-control bg-light border-start-0 ps-0" id="password" name="password"
44-
type="password" placeholder="Enter your password" required />
44+
type="password" placeholder="initial password is: maskan1447" required />
4545
<button class="btn btn-outline-light border bg-light text-muted border-start-0" type="button"
4646
id="togglePassword">
4747
<i class="fas fa-eye"></i>
@@ -70,7 +70,8 @@ <h2 class="fw-bold mb-0 mt-2">Member Login</h2>
7070

7171
<div class="pt-2 border-top mt-3">
7272
<span class="small text-muted">Are you Staff?</span>
73-
<a href="{{ url_for('auth.staff_login') }}" class="small fw-bold text-teal text-decoration-none hover-link">
73+
<a href="{{ url_for('auth.staff_login') }}"
74+
class="small fw-bold text-teal text-decoration-none hover-link">
7475
Staff Login <i class="fas fa-arrow-right ms-1"></i>
7576
</a>
7677
</div>

templates/staff_login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h2 class="fw-bold mb-0 mt-2">Staff Login</h2>
6767
<span class="input-group-text bg-light border-end-0"><i
6868
class="fas fa-key text-teal-light"></i></span>
6969
<input class="form-control bg-light border-start-0 ps-0" id="password" name="password"
70-
type="password" placeholder="Enter your password" required />
70+
type="password" placeholder="initial password is: maskan1447" required />
7171
<button class="btn btn-outline-light border bg-light text-muted border-start-0" type="button"
7272
id="togglePassword">
7373
<i class="fas fa-eye"></i>

0 commit comments

Comments
 (0)