Skip to content

Commit 34194e6

Browse files
committed
Update messages
1 parent 5d2a76a commit 34194e6

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

backend/internal/mfa.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ module.exports = {
3030
.where('user_id', userId)
3131
.first()
3232
.then((auth) => {
33+
console.log(auth);
3334
if (!auth) {
3435
throw new error.AuthError('User not found.');
3536
}
36-
return auth.mfa_enabled === 1;
37+
return auth.mfa_enabled === true;
3738
});
3839
},
3940
createMfaSecretForUser: (userId) => {
@@ -68,7 +69,7 @@ module.exports = {
6869
return authModel
6970
.query()
7071
.where('user_id', userId)
71-
.update({ mfa_enabled: 1 })
72+
.update({ mfa_enabled: true })
7273
.then(() => true);
7374
});
7475
},

frontend/js/app/user/form.ejs

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
</div>
2828

2929
<div class="col-sm-12 col-md-12">
30-
<button type="button" class="btn btn-info add-mfa">Add MFA</button>
31-
<p class="qr-instructions" style="display: none;">Scan this QR code in your authenticator app to set up MFA and then enter the current MFA code in the input field.</p>
30+
<label class="form-label mfa-label" style="display: none;"><%- i18n('mfa', 'mfa') %></label>
31+
<button type="button" class="btn btn-info add-mfa"><%- i18n('mfa', 'add-mfa') %></button>
32+
<p class="qr-instructions" style="display: none;"><%- i18n('mfa', 'mfa-setup-instruction') %></p>
3233
<div class="mfa-validation-container" style="display: none;">
33-
<label class="form-label"><%- i18n('str', 'mfa') %> <span class="form-required">*</span></label>
34-
<input name="mfa_validation" type="text" class="form-control" placeholder="000000" value="" required>
34+
<label class="form-label"><%- i18n('mfa', 'mfa-token') %> <span class="form-required">*</span></label>
35+
<input name="mfa_validation" type="text" class="form-control" placeholder="000000" value="">
3536
</div>
3637
</div>
3738

frontend/js/app/user/form.js

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = Mn.View.extend({
1616
save: 'button.save',
1717
error: '.secret-error',
1818
addMfa: '.add-mfa',
19+
mfaLabel: '.mfa-label', // added binding
1920
mfaValidation: '.mfa-validation-container', // added binding
2021
qrInstructions: '.qr-instructions' // added binding for instructions
2122
},
@@ -99,6 +100,8 @@ module.exports = Mn.View.extend({
99100
view.ui.addMfa.replaceWith(`<img class="qr-code" src="${response.qrCode}" alt="QR Code">`);
100101
view.ui.qrInstructions.show();
101102
view.ui.mfaValidation.show();
103+
// Add required attribute once MFA is activated
104+
view.ui.mfaValidation.find('input[name="mfa_validation"]').attr('required', true);
102105
})
103106
.catch(err => {
104107
view.ui.error.text(err.message).show();
@@ -140,12 +143,17 @@ module.exports = Mn.View.extend({
140143
.then(response => {
141144
if (response.active) {
142145
view.ui.addMfa.hide();
146+
view.ui.mfaLabel.hide();
143147
view.ui.qrInstructions.hide();
144148
view.ui.mfaValidation.hide();
149+
// Remove required attribute if MFA is active & field is hidden
150+
view.ui.mfaValidation.find('input[name="mfa_validation"]').removeAttr('required');
145151
} else {
146152
view.ui.addMfa.show();
153+
view.ui.mfaLabel.show();
147154
view.ui.qrInstructions.hide();
148155
view.ui.mfaValidation.hide();
156+
view.ui.mfaValidation.find('input[name="mfa_validation"]').removeAttr('required');
149157
}
150158
})
151159
.catch(err => {

frontend/js/i18n/messages.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"en": {
33
"str": {
44
"email-address": "Email address",
5-
"mfa": "Multi factor authentication token",
65
"username": "Username",
76
"password": "Password",
87
"sign-in": "Sign in",
@@ -38,9 +37,15 @@
3837
"all": "All",
3938
"any": "Any"
4039
},
40+
"mfa": {
41+
"mfa": "Multi Factor Authentication",
42+
"add-mfa": "Generate secret",
43+
"mfa-setup-instruction": "Scan this QR code in your authenticator app to set up MFA and then enter the current MFA code in the input field.",
44+
"mfa-token": "Multi factor authentication token"
45+
},
4146
"login": {
4247
"title": "Login to your account",
43-
"mfa_required_text": "Please enter your MFA token to continue"
48+
"mfa-required-text": "Please enter your MFA token to continue"
4449
},
4550
"main": {
4651
"app": "Nginx Proxy Manager",

frontend/js/login/ui/login.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
<div class="invalid-feedback secret-error"></div>
2727
</div>
2828
<div class="form-group mfa-group" style="display: none;">
29-
<p class="mfa-info"><%- i18n('login', 'mfa_required_text') %>:</p>
30-
<label class="form-label"><%- i18n('str', 'mfa') %></label>
31-
<input name="mfa_token" type="text" class="form-control" placeholder="<%- i18n('str', 'mfa') %>">
29+
<p class="mfa-info"><%- i18n('login', 'mfa-required-text') %>:</p>
30+
<label class="form-label"><%- i18n('mfa', 'mfa-token') %></label>
31+
<input name="mfa_token" type="text" class="form-control" placeholder="<%- i18n('mfa', 'mfa-token') %>">
3232
<div class="invalid-feedback mfa-error"></div>
3333
</div>
3434
<div class="form-footer">

0 commit comments

Comments
 (0)