levix-bot 4.2.1 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/views/login.ejs CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  <section class="gateway-panel">
34
34
  <div class="gateway-panel-inner">
35
- <form class="card auth-card" action="/login" method="post">
35
+ <form class="card auth-card" id="login-card" action="/login" method="post">
36
36
  <div class="auth-head">
37
37
  <span class="eyebrow">Secure access</span>
38
38
  <h1>Welcome back</h1>
@@ -41,14 +41,20 @@
41
41
 
42
42
  <label class="field">
43
43
  <span>Control panel password</span>
44
- <input
45
- type="password"
46
- name="password"
47
- autocomplete="current-password"
48
- placeholder="Enter your password"
49
- autofocus
50
- required
51
- />
44
+ <div class="input-wrap">
45
+ <input
46
+ type="password"
47
+ name="password"
48
+ autocomplete="current-password"
49
+ placeholder="Enter your password"
50
+ autofocus
51
+ required
52
+ />
53
+ <button type="button" class="eye-btn" aria-label="Show password">
54
+ <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
55
+ <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
56
+ </button>
57
+ </div>
52
58
  </label>
53
59
 
54
60
  <button type="submit" class="btn btn-primary auth-submit">
@@ -59,11 +65,205 @@
59
65
  <% if (error) { %>
60
66
  <div class="error" role="alert"><%= error %></div>
61
67
  <% } %>
68
+
69
+ <div class="auth-alt">
70
+ <button type="button" class="link-btn" id="forgot-link">Forgot password?</button>
71
+ </div>
62
72
  </form>
63
73
 
74
+ <div class="card auth-card" id="reset-card" hidden>
75
+ <div class="auth-head">
76
+ <span class="eyebrow">Password reset</span>
77
+ <h1>Reset your password</h1>
78
+ <p class="sub">
79
+ Levix sends a one-time code to your WhatsApp — the linked account's own chat.
80
+ The code works for 10 minutes.
81
+ </p>
82
+ </div>
83
+
84
+ <button type="button" class="btn btn-primary auth-submit" id="reset-send">
85
+ Send code to WhatsApp
86
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
87
+ </button>
88
+
89
+ <form id="reset-form" hidden>
90
+ <label class="field">
91
+ <span>Reset code</span>
92
+ <input
93
+ type="text"
94
+ id="reset-code"
95
+ inputmode="numeric"
96
+ autocomplete="one-time-code"
97
+ maxlength="6"
98
+ placeholder="6 digits"
99
+ required
100
+ />
101
+ </label>
102
+
103
+ <label class="field">
104
+ <span>New password</span>
105
+ <div class="input-wrap">
106
+ <input
107
+ type="password"
108
+ id="reset-pass"
109
+ autocomplete="new-password"
110
+ placeholder="At least <%= minLength %> characters"
111
+ minlength="<%= minLength %>"
112
+ required
113
+ />
114
+ <button type="button" class="eye-btn" aria-label="Show password">
115
+ <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
116
+ <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
117
+ </button>
118
+ </div>
119
+ </label>
120
+
121
+ <label class="field">
122
+ <span>Repeat password</span>
123
+ <div class="input-wrap">
124
+ <input
125
+ type="password"
126
+ id="reset-confirm"
127
+ autocomplete="new-password"
128
+ placeholder="Type it again"
129
+ minlength="<%= minLength %>"
130
+ required
131
+ />
132
+ <button type="button" class="eye-btn" aria-label="Show password">
133
+ <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
134
+ <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
135
+ </button>
136
+ </div>
137
+ </label>
138
+
139
+ <button type="submit" class="btn btn-primary auth-submit">
140
+ Set new password
141
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
142
+ </button>
143
+ </form>
144
+
145
+ <div class="error" id="reset-error" role="alert" hidden></div>
146
+ <div class="auth-alt">
147
+ <button type="button" class="link-btn" id="reset-back">Back to sign in</button>
148
+ </div>
149
+ </div>
150
+
64
151
  <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
65
152
  </div>
66
153
  </section>
67
154
  </main>
155
+
156
+ <script src="/gateway.js"></script>
157
+ <script>
158
+ (function () {
159
+ var loginCard = document.getElementById("login-card");
160
+ var resetCard = document.getElementById("reset-card");
161
+ var sendBtn = document.getElementById("reset-send");
162
+ var form = document.getElementById("reset-form");
163
+ var errorBox = document.getElementById("reset-error");
164
+
165
+ function showReset() {
166
+ loginCard.hidden = true;
167
+ resetCard.hidden = false;
168
+ }
169
+ function showLogin() {
170
+ resetCard.hidden = true;
171
+ loginCard.hidden = false;
172
+ document.getElementById("forgot-link").focus();
173
+ }
174
+ function showError(text) {
175
+ errorBox.textContent = text;
176
+ errorBox.hidden = false;
177
+ }
178
+ function hideError() {
179
+ errorBox.hidden = true;
180
+ }
181
+ async function postJson(url, body) {
182
+ const response = await fetch(url, {
183
+ method: "POST",
184
+ headers: { "Content-Type": "application/json" },
185
+ body: JSON.stringify(body || {}),
186
+ });
187
+ let data = {};
188
+ try {
189
+ data = await response.json();
190
+ } catch {}
191
+ return data;
192
+ }
193
+
194
+ document.getElementById("forgot-link").addEventListener("click", showReset);
195
+ document.getElementById("reset-back").addEventListener("click", showLogin);
196
+
197
+ sendBtn.addEventListener("click", async function () {
198
+ sendBtn.disabled = true;
199
+ hideError();
200
+ try {
201
+ const result = await postJson("/reset/request");
202
+ if (result.ok) {
203
+ sendBtn.hidden = true;
204
+ form.hidden = false;
205
+ document.getElementById("reset-code").focus();
206
+ } else if (result.reason === "throttled") {
207
+ showError("Too many requests. Try again in " + (result.retryAfter || 60) + " seconds.");
208
+ } else if (result.reason === "no_session") {
209
+ showError(
210
+ "WhatsApp isn't connected, so the code can't be sent. " +
211
+ "Sign in on the server and run `levix reset-password`, or start the WhatsApp session first."
212
+ );
213
+ } else if (result.reason === "send_failed") {
214
+ showError("Couldn't send the WhatsApp message. Try again in a minute.");
215
+ } else {
216
+ showError("Couldn't start the reset. Try again.");
217
+ }
218
+ } catch {
219
+ showError("Couldn't reach the server. Try again.");
220
+ }
221
+ sendBtn.disabled = false;
222
+ });
223
+
224
+ form.addEventListener("submit", async function (event) {
225
+ event.preventDefault();
226
+ hideError();
227
+ try {
228
+ const result = await postJson("/reset/confirm", {
229
+ code: document.getElementById("reset-code").value,
230
+ password: document.getElementById("reset-pass").value,
231
+ confirm: document.getElementById("reset-confirm").value,
232
+ });
233
+ if (result.ok) {
234
+ form.hidden = true;
235
+ sendBtn.hidden = true;
236
+ showError("Password updated. Taking you to sign in…");
237
+ setTimeout(function () {
238
+ window.location.href = "/";
239
+ }, 900);
240
+ return;
241
+ }
242
+ if (result.reason === "wrong_code") {
243
+ showError(
244
+ "Wrong code." +
245
+ (result.attemptsLeft ? " " + result.attemptsLeft + " attempts left." : "")
246
+ );
247
+ } else if (
248
+ result.reason === "expired" ||
249
+ result.reason === "no_pending" ||
250
+ result.reason === "too_many_attempts"
251
+ ) {
252
+ showError("That code is no longer valid. Send a new one.");
253
+ form.hidden = true;
254
+ sendBtn.hidden = false;
255
+ } else if (result.reason === "mismatch") {
256
+ showError("The two passwords don't match.");
257
+ } else if (result.reason === "invalid_password") {
258
+ showError(result.message || "That password isn't allowed.");
259
+ } else {
260
+ showError("Couldn't reset the password. Try again.");
261
+ }
262
+ } catch {
263
+ showError("Couldn't reach the server. Try again.");
264
+ }
265
+ });
266
+ })();
267
+ </script>
68
268
  </body>
69
269
  </html>
package/views/setup.ejs CHANGED
@@ -50,15 +50,27 @@
50
50
 
51
51
  <label class="field">
52
52
  <span>Password</span>
53
- <input type="password" name="password" autocomplete="new-password"
54
- placeholder="At least <%= minLength %> characters"
55
- minlength="<%= minLength %>" <%= needsCode ? "" : "autofocus" %> required />
53
+ <div class="input-wrap">
54
+ <input type="password" name="password" autocomplete="new-password"
55
+ placeholder="At least <%= minLength %> characters"
56
+ minlength="<%= minLength %>" <%= needsCode ? "" : "autofocus" %> required />
57
+ <button type="button" class="eye-btn" aria-label="Show password">
58
+ <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
59
+ <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
60
+ </button>
61
+ </div>
56
62
  </label>
57
63
 
58
64
  <label class="field">
59
65
  <span>Repeat password</span>
60
- <input type="password" name="confirm" autocomplete="new-password"
61
- placeholder="Type it again" minlength="<%= minLength %>" required />
66
+ <div class="input-wrap">
67
+ <input type="password" name="confirm" autocomplete="new-password"
68
+ placeholder="Type it again" minlength="<%= minLength %>" required />
69
+ <button type="button" class="eye-btn" aria-label="Show password">
70
+ <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
71
+ <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
72
+ </button>
73
+ </div>
62
74
  </label>
63
75
 
64
76
  <button type="submit" class="btn btn-primary auth-submit">
@@ -75,5 +87,7 @@
75
87
  </div>
76
88
  </section>
77
89
  </main>
90
+
91
+ <script src="/gateway.js"></script>
78
92
  </body>
79
93
  </html>