@wral/studio.mods.auth 1.0.0 → 2.0.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/README.md +3 -3
- package/bitbucket-pipelines.yml +3 -3
- package/dist/auth.cjs.js +119 -205
- package/dist/auth.es.js +387 -606
- package/dist/lib.cjs.js +1 -1
- package/dist/lib.es.js +4 -6
- package/example-app.mjs +34 -0
- package/index.html +19 -72
- package/package.json +3 -2
- package/src/{components/forgot-password-form.mjs → forgot-password-form.mjs} +69 -69
- package/src/helper.mjs +5 -16
- package/src/index.mjs +108 -12
- package/src/layout.mjs +38 -0
- package/src/{components/login-form.mjs → login-form.mjs} +125 -122
- package/src/token.mjs +34 -30
- package/vellum/README.md +1 -0
- package/vellum/app-manager.mjs +126 -0
- package/vellum/example-app.mjs +34 -0
- package/vellum/index.mjs +26 -0
- package/vellum/layout.mjs +85 -0
- package/vellum/mod-setup.mjs +22 -0
- package/vellum/render.mjs +21 -0
- package/vellum/themes/default/index.css +89 -0
- package/vite.config.mjs +1 -1
- package/src/auth.mjs +0 -208
- package/src/auth.test.mjs +0 -97
- package/src/components/auth-app.mjs +0 -26
- package/src/config.mjs +0 -27
- package/src/login-layout.mjs +0 -32
- package/src/login.mjs +0 -20
- package/src/routes/change-password.mjs +0 -158
- package/src/routes/dashboard.mjs +0 -17
- package/src/routes/index.mjs +0 -15
- package/src/state.mjs +0 -61
- package/src/state.test.mjs +0 -58
- package/src/styles.mjs +0 -9
- package/src/utils.mjs +0 -3
- package/vellum-fixture.mjs +0 -86
package/dist/auth.es.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { getToken as
|
|
2
|
-
function k(r, ...e) {
|
|
3
|
-
return (...t) => r(...e, ...t);
|
|
4
|
-
}
|
|
1
|
+
import { getToken as fe } from "./lib.es.js";
|
|
5
2
|
/**
|
|
6
3
|
* @license
|
|
7
4
|
* Copyright 2019 Google LLC
|
|
8
5
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
6
|
*/
|
|
10
|
-
const
|
|
11
|
-
let
|
|
7
|
+
const q = globalThis, G = q.ShadowRoot && (q.ShadyCSS === void 0 || q.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, V = Symbol(), K = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
let ae = class {
|
|
12
9
|
constructor(e, t, s) {
|
|
13
|
-
if (this._$cssResult$ = !0, s !==
|
|
10
|
+
if (this._$cssResult$ = !0, s !== V) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
|
|
14
11
|
this.cssText = e, this.t = t;
|
|
15
12
|
}
|
|
16
13
|
get styleSheet() {
|
|
17
14
|
let e = this.o;
|
|
18
15
|
const t = this.t;
|
|
19
|
-
if (
|
|
16
|
+
if (G && e === void 0) {
|
|
20
17
|
const s = t !== void 0 && t.length === 1;
|
|
21
|
-
s && (e =
|
|
18
|
+
s && (e = K.get(t)), e === void 0 && ((this.o = e = new CSSStyleSheet()).replaceSync(this.cssText), s && K.set(t, e));
|
|
22
19
|
}
|
|
23
20
|
return e;
|
|
24
21
|
}
|
|
@@ -26,33 +23,33 @@ let ce = class {
|
|
|
26
23
|
return this.cssText;
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
|
-
const
|
|
26
|
+
const ge = (r) => new ae(typeof r == "string" ? r : r + "", void 0, V), J = (r, ...e) => {
|
|
30
27
|
const t = r.length === 1 ? r[0] : e.reduce((s, o, i) => s + ((n) => {
|
|
31
28
|
if (n._$cssResult$ === !0) return n.cssText;
|
|
32
29
|
if (typeof n == "number") return n;
|
|
33
30
|
throw Error("Value passed to 'css' function must be a 'css' function result: " + n + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
|
|
34
31
|
})(o) + r[i + 1], r[0]);
|
|
35
|
-
return new
|
|
36
|
-
},
|
|
37
|
-
if (
|
|
32
|
+
return new ae(t, r, V);
|
|
33
|
+
}, $e = (r, e) => {
|
|
34
|
+
if (G) r.adoptedStyleSheets = e.map((t) => t instanceof CSSStyleSheet ? t : t.styleSheet);
|
|
38
35
|
else for (const t of e) {
|
|
39
|
-
const s = document.createElement("style"), o =
|
|
36
|
+
const s = document.createElement("style"), o = q.litNonce;
|
|
40
37
|
o !== void 0 && s.setAttribute("nonce", o), s.textContent = t.cssText, r.appendChild(s);
|
|
41
38
|
}
|
|
42
|
-
},
|
|
39
|
+
}, Y = G ? (r) => r : (r) => r instanceof CSSStyleSheet ? ((e) => {
|
|
43
40
|
let t = "";
|
|
44
41
|
for (const s of e.cssRules) t += s.cssText;
|
|
45
|
-
return
|
|
42
|
+
return ge(t);
|
|
46
43
|
})(r) : r;
|
|
47
44
|
/**
|
|
48
45
|
* @license
|
|
49
46
|
* Copyright 2017 Google LLC
|
|
50
47
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
51
48
|
*/
|
|
52
|
-
const { is:
|
|
49
|
+
const { is: ye, defineProperty: be, getOwnPropertyDescriptor: _e, getOwnPropertyNames: we, getOwnPropertySymbols: ve, getPrototypeOf: Ae } = Object, $ = globalThis, Z = $.trustedTypes, Ee = Z ? Z.emptyScript : "", I = $.reactiveElementPolyfillSupport, U = (r, e) => r, W = { toAttribute(r, e) {
|
|
53
50
|
switch (e) {
|
|
54
51
|
case Boolean:
|
|
55
|
-
r = r ?
|
|
52
|
+
r = r ? Ee : null;
|
|
56
53
|
break;
|
|
57
54
|
case Object:
|
|
58
55
|
case Array:
|
|
@@ -77,23 +74,23 @@ const { is: _e, defineProperty: Ae, getOwnPropertyDescriptor: Ee, getOwnProperty
|
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
return t;
|
|
80
|
-
} },
|
|
81
|
-
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")),
|
|
82
|
-
class
|
|
77
|
+
} }, le = (r, e) => !ye(r, e), X = { attribute: !0, type: String, converter: W, reflect: !1, hasChanged: le };
|
|
78
|
+
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), $.litPropertyMetadata ?? ($.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
|
|
79
|
+
class S extends HTMLElement {
|
|
83
80
|
static addInitializer(e) {
|
|
84
81
|
this._$Ei(), (this.l ?? (this.l = [])).push(e);
|
|
85
82
|
}
|
|
86
83
|
static get observedAttributes() {
|
|
87
84
|
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
|
|
88
85
|
}
|
|
89
|
-
static createProperty(e, t =
|
|
86
|
+
static createProperty(e, t = X) {
|
|
90
87
|
if (t.state && (t.attribute = !1), this._$Ei(), this.elementProperties.set(e, t), !t.noAccessor) {
|
|
91
88
|
const s = Symbol(), o = this.getPropertyDescriptor(e, s, t);
|
|
92
|
-
o !== void 0 &&
|
|
89
|
+
o !== void 0 && be(this.prototype, e, o);
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
static getPropertyDescriptor(e, t, s) {
|
|
96
|
-
const { get: o, set: i } =
|
|
93
|
+
const { get: o, set: i } = _e(this.prototype, e) ?? { get() {
|
|
97
94
|
return this[t];
|
|
98
95
|
}, set(n) {
|
|
99
96
|
this[t] = n;
|
|
@@ -106,17 +103,17 @@ class P extends HTMLElement {
|
|
|
106
103
|
}, configurable: !0, enumerable: !0 };
|
|
107
104
|
}
|
|
108
105
|
static getPropertyOptions(e) {
|
|
109
|
-
return this.elementProperties.get(e) ??
|
|
106
|
+
return this.elementProperties.get(e) ?? X;
|
|
110
107
|
}
|
|
111
108
|
static _$Ei() {
|
|
112
109
|
if (this.hasOwnProperty(U("elementProperties"))) return;
|
|
113
|
-
const e =
|
|
110
|
+
const e = Ae(this);
|
|
114
111
|
e.finalize(), e.l !== void 0 && (this.l = [...e.l]), this.elementProperties = new Map(e.elementProperties);
|
|
115
112
|
}
|
|
116
113
|
static finalize() {
|
|
117
114
|
if (this.hasOwnProperty(U("finalized"))) return;
|
|
118
115
|
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(U("properties"))) {
|
|
119
|
-
const t = this.properties, s = [...
|
|
116
|
+
const t = this.properties, s = [...we(t), ...ve(t)];
|
|
120
117
|
for (const o of s) this.createProperty(o, t[o]);
|
|
121
118
|
}
|
|
122
119
|
const e = this[Symbol.metadata];
|
|
@@ -135,8 +132,8 @@ class P extends HTMLElement {
|
|
|
135
132
|
const t = [];
|
|
136
133
|
if (Array.isArray(e)) {
|
|
137
134
|
const s = new Set(e.flat(1 / 0).reverse());
|
|
138
|
-
for (const o of s) t.unshift(
|
|
139
|
-
} else e !== void 0 && t.push(
|
|
135
|
+
for (const o of s) t.unshift(Y(o));
|
|
136
|
+
} else e !== void 0 && t.push(Y(e));
|
|
140
137
|
return t;
|
|
141
138
|
}
|
|
142
139
|
static _$Eu(e, t) {
|
|
@@ -165,7 +162,7 @@ class P extends HTMLElement {
|
|
|
165
162
|
}
|
|
166
163
|
createRenderRoot() {
|
|
167
164
|
const e = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
|
|
168
|
-
return
|
|
165
|
+
return $e(e, this.constructor.elementStyles), e;
|
|
169
166
|
}
|
|
170
167
|
connectedCallback() {
|
|
171
168
|
var e;
|
|
@@ -190,7 +187,7 @@ class P extends HTMLElement {
|
|
|
190
187
|
var i;
|
|
191
188
|
const s = this.constructor.elementProperties.get(e), o = this.constructor._$Eu(e, s);
|
|
192
189
|
if (o !== void 0 && s.reflect === !0) {
|
|
193
|
-
const n = (((i = s.converter) == null ? void 0 : i.toAttribute) !== void 0 ? s.converter :
|
|
190
|
+
const n = (((i = s.converter) == null ? void 0 : i.toAttribute) !== void 0 ? s.converter : W).toAttribute(t, s.type);
|
|
194
191
|
this._$Em = e, n == null ? this.removeAttribute(o) : this.setAttribute(o, n), this._$Em = null;
|
|
195
192
|
}
|
|
196
193
|
}
|
|
@@ -198,13 +195,13 @@ class P extends HTMLElement {
|
|
|
198
195
|
var i;
|
|
199
196
|
const s = this.constructor, o = s._$Eh.get(e);
|
|
200
197
|
if (o !== void 0 && this._$Em !== o) {
|
|
201
|
-
const n = s.getPropertyOptions(o), l = typeof n.converter == "function" ? { fromAttribute: n.converter } : ((i = n.converter) == null ? void 0 : i.fromAttribute) !== void 0 ? n.converter :
|
|
198
|
+
const n = s.getPropertyOptions(o), l = typeof n.converter == "function" ? { fromAttribute: n.converter } : ((i = n.converter) == null ? void 0 : i.fromAttribute) !== void 0 ? n.converter : W;
|
|
202
199
|
this._$Em = o, this[o] = l.fromAttribute(t, n.type), this._$Em = null;
|
|
203
200
|
}
|
|
204
201
|
}
|
|
205
202
|
requestUpdate(e, t, s) {
|
|
206
203
|
if (e !== void 0) {
|
|
207
|
-
if (s ?? (s = this.constructor.getPropertyOptions(e)), !(s.hasChanged ??
|
|
204
|
+
if (s ?? (s = this.constructor.getPropertyOptions(e)), !(s.hasChanged ?? le)(this[e], t)) return;
|
|
208
205
|
this.P(e, t, s);
|
|
209
206
|
}
|
|
210
207
|
this.isUpdatePending === !1 && (this._$ES = this._$ET());
|
|
@@ -277,59 +274,59 @@ class P extends HTMLElement {
|
|
|
277
274
|
firstUpdated(e) {
|
|
278
275
|
}
|
|
279
276
|
}
|
|
280
|
-
|
|
277
|
+
S.elementStyles = [], S.shadowRootOptions = { mode: "open" }, S[U("elementProperties")] = /* @__PURE__ */ new Map(), S[U("finalized")] = /* @__PURE__ */ new Map(), I == null || I({ ReactiveElement: S }), ($.reactiveElementVersions ?? ($.reactiveElementVersions = [])).push("2.0.4");
|
|
281
278
|
/**
|
|
282
279
|
* @license
|
|
283
280
|
* Copyright 2017 Google LLC
|
|
284
281
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
285
282
|
*/
|
|
286
|
-
const
|
|
287
|
-
\f\r]`,
|
|
288
|
-
\f\r"'\`<>=]|("|')|))|$)`, "g"),
|
|
289
|
-
function
|
|
290
|
-
if (!
|
|
291
|
-
return
|
|
283
|
+
const T = globalThis, M = T.trustedTypes, ee = M ? M.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, he = "$lit$", g = `lit$${Math.random().toFixed(9).slice(2)}$`, ce = "?" + g, Se = `<${ce}>`, A = document, k = () => A.createComment(""), O = (r) => r === null || typeof r != "object" && typeof r != "function", Q = Array.isArray, Ce = (r) => Q(r) || typeof (r == null ? void 0 : r[Symbol.iterator]) == "function", z = `[
|
|
284
|
+
\f\r]`, x = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, te = /-->/g, se = />/g, b = RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^
|
|
285
|
+
\f\r"'\`<>=]|("|')|))|$)`, "g"), re = /'/g, oe = /"/g, de = /^(?:script|style|textarea|title)$/i, Pe = (r) => (e, ...t) => ({ _$litType$: r, strings: e, values: t }), p = Pe(1), C = Symbol.for("lit-noChange"), u = Symbol.for("lit-nothing"), ie = /* @__PURE__ */ new WeakMap(), w = A.createTreeWalker(A, 129);
|
|
286
|
+
function ue(r, e) {
|
|
287
|
+
if (!Q(r) || !r.hasOwnProperty("raw")) throw Error("invalid template strings array");
|
|
288
|
+
return ee !== void 0 ? ee.createHTML(e) : e;
|
|
292
289
|
}
|
|
293
|
-
const
|
|
290
|
+
const xe = (r, e) => {
|
|
294
291
|
const t = r.length - 1, s = [];
|
|
295
|
-
let o, i = e === 2 ? "<svg>" : e === 3 ? "<math>" : "", n =
|
|
292
|
+
let o, i = e === 2 ? "<svg>" : e === 3 ? "<math>" : "", n = x;
|
|
296
293
|
for (let l = 0; l < t; l++) {
|
|
297
294
|
const a = r[l];
|
|
298
|
-
let
|
|
299
|
-
for (; m < a.length && (n.lastIndex = m,
|
|
300
|
-
const f = n ===
|
|
301
|
-
i += n ===
|
|
295
|
+
let d, h, c = -1, m = 0;
|
|
296
|
+
for (; m < a.length && (n.lastIndex = m, h = n.exec(a), h !== null); ) m = n.lastIndex, n === x ? h[1] === "!--" ? n = te : h[1] !== void 0 ? n = se : h[2] !== void 0 ? (de.test(h[2]) && (o = RegExp("</" + h[2], "g")), n = b) : h[3] !== void 0 && (n = b) : n === b ? h[0] === ">" ? (n = o ?? x, c = -1) : h[1] === void 0 ? c = -2 : (c = n.lastIndex - h[2].length, d = h[1], n = h[3] === void 0 ? b : h[3] === '"' ? oe : re) : n === oe || n === re ? n = b : n === te || n === se ? n = x : (n = b, o = void 0);
|
|
297
|
+
const f = n === b && r[l + 1].startsWith("/>") ? " " : "";
|
|
298
|
+
i += n === x ? a + Se : c >= 0 ? (s.push(d), a.slice(0, c) + he + a.slice(c) + g + f) : a + g + (c === -2 ? l : f);
|
|
302
299
|
}
|
|
303
|
-
return [
|
|
300
|
+
return [ue(r, i + (r[t] || "<?>") + (e === 2 ? "</svg>" : e === 3 ? "</math>" : "")), s];
|
|
304
301
|
};
|
|
305
|
-
class
|
|
302
|
+
class R {
|
|
306
303
|
constructor({ strings: e, _$litType$: t }, s) {
|
|
307
304
|
let o;
|
|
308
305
|
this.parts = [];
|
|
309
306
|
let i = 0, n = 0;
|
|
310
|
-
const l = e.length - 1, a = this.parts, [
|
|
311
|
-
if (this.el =
|
|
312
|
-
const
|
|
313
|
-
|
|
307
|
+
const l = e.length - 1, a = this.parts, [d, h] = xe(e, t);
|
|
308
|
+
if (this.el = R.createElement(d, s), w.currentNode = this.el.content, t === 2 || t === 3) {
|
|
309
|
+
const c = this.el.content.firstChild;
|
|
310
|
+
c.replaceWith(...c.childNodes);
|
|
314
311
|
}
|
|
315
|
-
for (; (o =
|
|
312
|
+
for (; (o = w.nextNode()) !== null && a.length < l; ) {
|
|
316
313
|
if (o.nodeType === 1) {
|
|
317
|
-
if (o.hasAttributes()) for (const
|
|
318
|
-
const m =
|
|
319
|
-
a.push({ type: 1, index: i, name:
|
|
320
|
-
} else
|
|
321
|
-
if (
|
|
322
|
-
const
|
|
314
|
+
if (o.hasAttributes()) for (const c of o.getAttributeNames()) if (c.endsWith(he)) {
|
|
315
|
+
const m = h[n++], f = o.getAttribute(c).split(g), y = /([.?@])?(.*)/.exec(m);
|
|
316
|
+
a.push({ type: 1, index: i, name: y[2], strings: f, ctor: y[1] === "." ? Te : y[1] === "?" ? ke : y[1] === "@" ? Oe : D }), o.removeAttribute(c);
|
|
317
|
+
} else c.startsWith(g) && (a.push({ type: 6, index: i }), o.removeAttribute(c));
|
|
318
|
+
if (de.test(o.tagName)) {
|
|
319
|
+
const c = o.textContent.split(g), m = c.length - 1;
|
|
323
320
|
if (m > 0) {
|
|
324
321
|
o.textContent = M ? M.emptyScript : "";
|
|
325
|
-
for (let f = 0; f < m; f++) o.append(
|
|
326
|
-
o.append(
|
|
322
|
+
for (let f = 0; f < m; f++) o.append(c[f], k()), w.nextNode(), a.push({ type: 2, index: ++i });
|
|
323
|
+
o.append(c[m], k());
|
|
327
324
|
}
|
|
328
325
|
}
|
|
329
|
-
} else if (o.nodeType === 8) if (o.data ===
|
|
326
|
+
} else if (o.nodeType === 8) if (o.data === ce) a.push({ type: 2, index: i });
|
|
330
327
|
else {
|
|
331
|
-
let
|
|
332
|
-
for (; (
|
|
328
|
+
let c = -1;
|
|
329
|
+
for (; (c = o.data.indexOf(g, c + 1)) !== -1; ) a.push({ type: 7, index: i }), c += g.length - 1;
|
|
333
330
|
}
|
|
334
331
|
i++;
|
|
335
332
|
}
|
|
@@ -339,14 +336,14 @@ class H {
|
|
|
339
336
|
return s.innerHTML = e, s;
|
|
340
337
|
}
|
|
341
338
|
}
|
|
342
|
-
function
|
|
339
|
+
function P(r, e, t = r, s) {
|
|
343
340
|
var n, l;
|
|
344
|
-
if (e ===
|
|
341
|
+
if (e === C) return e;
|
|
345
342
|
let o = s !== void 0 ? (n = t._$Co) == null ? void 0 : n[s] : t._$Cl;
|
|
346
|
-
const i =
|
|
347
|
-
return (o == null ? void 0 : o.constructor) !== i && ((l = o == null ? void 0 : o._$AO) == null || l.call(o, !1), i === void 0 ? o = void 0 : (o = new i(r), o._$AT(r, t, s)), s !== void 0 ? (t._$Co ?? (t._$Co = []))[s] = o : t._$Cl = o), o !== void 0 && (e =
|
|
343
|
+
const i = O(e) ? void 0 : e._$litDirective$;
|
|
344
|
+
return (o == null ? void 0 : o.constructor) !== i && ((l = o == null ? void 0 : o._$AO) == null || l.call(o, !1), i === void 0 ? o = void 0 : (o = new i(r), o._$AT(r, t, s)), s !== void 0 ? (t._$Co ?? (t._$Co = []))[s] = o : t._$Cl = o), o !== void 0 && (e = P(r, o._$AS(r, e.values), o, s)), e;
|
|
348
345
|
}
|
|
349
|
-
class
|
|
346
|
+
class Ue {
|
|
350
347
|
constructor(e, t) {
|
|
351
348
|
this._$AV = [], this._$AN = void 0, this._$AD = e, this._$AM = t;
|
|
352
349
|
}
|
|
@@ -358,29 +355,29 @@ class Oe {
|
|
|
358
355
|
}
|
|
359
356
|
u(e) {
|
|
360
357
|
const { el: { content: t }, parts: s } = this._$AD, o = ((e == null ? void 0 : e.creationScope) ?? A).importNode(t, !0);
|
|
361
|
-
|
|
362
|
-
let i =
|
|
358
|
+
w.currentNode = o;
|
|
359
|
+
let i = w.nextNode(), n = 0, l = 0, a = s[0];
|
|
363
360
|
for (; a !== void 0; ) {
|
|
364
361
|
if (n === a.index) {
|
|
365
|
-
let
|
|
366
|
-
a.type === 2 ?
|
|
362
|
+
let d;
|
|
363
|
+
a.type === 2 ? d = new H(i, i.nextSibling, this, e) : a.type === 1 ? d = new a.ctor(i, a.name, a.strings, this, e) : a.type === 6 && (d = new Re(i, this, e)), this._$AV.push(d), a = s[++l];
|
|
367
364
|
}
|
|
368
|
-
n !== (a == null ? void 0 : a.index) && (i =
|
|
365
|
+
n !== (a == null ? void 0 : a.index) && (i = w.nextNode(), n++);
|
|
369
366
|
}
|
|
370
|
-
return
|
|
367
|
+
return w.currentNode = A, o;
|
|
371
368
|
}
|
|
372
369
|
p(e) {
|
|
373
370
|
let t = 0;
|
|
374
371
|
for (const s of this._$AV) s !== void 0 && (s.strings !== void 0 ? (s._$AI(e, s, t), t += s.strings.length - 2) : s._$AI(e[t])), t++;
|
|
375
372
|
}
|
|
376
373
|
}
|
|
377
|
-
class
|
|
374
|
+
class H {
|
|
378
375
|
get _$AU() {
|
|
379
376
|
var e;
|
|
380
377
|
return ((e = this._$AM) == null ? void 0 : e._$AU) ?? this._$Cv;
|
|
381
378
|
}
|
|
382
379
|
constructor(e, t, s, o) {
|
|
383
|
-
this.type = 2, this._$AH =
|
|
380
|
+
this.type = 2, this._$AH = u, this._$AN = void 0, this._$AA = e, this._$AB = t, this._$AM = s, this.options = o, this._$Cv = (o == null ? void 0 : o.isConnected) ?? !0;
|
|
384
381
|
}
|
|
385
382
|
get parentNode() {
|
|
386
383
|
let e = this._$AA.parentNode;
|
|
@@ -394,7 +391,7 @@ class D {
|
|
|
394
391
|
return this._$AB;
|
|
395
392
|
}
|
|
396
393
|
_$AI(e, t = this) {
|
|
397
|
-
e =
|
|
394
|
+
e = P(this, e, t), O(e) ? e === u || e == null || e === "" ? (this._$AH !== u && this._$AR(), this._$AH = u) : e !== this._$AH && e !== C && this._(e) : e._$litType$ !== void 0 ? this.$(e) : e.nodeType !== void 0 ? this.T(e) : Ce(e) ? this.k(e) : this._(e);
|
|
398
395
|
}
|
|
399
396
|
O(e) {
|
|
400
397
|
return this._$AA.parentNode.insertBefore(e, this._$AB);
|
|
@@ -403,26 +400,26 @@ class D {
|
|
|
403
400
|
this._$AH !== e && (this._$AR(), this._$AH = this.O(e));
|
|
404
401
|
}
|
|
405
402
|
_(e) {
|
|
406
|
-
this._$AH !==
|
|
403
|
+
this._$AH !== u && O(this._$AH) ? this._$AA.nextSibling.data = e : this.T(A.createTextNode(e)), this._$AH = e;
|
|
407
404
|
}
|
|
408
405
|
$(e) {
|
|
409
406
|
var i;
|
|
410
|
-
const { values: t, _$litType$: s } = e, o = typeof s == "number" ? this._$AC(e) : (s.el === void 0 && (s.el =
|
|
407
|
+
const { values: t, _$litType$: s } = e, o = typeof s == "number" ? this._$AC(e) : (s.el === void 0 && (s.el = R.createElement(ue(s.h, s.h[0]), this.options)), s);
|
|
411
408
|
if (((i = this._$AH) == null ? void 0 : i._$AD) === o) this._$AH.p(t);
|
|
412
409
|
else {
|
|
413
|
-
const n = new
|
|
410
|
+
const n = new Ue(o, this), l = n.u(this.options);
|
|
414
411
|
n.p(t), this.T(l), this._$AH = n;
|
|
415
412
|
}
|
|
416
413
|
}
|
|
417
414
|
_$AC(e) {
|
|
418
|
-
let t =
|
|
419
|
-
return t === void 0 &&
|
|
415
|
+
let t = ie.get(e.strings);
|
|
416
|
+
return t === void 0 && ie.set(e.strings, t = new R(e)), t;
|
|
420
417
|
}
|
|
421
418
|
k(e) {
|
|
422
|
-
|
|
419
|
+
Q(this._$AH) || (this._$AH = [], this._$AR());
|
|
423
420
|
const t = this._$AH;
|
|
424
421
|
let s, o = 0;
|
|
425
|
-
for (const i of e) o === t.length ? t.push(s = new
|
|
422
|
+
for (const i of e) o === t.length ? t.push(s = new H(this.O(k()), this.O(k()), this, this.options)) : s = t[o], s._$AI(i), o++;
|
|
426
423
|
o < t.length && (this._$AR(s && s._$AB.nextSibling, o), t.length = o);
|
|
427
424
|
}
|
|
428
425
|
_$AR(e = this._$AA.nextSibling, t) {
|
|
@@ -437,7 +434,7 @@ class D {
|
|
|
437
434
|
this._$AM === void 0 && (this._$Cv = e, (t = this._$AP) == null || t.call(this, e));
|
|
438
435
|
}
|
|
439
436
|
}
|
|
440
|
-
class
|
|
437
|
+
class D {
|
|
441
438
|
get tagName() {
|
|
442
439
|
return this.element.tagName;
|
|
443
440
|
}
|
|
@@ -445,46 +442,46 @@ class I {
|
|
|
445
442
|
return this._$AM._$AU;
|
|
446
443
|
}
|
|
447
444
|
constructor(e, t, s, o, i) {
|
|
448
|
-
this.type = 1, this._$AH =
|
|
445
|
+
this.type = 1, this._$AH = u, this._$AN = void 0, this.element = e, this.name = t, this._$AM = o, this.options = i, s.length > 2 || s[0] !== "" || s[1] !== "" ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = u;
|
|
449
446
|
}
|
|
450
447
|
_$AI(e, t = this, s, o) {
|
|
451
448
|
const i = this.strings;
|
|
452
449
|
let n = !1;
|
|
453
|
-
if (i === void 0) e =
|
|
450
|
+
if (i === void 0) e = P(this, e, t, 0), n = !O(e) || e !== this._$AH && e !== C, n && (this._$AH = e);
|
|
454
451
|
else {
|
|
455
452
|
const l = e;
|
|
456
|
-
let a,
|
|
457
|
-
for (e = i[0], a = 0; a < i.length - 1; a++)
|
|
453
|
+
let a, d;
|
|
454
|
+
for (e = i[0], a = 0; a < i.length - 1; a++) d = P(this, l[s + a], t, a), d === C && (d = this._$AH[a]), n || (n = !O(d) || d !== this._$AH[a]), d === u ? e = u : e !== u && (e += (d ?? "") + i[a + 1]), this._$AH[a] = d;
|
|
458
455
|
}
|
|
459
456
|
n && !o && this.j(e);
|
|
460
457
|
}
|
|
461
458
|
j(e) {
|
|
462
|
-
e ===
|
|
459
|
+
e === u ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, e ?? "");
|
|
463
460
|
}
|
|
464
461
|
}
|
|
465
|
-
class
|
|
462
|
+
class Te extends D {
|
|
466
463
|
constructor() {
|
|
467
464
|
super(...arguments), this.type = 3;
|
|
468
465
|
}
|
|
469
466
|
j(e) {
|
|
470
|
-
this.element[this.name] = e ===
|
|
467
|
+
this.element[this.name] = e === u ? void 0 : e;
|
|
471
468
|
}
|
|
472
469
|
}
|
|
473
|
-
class
|
|
470
|
+
class ke extends D {
|
|
474
471
|
constructor() {
|
|
475
472
|
super(...arguments), this.type = 4;
|
|
476
473
|
}
|
|
477
474
|
j(e) {
|
|
478
|
-
this.element.toggleAttribute(this.name, !!e && e !==
|
|
475
|
+
this.element.toggleAttribute(this.name, !!e && e !== u);
|
|
479
476
|
}
|
|
480
477
|
}
|
|
481
|
-
class
|
|
478
|
+
class Oe extends D {
|
|
482
479
|
constructor(e, t, s, o, i) {
|
|
483
480
|
super(e, t, s, o, i), this.type = 5;
|
|
484
481
|
}
|
|
485
482
|
_$AI(e, t = this) {
|
|
486
|
-
if ((e =
|
|
487
|
-
const s = this._$AH, o = e ===
|
|
483
|
+
if ((e = P(this, e, t, 0) ?? u) === C) return;
|
|
484
|
+
const s = this._$AH, o = e === u && s !== u || e.capture !== s.capture || e.once !== s.once || e.passive !== s.passive, i = e !== u && (s === u || o);
|
|
488
485
|
o && this.element.removeEventListener(this.name, this, s), i && this.element.addEventListener(this.name, this, e), this._$AH = e;
|
|
489
486
|
}
|
|
490
487
|
handleEvent(e) {
|
|
@@ -492,7 +489,7 @@ class qe extends I {
|
|
|
492
489
|
typeof this._$AH == "function" ? this._$AH.call(((t = this.options) == null ? void 0 : t.host) ?? this.element, e) : this._$AH.handleEvent(e);
|
|
493
490
|
}
|
|
494
491
|
}
|
|
495
|
-
class
|
|
492
|
+
class Re {
|
|
496
493
|
constructor(e, t, s) {
|
|
497
494
|
this.element = e, this.type = 6, this._$AN = void 0, this._$AM = t, this.options = s;
|
|
498
495
|
}
|
|
@@ -500,17 +497,17 @@ class De {
|
|
|
500
497
|
return this._$AM._$AU;
|
|
501
498
|
}
|
|
502
499
|
_$AI(e) {
|
|
503
|
-
|
|
500
|
+
P(this, e);
|
|
504
501
|
}
|
|
505
502
|
}
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
const
|
|
503
|
+
const j = T.litHtmlPolyfillSupport;
|
|
504
|
+
j == null || j(R, H), (T.litHtmlVersions ?? (T.litHtmlVersions = [])).push("3.2.1");
|
|
505
|
+
const Ne = (r, e, t) => {
|
|
509
506
|
const s = (t == null ? void 0 : t.renderBefore) ?? e;
|
|
510
507
|
let o = s._$litPart$;
|
|
511
508
|
if (o === void 0) {
|
|
512
509
|
const i = (t == null ? void 0 : t.renderBefore) ?? null;
|
|
513
|
-
s._$litPart$ = o = new
|
|
510
|
+
s._$litPart$ = o = new H(e.insertBefore(k(), i), i, void 0, t ?? {});
|
|
514
511
|
}
|
|
515
512
|
return o._$AI(r), o;
|
|
516
513
|
};
|
|
@@ -519,7 +516,7 @@ const Le = (r, e, t) => {
|
|
|
519
516
|
* Copyright 2017 Google LLC
|
|
520
517
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
521
518
|
*/
|
|
522
|
-
class
|
|
519
|
+
class v extends S {
|
|
523
520
|
constructor() {
|
|
524
521
|
super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
|
|
525
522
|
}
|
|
@@ -530,7 +527,7 @@ class b extends P {
|
|
|
530
527
|
}
|
|
531
528
|
update(e) {
|
|
532
529
|
const t = this.render();
|
|
533
|
-
this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(e), this._$Do =
|
|
530
|
+
this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(e), this._$Do = Ne(t, this.renderRoot, this.renderOptions);
|
|
534
531
|
}
|
|
535
532
|
connectedCallback() {
|
|
536
533
|
var e;
|
|
@@ -541,24 +538,53 @@ class b extends P {
|
|
|
541
538
|
super.disconnectedCallback(), (e = this._$Do) == null || e.setConnected(!1);
|
|
542
539
|
}
|
|
543
540
|
render() {
|
|
544
|
-
return
|
|
541
|
+
return C;
|
|
545
542
|
}
|
|
546
543
|
}
|
|
547
|
-
var
|
|
548
|
-
|
|
544
|
+
var ne;
|
|
545
|
+
v._$litElement$ = !0, v.finalized = !0, (ne = globalThis.litElementHydrateSupport) == null || ne.call(globalThis, { LitElement: v });
|
|
549
546
|
const B = globalThis.litElementPolyfillSupport;
|
|
550
|
-
B == null || B({ LitElement:
|
|
547
|
+
B == null || B({ LitElement: v });
|
|
551
548
|
(globalThis.litElementVersions ?? (globalThis.litElementVersions = [])).push("4.1.1");
|
|
552
|
-
|
|
549
|
+
class He extends v {
|
|
550
|
+
static get styles() {
|
|
551
|
+
return J`
|
|
552
|
+
.login-layout {
|
|
553
|
+
display: flex;
|
|
554
|
+
flex-direction: column;
|
|
555
|
+
gap: 1rem;
|
|
556
|
+
justify-content: center;
|
|
557
|
+
align-items: center;
|
|
558
|
+
min-height: 100vh;
|
|
559
|
+
background-color: var(--color-gray-100);
|
|
560
|
+
}
|
|
561
|
+
.login-layout > * {
|
|
562
|
+
max-width: 400px;
|
|
563
|
+
}
|
|
564
|
+
`;
|
|
565
|
+
}
|
|
566
|
+
render() {
|
|
567
|
+
return p`
|
|
568
|
+
<div class="login-layout">
|
|
569
|
+
<slot name="main"></slot>
|
|
570
|
+
</div>
|
|
571
|
+
`;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
customElements.get("mod-auth-layout") === void 0 && customElements.define("mod-auth-layout", He);
|
|
575
|
+
function Le() {
|
|
576
|
+
return p`<mod-auth-layout></mod-auth-layout>`;
|
|
577
|
+
}
|
|
578
|
+
function N(r) {
|
|
553
579
|
return {
|
|
554
580
|
// Underlying mechanism to use the REST URLs directly.
|
|
555
581
|
api: (e, t) => E(r, e, t),
|
|
556
582
|
mintToken: ({ username: e, password: t }) => Fe({ config: r, username: e, password: t }),
|
|
557
|
-
refreshToken: ({ token: e }) =>
|
|
558
|
-
pubkey: () =>
|
|
559
|
-
updatePassword: ({ token: e, currentPassword: t, newPassword: s }) =>
|
|
560
|
-
triggerResetPassword: ({ username: e }) =>
|
|
561
|
-
confirmResetPassword: ({ username: e, newPassword: t, confirmationCode: s }) =>
|
|
583
|
+
refreshToken: ({ token: e }) => qe({ config: r, token: e }),
|
|
584
|
+
pubkey: () => Me({ config: r }),
|
|
585
|
+
updatePassword: ({ token: e, currentPassword: t, newPassword: s }) => De({ config: r, token: e, currentPassword: t, newPassword: s }),
|
|
586
|
+
triggerResetPassword: ({ username: e }) => Ie({ config: r, username: e }),
|
|
587
|
+
confirmResetPassword: ({ username: e, newPassword: t, confirmationCode: s }) => ze({ config: r, username: e, newPassword: t, confirmationCode: s })
|
|
562
588
|
};
|
|
563
589
|
}
|
|
564
590
|
function Fe({ config: r, username: e, password: t }) {
|
|
@@ -570,7 +596,7 @@ function Fe({ config: r, username: e, password: t }) {
|
|
|
570
596
|
}
|
|
571
597
|
});
|
|
572
598
|
}
|
|
573
|
-
function
|
|
599
|
+
function qe({ config: r, token: e }) {
|
|
574
600
|
return E(r, "/v1/refresh", {
|
|
575
601
|
method: "POST",
|
|
576
602
|
body: {
|
|
@@ -578,12 +604,12 @@ function Me({ config: r, token: e }) {
|
|
|
578
604
|
}
|
|
579
605
|
});
|
|
580
606
|
}
|
|
581
|
-
function
|
|
607
|
+
function Me({ config: r }) {
|
|
582
608
|
return E(r, "/v1/pubkey", {
|
|
583
609
|
method: "GET"
|
|
584
610
|
});
|
|
585
611
|
}
|
|
586
|
-
function
|
|
612
|
+
function De({ config: r, token: e, currentPassword: t, newPassword: s }) {
|
|
587
613
|
return E(r, "/v1/user/password", {
|
|
588
614
|
method: "PUT",
|
|
589
615
|
body: {
|
|
@@ -595,7 +621,7 @@ function ze({ config: r, token: e, currentPassword: t, newPassword: s }) {
|
|
|
595
621
|
}
|
|
596
622
|
});
|
|
597
623
|
}
|
|
598
|
-
function
|
|
624
|
+
function Ie({ config: r, username: e }) {
|
|
599
625
|
return E(r, "/v1/user/password/reset", {
|
|
600
626
|
method: "POST",
|
|
601
627
|
body: {
|
|
@@ -603,7 +629,7 @@ function je({ config: r, username: e }) {
|
|
|
603
629
|
}
|
|
604
630
|
});
|
|
605
631
|
}
|
|
606
|
-
function
|
|
632
|
+
function ze({ config: r, username: e, newPassword: t, confirmationCode: s }) {
|
|
607
633
|
return E(r, "/v1/user/password/reset/confirm", {
|
|
608
634
|
method: "POST",
|
|
609
635
|
body: {
|
|
@@ -614,7 +640,7 @@ function We({ config: r, username: e, newPassword: t, confirmationCode: s }) {
|
|
|
614
640
|
});
|
|
615
641
|
}
|
|
616
642
|
async function E(r, e, t) {
|
|
617
|
-
var
|
|
643
|
+
var d;
|
|
618
644
|
const s = r.baseUrl.endsWith("/") ? r.baseUrl : `${r.baseUrl}/`, o = e.startsWith("/") ? e.substring(1) : e, i = new URL(o, s), l = Object.assign({}, t, {
|
|
619
645
|
headers: Object.assign({}, {
|
|
620
646
|
"Content-Type": "application/json"
|
|
@@ -622,41 +648,40 @@ async function E(r, e, t) {
|
|
|
622
648
|
body: t != null && t.body ? JSON.stringify(t.body) : void 0
|
|
623
649
|
}), a = await fetch(i.toString(), l);
|
|
624
650
|
if (!a.ok) {
|
|
625
|
-
const
|
|
626
|
-
if (
|
|
651
|
+
const h = new Error("API request failed.");
|
|
652
|
+
if (h.status = a.status, h.statusText = a.statusText, h.url = i.toString(), h.headers = a.headers, h.bodyUsed = a.bodyUsed, (d = a.headers.get("Content-Type")) != null && d.includes("application/json"))
|
|
627
653
|
try {
|
|
628
|
-
|
|
654
|
+
h.body = await a.json();
|
|
629
655
|
} catch {
|
|
630
|
-
|
|
656
|
+
h.body = "Failed to parse response body.";
|
|
631
657
|
}
|
|
632
|
-
throw
|
|
658
|
+
throw h;
|
|
633
659
|
}
|
|
634
660
|
if (a.status !== 204)
|
|
635
661
|
return await a.json();
|
|
636
662
|
}
|
|
637
|
-
|
|
638
|
-
const t = x({
|
|
639
|
-
baseUrl: r
|
|
640
|
-
});
|
|
641
|
-
return console.log("sending credentials to API", r), t.mintToken(e);
|
|
642
|
-
}
|
|
643
|
-
const g = Object.freeze({
|
|
663
|
+
const _ = Object.freeze({
|
|
644
664
|
REQUEST: "request",
|
|
645
665
|
CONFIRM: "confirm",
|
|
646
666
|
FINISHED: "finished"
|
|
647
667
|
});
|
|
648
|
-
class
|
|
668
|
+
class je extends v {
|
|
649
669
|
static get properties() {
|
|
650
670
|
return {
|
|
651
|
-
api: { type: String
|
|
652
|
-
confirmation: { type: "String", attribute: "confirmation" }
|
|
671
|
+
api: { type: String }
|
|
653
672
|
};
|
|
654
673
|
}
|
|
655
674
|
static get styles() {
|
|
656
|
-
return
|
|
675
|
+
return J`
|
|
657
676
|
:host {
|
|
658
|
-
display:
|
|
659
|
-
|
|
677
|
+
display: flex;
|
|
678
|
+
flex-direction: column;
|
|
679
|
+
justify-content: center;
|
|
680
|
+
align-items: center;
|
|
681
|
+
}
|
|
682
|
+
form {
|
|
683
|
+
display: flex;
|
|
684
|
+
flex-direction: column;
|
|
660
685
|
}
|
|
661
686
|
form input[type="text"],
|
|
662
687
|
form input[type="password"] {
|
|
@@ -664,14 +689,14 @@ class Be extends b {
|
|
|
664
689
|
margin: 5px 0 15px 0;
|
|
665
690
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
666
691
|
box-sizing: border-box;
|
|
667
|
-
border: 1px solid var(--color-gray-300, #
|
|
668
|
-
border-radius: var(--radius-sm,
|
|
669
|
-
color: var(--color-gray-
|
|
670
|
-
background-color: var(--color-gray-
|
|
692
|
+
border: 1px solid var(--color-gray-300, #CCC);
|
|
693
|
+
border-radius: var(--radius-sm, 3px);
|
|
694
|
+
color: var(--color-gray-700, #333);
|
|
695
|
+
background-color: var(--color-gray-50, #FFF);
|
|
671
696
|
}
|
|
672
697
|
form input[type="submit"] {
|
|
673
|
-
background-color:var(--color-primary, inherit);
|
|
674
|
-
color: var(--color-gray-
|
|
698
|
+
background-color: var(--color-primary, inherit);
|
|
699
|
+
color: var(--color-gray-50, #fff);
|
|
675
700
|
border: none;
|
|
676
701
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
677
702
|
border-radius: var(--radius-dynamic, 5px);
|
|
@@ -682,31 +707,32 @@ class Be extends b {
|
|
|
682
707
|
}
|
|
683
708
|
form label {
|
|
684
709
|
font-size: 14px;
|
|
685
|
-
color: var(--color-gray-
|
|
710
|
+
color: var(--color-gray-700, #333);
|
|
686
711
|
font-weight: bold;
|
|
687
712
|
margin-bottom: var(--spacing-sm, 0.5rem);
|
|
688
713
|
}
|
|
689
714
|
.error {
|
|
690
715
|
color: var(--color-danger, red);
|
|
691
|
-
font-size:
|
|
716
|
+
font-size: 14px;
|
|
692
717
|
}
|
|
693
718
|
`;
|
|
694
719
|
}
|
|
695
720
|
constructor() {
|
|
696
|
-
super(), this.errors = {}, this.stage =
|
|
721
|
+
super(), this.errors = {}, this.stage = _.REQUEST;
|
|
697
722
|
}
|
|
698
723
|
connectedCallback() {
|
|
699
|
-
|
|
724
|
+
super.connectedCallback(), this.confirmToken && this.stage !== _.FINISHED && this.setStage(_.CONFIRM);
|
|
725
|
+
}
|
|
726
|
+
setStage(e) {
|
|
727
|
+
this.stage !== e && (this.stage = e, this.requestUpdate());
|
|
700
728
|
}
|
|
701
729
|
handleSubmitRequest(e) {
|
|
702
730
|
e.preventDefault();
|
|
703
731
|
const t = e.target.username.value;
|
|
704
|
-
this.username = t,
|
|
705
|
-
|
|
706
|
-
}).triggerResetPassword({ username: t }).then(() => {
|
|
707
|
-
console.log("[auth]", "triggered reset password for ", t), this.stage = g.CONFIRM;
|
|
732
|
+
this.username = t, N({ baseUrl: this.api }).triggerResetPassword({ username: t }).then(() => {
|
|
733
|
+
this.setStage(_.CONFIRM);
|
|
708
734
|
}).catch((o) => {
|
|
709
|
-
|
|
735
|
+
this.errors.general = o.message || "Unable to send password reset request. Please try again later.";
|
|
710
736
|
}).finally(() => {
|
|
711
737
|
this.requestUpdate();
|
|
712
738
|
});
|
|
@@ -715,48 +741,50 @@ class Be extends b {
|
|
|
715
741
|
e.preventDefault();
|
|
716
742
|
const t = e.target.password.value, s = e.target["confirm-password"].value;
|
|
717
743
|
if (t !== s) {
|
|
718
|
-
this.errors["confirm-password"] = "Passwords do not match
|
|
744
|
+
this.errors["confirm-password"] = "Passwords do not match", this.requestUpdate();
|
|
719
745
|
return;
|
|
720
746
|
}
|
|
721
|
-
const o = this.
|
|
747
|
+
const o = this.confirmToken || e.target.confirmation.value;
|
|
722
748
|
if (!o) {
|
|
723
|
-
this.errors.general = "Confirmation code is required
|
|
749
|
+
this.errors.general = "Confirmation code is required", this.requestUpdate();
|
|
724
750
|
return;
|
|
725
751
|
}
|
|
726
|
-
|
|
752
|
+
const i = N({
|
|
727
753
|
baseUrl: this.api
|
|
728
|
-
})
|
|
754
|
+
});
|
|
755
|
+
i.confirmResetPassword({
|
|
729
756
|
username: this.username,
|
|
730
757
|
newPassword: t,
|
|
731
758
|
confirmationCode: o
|
|
732
|
-
}).then(() =>
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
759
|
+
}).then(() => {
|
|
760
|
+
i.mintToken({ username: this.username, password: t }).then(({ token: n }) => {
|
|
761
|
+
this.dispatchEvent(new CustomEvent("login-success", {
|
|
762
|
+
detail: { token: n },
|
|
763
|
+
bubbles: !0,
|
|
764
|
+
composed: !0,
|
|
765
|
+
cancelable: !0
|
|
766
|
+
}));
|
|
767
|
+
});
|
|
768
|
+
}).catch((n) => {
|
|
769
|
+
this.errors.general = n.message || "Unable to send password reset request. Please try again later.";
|
|
740
770
|
}).finally(() => {
|
|
741
771
|
this.requestUpdate();
|
|
742
772
|
});
|
|
743
773
|
}
|
|
744
774
|
render() {
|
|
745
775
|
switch (this.stage) {
|
|
746
|
-
case
|
|
776
|
+
case _.FINISHED:
|
|
777
|
+
return p`<p>Your password has been reset.</p>`;
|
|
778
|
+
case _.CONFIRM:
|
|
747
779
|
return this.renderConfirmForm();
|
|
748
|
-
case
|
|
749
|
-
return c`<p>Your password has been reset.</p>`;
|
|
750
|
-
case g.REQUEST_SENT:
|
|
751
|
-
return c`<p>A email has been sent with instructions to finish
|
|
752
|
-
resetting your password.</p>`;
|
|
753
|
-
case g.REQUEST:
|
|
780
|
+
case _.REQUEST:
|
|
754
781
|
default:
|
|
755
782
|
return this.renderRequestForm();
|
|
756
783
|
}
|
|
757
784
|
}
|
|
758
785
|
renderRequestForm() {
|
|
759
|
-
return
|
|
786
|
+
return p`<form @submit="${this.handleSubmitRequest}">
|
|
787
|
+
<p>Enter your username or email address to request a password reset.</p>
|
|
760
788
|
<label for="username">Username/Email</label>
|
|
761
789
|
<input
|
|
762
790
|
type="text"
|
|
@@ -765,20 +793,20 @@ class Be extends b {
|
|
|
765
793
|
required
|
|
766
794
|
/>
|
|
767
795
|
<p class="error">${this.errors.general}</p>
|
|
768
|
-
<input type="submit" value="Request
|
|
796
|
+
<input type="submit" value="Request Password Reset" />
|
|
769
797
|
</form>`;
|
|
770
798
|
}
|
|
771
799
|
renderConfirmForm() {
|
|
772
|
-
return
|
|
773
|
-
|
|
800
|
+
return p`<form @submit="${this.handleSubmitConfirm}">
|
|
801
|
+
<p>You should have received a confirmation code to reset your password.</p>
|
|
774
802
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
803
|
+
${this.confirmToken ? "" : p`<label for="confirmation">Confirmation Code</label>
|
|
804
|
+
<input
|
|
805
|
+
type="text"
|
|
806
|
+
name="confirmation"
|
|
807
|
+
placeholder="Confirmation Code"
|
|
808
|
+
required
|
|
809
|
+
/>`}
|
|
782
810
|
|
|
783
811
|
<label for="password">New Password</label>
|
|
784
812
|
<input
|
|
@@ -787,8 +815,6 @@ class Be extends b {
|
|
|
787
815
|
placeholder="Password"
|
|
788
816
|
required
|
|
789
817
|
/>
|
|
790
|
-
${this.errors.password ? c`<p class="error">${this.errors.password}</p>` : ""}
|
|
791
|
-
|
|
792
818
|
<label for="confirm-password">Confirm Password</label>
|
|
793
819
|
<input
|
|
794
820
|
type="password"
|
|
@@ -796,27 +822,28 @@ class Be extends b {
|
|
|
796
822
|
placeholder="Confirm Password"
|
|
797
823
|
required
|
|
798
824
|
/>
|
|
799
|
-
${this.errors["confirm-password"] ?
|
|
825
|
+
${this.errors["confirm-password"] ? p`<p class="error">${this.errors["confirm-password"]}</p>` : ""}
|
|
826
|
+
|
|
827
|
+
${this.errors.general ? p`<p class="error">${this.errors.general}</p>` : ""}
|
|
800
828
|
|
|
801
|
-
${this.errors.general ? c`<p class="error">${this.errors.general}</p>` : ""}
|
|
802
829
|
<input type="submit" value="Reset Password" />
|
|
803
830
|
</form>`;
|
|
804
831
|
}
|
|
805
832
|
}
|
|
806
|
-
|
|
833
|
+
customElements.get("auth-forgot-password-form") || window.customElements.define("auth-forgot-password-form", je);
|
|
834
|
+
class Be extends v {
|
|
807
835
|
static get properties() {
|
|
808
836
|
return {
|
|
809
837
|
api: { type: String, attribute: "api" }
|
|
810
838
|
};
|
|
811
839
|
}
|
|
812
840
|
static get styles() {
|
|
813
|
-
return
|
|
841
|
+
return J`
|
|
814
842
|
:host {
|
|
815
843
|
display: block;
|
|
816
|
-
font-family: Arial, sans-serif;
|
|
817
844
|
}
|
|
818
845
|
.login-form {
|
|
819
|
-
background-color: var(--color-gray-
|
|
846
|
+
background-color: var(--color-gray-50);
|
|
820
847
|
padding: var(--spacing-xl, 3rem);
|
|
821
848
|
border-radius: var(--radius-md, 5px);
|
|
822
849
|
box-shadow: var(--drop-shadow-md, none);
|
|
@@ -827,14 +854,14 @@ class y extends b {
|
|
|
827
854
|
margin: 5px 0 15px 0;
|
|
828
855
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
829
856
|
box-sizing: border-box;
|
|
830
|
-
border: 1px solid var(--color-gray-300, #
|
|
831
|
-
border-radius: var(--radius-sm,
|
|
832
|
-
color: var(--color-gray-
|
|
833
|
-
background-color: var(--color-gray-
|
|
857
|
+
border: 1px solid var(--color-gray-300, #CCC);
|
|
858
|
+
border-radius: var(--radius-sm, 3px);
|
|
859
|
+
color: var(--color-gray-700, #333);
|
|
860
|
+
background-color: var(--color-gray-100, #FFF);
|
|
834
861
|
}
|
|
835
862
|
form input[type="submit"] {
|
|
836
863
|
background-color: var(--color-primary, inherit);
|
|
837
|
-
color: var(--color-gray-
|
|
864
|
+
color: var(--color-gray-50, #fff);
|
|
838
865
|
border: none;
|
|
839
866
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
840
867
|
border-radius: var(--radius-dynamic, 5px);
|
|
@@ -845,15 +872,15 @@ class y extends b {
|
|
|
845
872
|
}
|
|
846
873
|
form label {
|
|
847
874
|
font-size: 14px;
|
|
848
|
-
color: var(--color-gray-
|
|
875
|
+
color: var(--color-gray-900, #333);
|
|
849
876
|
font-weight: bold;
|
|
850
877
|
margin-bottom: var(--spacing-sm, 0.5rem);
|
|
851
878
|
}
|
|
852
879
|
a.forgot {
|
|
853
880
|
color: var(--color-primary, inherit);
|
|
854
881
|
text-decoration: none;
|
|
855
|
-
font-size: 12px;
|
|
856
882
|
font-weight: bold;
|
|
883
|
+
font-size: 12px;
|
|
857
884
|
}
|
|
858
885
|
.error {
|
|
859
886
|
color: var(--color-error, red);
|
|
@@ -868,7 +895,7 @@ class y extends b {
|
|
|
868
895
|
.header .intro {
|
|
869
896
|
width: 200px;
|
|
870
897
|
margin-bottom: 0;
|
|
871
|
-
color: var(--color-gray-
|
|
898
|
+
color: var(--color-gray-300, #333);
|
|
872
899
|
}
|
|
873
900
|
.header .brand {
|
|
874
901
|
font-size: 32px;
|
|
@@ -890,478 +917,232 @@ class y extends b {
|
|
|
890
917
|
};
|
|
891
918
|
}
|
|
892
919
|
constructor() {
|
|
893
|
-
super(), this.formState =
|
|
920
|
+
super(), this.formState = this.constructor.states.DEFAULT, this.errors = [], this.isBusy = !1;
|
|
921
|
+
}
|
|
922
|
+
login({ username: e, password: t }) {
|
|
923
|
+
return N({
|
|
924
|
+
baseUrl: this.api
|
|
925
|
+
}).mintToken({ username: e, password: t });
|
|
894
926
|
}
|
|
895
|
-
|
|
927
|
+
emitLoginSuccess(e) {
|
|
928
|
+
this.dispatchEvent(new CustomEvent("login-success", {
|
|
929
|
+
detail: { token: e },
|
|
930
|
+
bubbles: !0,
|
|
931
|
+
composed: !0,
|
|
932
|
+
cancelable: !0
|
|
933
|
+
}));
|
|
934
|
+
}
|
|
935
|
+
handleSubmitLogin(e) {
|
|
896
936
|
e.preventDefault();
|
|
897
|
-
const t = e.explicitOriginalTarget.parentElement;
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
if (i && i.name === "NEW_PASSWORD_REQUIRED") {
|
|
902
|
-
this.token = o, this.username = s.username, this.password = s.password, this.setState(y.states.CHALLENGE_CHANGE_PW);
|
|
937
|
+
const t = e.explicitOriginalTarget.parentElement, s = new FormData(t).entries().reduce((o, [i, n]) => (o[i] = n, o), {});
|
|
938
|
+
this.isBusy = !0, this.errors = [], this.requestUpdate(), this.login(s).then(({ token: o, challenge: i }) => {
|
|
939
|
+
if ((i == null ? void 0 : i.name) === "NEW_PASSWORD_REQUIRED") {
|
|
940
|
+
this.token = o, this.username = s.username, this.password = s.password, this.setState(this.constructor.states.CHALLENGE_CHANGE_PW);
|
|
903
941
|
return;
|
|
904
942
|
}
|
|
905
|
-
this.
|
|
906
|
-
detail: { token: o }
|
|
907
|
-
}));
|
|
943
|
+
this.emitLoginSuccess(o);
|
|
908
944
|
}).catch((o) => {
|
|
909
|
-
console.
|
|
945
|
+
console.error(o), this.errors = [o.message], this.requestUpdate();
|
|
910
946
|
});
|
|
911
947
|
}
|
|
912
948
|
onSubmitChangePasswordChallenge(e) {
|
|
913
949
|
e.preventDefault();
|
|
914
|
-
const t = e.explicitOriginalTarget, s = new FormData(t).entries().reduce((l, [a,
|
|
950
|
+
const t = e.explicitOriginalTarget.parentElement, s = new FormData(t).entries().reduce((l, [a, d]) => (l[a] = d, l), {}), o = s.password, i = s["confirm-password"];
|
|
915
951
|
if (o !== i) {
|
|
916
|
-
this.errors = ["Passwords do not match
|
|
952
|
+
this.errors = ["Passwords do not match"], this.requestUpdate();
|
|
917
953
|
return;
|
|
918
954
|
}
|
|
919
|
-
|
|
955
|
+
N({
|
|
920
956
|
baseUrl: this.api
|
|
921
957
|
}).updatePassword({
|
|
922
958
|
token: this.token,
|
|
923
959
|
currentPassword: this.password,
|
|
924
960
|
newPassword: o
|
|
925
961
|
}).then(() => {
|
|
926
|
-
this.
|
|
927
|
-
detail: { token: this.token }
|
|
928
|
-
}));
|
|
962
|
+
this.emitLoginSuccess(this.token);
|
|
929
963
|
}).catch((l) => {
|
|
930
|
-
console.
|
|
964
|
+
console.error(l), this.errors = [l.message], this.requestUpdate();
|
|
931
965
|
});
|
|
932
966
|
}
|
|
933
967
|
setState(e) {
|
|
934
|
-
|
|
968
|
+
this.formState = e, this.isBusy = !1, this.errors = [], this.requestUpdate();
|
|
935
969
|
}
|
|
936
970
|
render() {
|
|
937
|
-
return
|
|
971
|
+
return p`<div class="login-form">
|
|
938
972
|
${this.renderHeader()}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
973
|
+
${this.formState === this.constructor.states.DEFAULT ? this.renderLoginForm() : ""}
|
|
974
|
+
${this.formState === this.constructor.states.CHALLENGE_CHANGE_PW ? this.renderChangePasswordForm() : ""}
|
|
975
|
+
${this.formState === this.constructor.states.FORGOT ? this.renderForgotPasswordForm() : ""}
|
|
942
976
|
</div>`;
|
|
943
977
|
}
|
|
944
|
-
/**
|
|
945
|
-
* TODO: accept the header as a slot
|
|
946
|
-
*/
|
|
947
978
|
renderHeader() {
|
|
948
|
-
return
|
|
949
|
-
<div class="intro">
|
|
950
|
-
|
|
951
|
-
</div>
|
|
952
|
-
<div class="brand">
|
|
953
|
-
<em>WRAL</em>.studio
|
|
954
|
-
</div>
|
|
979
|
+
return p`<div class="header">
|
|
980
|
+
<div class="intro">Welcome to</div>
|
|
981
|
+
<div class="brand"><em>WRAL</em>.studio</div>
|
|
955
982
|
</div>`;
|
|
956
983
|
}
|
|
957
984
|
renderLoginForm() {
|
|
958
|
-
return
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
<label for="password">Password</label>
|
|
969
|
-
<input
|
|
970
|
-
type="password"
|
|
971
|
-
name="password"
|
|
972
|
-
placeholder="Password"
|
|
973
|
-
required
|
|
974
|
-
/>
|
|
975
|
-
<div>
|
|
976
|
-
<a href="#" class="forgot"
|
|
977
|
-
@click=${() => {
|
|
978
|
-
this.setState(y.states.FORGOT);
|
|
979
|
-
}}
|
|
980
|
-
>Forgot password</a>
|
|
981
|
-
</div>
|
|
982
|
-
|
|
983
|
-
${this.errors ? this.errors.map((e) => c`<p class="error">${e}</p>`) : ""}
|
|
984
|
-
<input type="submit" value="Log in" @click=${this.onSubmit} />
|
|
985
|
+
return p`
|
|
986
|
+
<form>
|
|
987
|
+
<label for="username">User</label>
|
|
988
|
+
<input
|
|
989
|
+
type="text"
|
|
990
|
+
name="username"
|
|
991
|
+
placeholder="Email or Username"
|
|
992
|
+
required
|
|
993
|
+
/>
|
|
985
994
|
|
|
986
|
-
</
|
|
987
|
-
}
|
|
988
|
-
renderForgotPasswordForm() {
|
|
989
|
-
return c`
|
|
990
|
-
<auth-forgot-password-form
|
|
991
|
-
api=${this.api}>
|
|
992
|
-
</auth-forgot-password-form>
|
|
993
|
-
`;
|
|
994
|
-
}
|
|
995
|
-
renderChangePasswordForm() {
|
|
996
|
-
return c`
|
|
997
|
-
<p>You have logged in successfully, but you must change your password.</p>
|
|
998
|
-
<form @submit=${this.onSubmitChangePasswordChallenge}>
|
|
999
|
-
<input type="hidden" name="username" value="${this.username}" />
|
|
1000
|
-
<label for="password">New Password</label>
|
|
995
|
+
<label for="password">Password</label>
|
|
1001
996
|
<input
|
|
1002
997
|
type="password"
|
|
1003
998
|
name="password"
|
|
1004
999
|
placeholder="Password"
|
|
1005
1000
|
required
|
|
1006
1001
|
/>
|
|
1007
|
-
<
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1002
|
+
<div>
|
|
1003
|
+
<a href="#" class="forgot"
|
|
1004
|
+
@click=${() => {
|
|
1005
|
+
this.setState(this.constructor.states.FORGOT);
|
|
1006
|
+
}}>Forgot password</a>
|
|
1007
|
+
</div>
|
|
1008
|
+
${this.errors ? this.errors.map((e) => p`<p class="error">${e}</p>`) : ""}
|
|
1009
|
+
|
|
1010
|
+
<input type="submit" value="Log in" @click=${this.handleSubmitLogin}
|
|
1011
|
+
?disabled=${this.isBusy}
|
|
1013
1012
|
/>
|
|
1014
|
-
${this.errors ? this.errors.map((e) => c`<p class="error">${e}</p>`) : ""}
|
|
1015
|
-
<input type="submit" value="Change Password" />
|
|
1016
1013
|
</form>
|
|
1017
1014
|
`;
|
|
1018
1015
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
const e = q`
|
|
1025
|
-
.login-layout {
|
|
1026
|
-
display: flex;
|
|
1027
|
-
flex-direction: column;
|
|
1028
|
-
gap: 1rem;
|
|
1029
|
-
justify-content: center;
|
|
1030
|
-
align-items: center;
|
|
1031
|
-
min-height: 100vh;
|
|
1032
|
-
background-color: var(--color-gray-100, #f5f5f5);
|
|
1033
|
-
}
|
|
1034
|
-
.login-layout > * {
|
|
1035
|
-
max-width: 400px;
|
|
1036
|
-
}
|
|
1016
|
+
renderForgotPasswordForm() {
|
|
1017
|
+
return p`
|
|
1018
|
+
<auth-forgot-password-form
|
|
1019
|
+
api=${this.api}>
|
|
1020
|
+
</auth-forgot-password-form>
|
|
1037
1021
|
`;
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1022
|
+
}
|
|
1023
|
+
renderChangePasswordForm() {
|
|
1024
|
+
return p`
|
|
1025
|
+
<p>You have logged in successfully, but you must change your password.</p>
|
|
1026
|
+
<form @submit="${this.onSubmitChangePasswordChallenge}">
|
|
1027
|
+
<input type="hidden" name="username" value="${this.username}" />
|
|
1028
|
+
<label for="password">New Password</label>
|
|
1029
|
+
<input
|
|
1030
|
+
type="password"
|
|
1031
|
+
name="password"
|
|
1032
|
+
placeholder="Password"
|
|
1033
|
+
required
|
|
1034
|
+
/>
|
|
1035
|
+
<label for="confirm-password">Confirm Password</label>
|
|
1036
|
+
<input
|
|
1037
|
+
type="password"
|
|
1038
|
+
name="confirm-password"
|
|
1039
|
+
placeholder="Confirm Password"
|
|
1040
|
+
required
|
|
1041
|
+
/>
|
|
1042
|
+
${this.errors ? this.errors.map((e) => p`<p class="error">${e}</p>`) : ""}
|
|
1043
|
+
<input type="submit" value="Change Password" />
|
|
1044
|
+
</form>
|
|
1043
1045
|
`;
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
function Ve(r) {
|
|
1047
|
-
return JSON.parse(window.atob(r.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
1048
|
-
}
|
|
1049
|
-
function Qe(r, e = 300, t = Date.now()) {
|
|
1050
|
-
return Ve(r).exp * 1e3 - e < t;
|
|
1051
|
-
}
|
|
1052
|
-
function ge(r) {
|
|
1053
|
-
return (r.startsWith("/") ? r : `/${r}`).replace(/\/{2,}/g, "/").replace(new RegExp("(?<=.)\\/$"), "");
|
|
1054
|
-
}
|
|
1055
|
-
function ye(r, e, t) {
|
|
1056
|
-
const s = Ke(r, t);
|
|
1057
|
-
e.pushState(t, t.title, s), r.requestRender(t);
|
|
1058
|
-
}
|
|
1059
|
-
function Je(r, e) {
|
|
1060
|
-
const { mount: t } = r.config, { history: s } = r.config.toolkit.element.ownerDocument.defaultView;
|
|
1061
|
-
return e.startsWith(t) ? {
|
|
1062
|
-
path: ge(e.slice(t.length)),
|
|
1063
|
-
push: (o) => ye(r, s, o)
|
|
1064
|
-
} : null;
|
|
1046
|
+
}
|
|
1065
1047
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
return
|
|
1048
|
+
customElements.get("auth-login-form") || customElements.define("auth-login-form", Be);
|
|
1049
|
+
function We(r, e) {
|
|
1050
|
+
return p`<auth-login-form slot="main"
|
|
1051
|
+
api=${r == null ? void 0 : r.apiBaseUrl}
|
|
1052
|
+
@login-success=${e}>
|
|
1053
|
+
</auth-login-form>`;
|
|
1069
1054
|
}
|
|
1070
|
-
function
|
|
1071
|
-
|
|
1072
|
-
return c`
|
|
1073
|
-
<h1>Auth Dashboard</h1>
|
|
1074
|
-
<ul>
|
|
1075
|
-
<li><a href="#" @click=${((o, i) => () => {
|
|
1076
|
-
ye(e, t, { path: o, title: i });
|
|
1077
|
-
})("/change-password")}>Change Password</a></li>
|
|
1078
|
-
<li><a href="#" @click=${e.handleDestroyAuth}>Logout</a></li>
|
|
1079
|
-
</ul>
|
|
1080
|
-
`;
|
|
1055
|
+
function Ge({ tokenKey: r }) {
|
|
1056
|
+
return window.localStorage.getItem(r);
|
|
1081
1057
|
}
|
|
1082
|
-
function
|
|
1083
|
-
|
|
1084
|
-
<auth-change-password-form .auth=${e}></auth-change-password-form>
|
|
1085
|
-
`;
|
|
1058
|
+
function Ve({ tokenKey: r }, e) {
|
|
1059
|
+
window.localStorage.setItem(r, e);
|
|
1086
1060
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
return q`
|
|
1090
|
-
:host {
|
|
1091
|
-
color: var(--color-text);
|
|
1092
|
-
display: block;
|
|
1093
|
-
font-family: var(--font-body);
|
|
1094
|
-
}
|
|
1095
|
-
h1,h2,h3,h4,h5,h6,label { font-family: var(--font-heading) }
|
|
1096
|
-
label {
|
|
1097
|
-
display: block;
|
|
1098
|
-
font-size: var(--font-size-base);
|
|
1099
|
-
margin-top: var(--spacing-md, 0.5rem);
|
|
1100
|
-
}
|
|
1101
|
-
input[type="text"],
|
|
1102
|
-
input[type="password"] {
|
|
1103
|
-
width: 100%;
|
|
1104
|
-
margin: 5px 0 15px 0;
|
|
1105
|
-
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
1106
|
-
box-sizing: border-box;
|
|
1107
|
-
border: 1px solid var(--color-gray-300, #ccc);
|
|
1108
|
-
border-radius: var(--radius-sm, 5px);
|
|
1109
|
-
color: var(--color-gray-9, #333);
|
|
1110
|
-
background-color: var(--color-gray-0, transparent);
|
|
1111
|
-
}
|
|
1112
|
-
input[type="submit"] {
|
|
1113
|
-
background-color: var(--color-primary, inherit);
|
|
1114
|
-
color: var(--color-gray-0, #fff);
|
|
1115
|
-
border: none;
|
|
1116
|
-
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
1117
|
-
border-radius: var(--radius-dynamic, 5px);
|
|
1118
|
-
width: 200px;
|
|
1119
|
-
cursor: pointer;
|
|
1120
|
-
}
|
|
1121
|
-
.error {
|
|
1122
|
-
color: var(--color-error);
|
|
1123
|
-
}
|
|
1124
|
-
`;
|
|
1125
|
-
}
|
|
1126
|
-
static get properties() {
|
|
1127
|
-
return {
|
|
1128
|
-
auth: { type: Object }
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
constructor() {
|
|
1132
|
-
super(), this.errors = {}, this.success = null;
|
|
1133
|
-
}
|
|
1134
|
-
connectedCallback() {
|
|
1135
|
-
super.connectedCallback(), Y(this);
|
|
1136
|
-
}
|
|
1137
|
-
async onSubmit(e) {
|
|
1138
|
-
if (e.preventDefault(), e.target.newPassword.value !== e.target.confirmPassword.value) {
|
|
1139
|
-
this.errors.confirmPassword = "Passwords do not match", this.requestUpdate();
|
|
1140
|
-
return;
|
|
1141
|
-
}
|
|
1142
|
-
if (e.target.newPassword.value === e.target.currentPassword.value) {
|
|
1143
|
-
this.errors.newPassword = "The new password is the same as your current password.", this.requestUpdate();
|
|
1144
|
-
return;
|
|
1145
|
-
}
|
|
1146
|
-
await Y(this), await x({
|
|
1147
|
-
baseUrl: this.auth.config.api
|
|
1148
|
-
}).updatePassword({
|
|
1149
|
-
currentPassword: e.target.currentPassword.value,
|
|
1150
|
-
newPassword: e.target.newPassword.value
|
|
1151
|
-
}).then(() => {
|
|
1152
|
-
this.errors = {}, this.success = "Password changed.", this.requestUpdate();
|
|
1153
|
-
}).catch((s) => {
|
|
1154
|
-
this.errors.submit = s.message, this.requestUpdate();
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
render() {
|
|
1158
|
-
return c`
|
|
1159
|
-
<h1>Change your password</h1>
|
|
1160
|
-
<p>Enter your current password and choose a new password.</p>
|
|
1161
|
-
<form @submit=${this.onSubmit}>
|
|
1162
|
-
<div class="field">
|
|
1163
|
-
<label for="currentPassword">Current Password</label>
|
|
1164
|
-
<input
|
|
1165
|
-
type="password"
|
|
1166
|
-
name="currentPassword"
|
|
1167
|
-
placeholder="Current Password"
|
|
1168
|
-
required
|
|
1169
|
-
/>
|
|
1170
|
-
${this.errors.currentPassword ? c`<p class="error">${this.errors.currentPassword}</p>` : ""}
|
|
1171
|
-
</div>
|
|
1172
|
-
<div class="field">
|
|
1173
|
-
<label for="newPassword">New Password</label>
|
|
1174
|
-
<input
|
|
1175
|
-
type="password"
|
|
1176
|
-
name="newPassword"
|
|
1177
|
-
placeholder="New Password"
|
|
1178
|
-
required
|
|
1179
|
-
/>
|
|
1180
|
-
${this.errors.newPassword ? c`<p class="error">${this.errors.newPassword}</p>` : ""}
|
|
1181
|
-
</div>
|
|
1182
|
-
<div class="field">
|
|
1183
|
-
<label for="confirmPassword">Confirm Password</label>
|
|
1184
|
-
<input
|
|
1185
|
-
type="password"
|
|
1186
|
-
name="confirmPassword"
|
|
1187
|
-
placeholder="Confirm Password"
|
|
1188
|
-
required
|
|
1189
|
-
/>
|
|
1190
|
-
${this.errors.confirmPassword ? c`<p class="error">${this.errors.confirmPassword}</p>` : ""}
|
|
1191
|
-
</div>
|
|
1192
|
-
<input type="submit" value="Change Password" />
|
|
1193
|
-
${this.errors.submit ? c`<p class="error">${this.errors.submit}</p>` : ""}
|
|
1194
|
-
${this.success ? c`<p class="success">${this.success}</p>` : ""}
|
|
1195
|
-
</form>
|
|
1196
|
-
`;
|
|
1197
|
-
}
|
|
1061
|
+
function Je({ tokenKey: r }) {
|
|
1062
|
+
window.localStorage.removeItem(r);
|
|
1198
1063
|
}
|
|
1199
|
-
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
if (s)
|
|
1207
|
-
return s.render(r, e);
|
|
1064
|
+
async function Qe(r) {
|
|
1065
|
+
const e = Ge(r);
|
|
1066
|
+
if (!e || e.length < 1)
|
|
1067
|
+
throw new Error("No token found");
|
|
1068
|
+
return Ke(e) ? await N({
|
|
1069
|
+
baseUrl: r.apiBaseUrl
|
|
1070
|
+
}).refreshToken({ token: e }).then(({ token: s }) => s) : e;
|
|
1208
1071
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
}
|
|
1213
|
-
`;
|
|
1214
|
-
class st extends b {
|
|
1215
|
-
static get styles() {
|
|
1216
|
-
return [rt];
|
|
1217
|
-
}
|
|
1218
|
-
static get properties() {
|
|
1219
|
-
return {
|
|
1220
|
-
state: { type: Object },
|
|
1221
|
-
auth: { type: Object }
|
|
1222
|
-
};
|
|
1223
|
-
}
|
|
1224
|
-
render() {
|
|
1225
|
-
const { state: e, auth: t } = this;
|
|
1226
|
-
return tt(e, t);
|
|
1227
|
-
}
|
|
1072
|
+
function Ke(r, e = 300, t = Date.now()) {
|
|
1073
|
+
return Ye(r).exp * 1e3 - e < t;
|
|
1228
1074
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
const e = {
|
|
1232
|
-
config: r,
|
|
1233
|
-
log: (...t) => console.log("[auth]", ...t)
|
|
1234
|
-
};
|
|
1235
|
-
return e.mount = k(ot, e), e.handleTokenRequest = nt(e), e.handleDestroyAuth = at(e), e.presentLoginForm = k(lt, e), e.getToken = k(we, e), e.saveToken = k(ct, e), e.getFreshToken = k(dt, e), e.requestRender = (t) => $e(e, t), e;
|
|
1075
|
+
function Ye(r) {
|
|
1076
|
+
return JSON.parse(window.atob(r.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
1236
1077
|
}
|
|
1237
|
-
function ot(r) {
|
|
1238
|
-
|
|
1239
|
-
[
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
handler: r.handleTokenRequest,
|
|
1245
|
-
modName: "auth"
|
|
1246
|
-
}
|
|
1078
|
+
function ot(r, e) {
|
|
1079
|
+
var n, l, a, d, h, c, m, f, y;
|
|
1080
|
+
const t = "mod-auth", s = ((a = (l = (n = e == null ? void 0 : e.element) == null ? void 0 : n.attributes) == null ? void 0 : l.debug) == null ? void 0 : a.value) || !1, o = ((c = (h = (d = e == null ? void 0 : e.element) == null ? void 0 : d.attributes) == null ? void 0 : h["force-login"]) == null ? void 0 : c.value) || !1, i = {
|
|
1081
|
+
modName: t,
|
|
1082
|
+
toolkit: r,
|
|
1083
|
+
apiBaseUrl: ((y = (f = (m = e == null ? void 0 : e.element) == null ? void 0 : m.attributes) == null ? void 0 : f.api) == null ? void 0 : y.value) || "https://api.wral.com/auth",
|
|
1084
|
+
debug: s ? (...L) => console.log("[auth]", ...L) : () => {
|
|
1247
1085
|
},
|
|
1248
|
-
{
|
|
1086
|
+
tokenKey: `${t}::token`,
|
|
1087
|
+
callbacks: [],
|
|
1088
|
+
isLoginPresent: !1
|
|
1089
|
+
};
|
|
1090
|
+
Object.entries({
|
|
1091
|
+
"auth:requestToken": Ze,
|
|
1092
|
+
"auth:destroy": Xe
|
|
1093
|
+
}).forEach(([L, pe]) => {
|
|
1094
|
+
const me = (...F) => i.debug("[action]", L, ...F);
|
|
1095
|
+
r.dispatchAction({
|
|
1249
1096
|
type: "action:register",
|
|
1250
1097
|
detail: {
|
|
1251
|
-
actionType:
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
{
|
|
1257
|
-
type: "layout:register",
|
|
1258
|
-
detail: {
|
|
1259
|
-
name: "auth:login",
|
|
1260
|
-
slots: ["main"],
|
|
1261
|
-
templateFn: Ge()
|
|
1098
|
+
actionType: L,
|
|
1099
|
+
modName: t,
|
|
1100
|
+
handler: (...F) => {
|
|
1101
|
+
me("handler", ...F), pe(i, ...F);
|
|
1102
|
+
}
|
|
1262
1103
|
}
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
function $e(r, e) {
|
|
1267
|
-
const t = r.config.toolkit.element.ownerDocument.defaultView;
|
|
1268
|
-
let s = e;
|
|
1269
|
-
s || (s = Je(r, t.location.pathname)), s && r.config.toolkit.dispatchAction({
|
|
1270
|
-
type: "layout:slot:replace",
|
|
1104
|
+
});
|
|
1105
|
+
}), r.dispatchAction({
|
|
1106
|
+
type: "layout:register",
|
|
1271
1107
|
detail: {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
content: c`<auth-app .state=${s} .auth=${r}></auth-app>`
|
|
1108
|
+
name: `${t}::auth-layout`,
|
|
1109
|
+
templateFn: Le
|
|
1275
1110
|
}
|
|
1276
|
-
});
|
|
1111
|
+
}), o && fe(e.element);
|
|
1277
1112
|
}
|
|
1278
|
-
function
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
e.forEach((i) => {
|
|
1287
|
-
i(o);
|
|
1288
|
-
}), e = [];
|
|
1289
|
-
};
|
|
1290
|
-
return async ({ callback: o }) => {
|
|
1291
|
-
let i;
|
|
1292
|
-
try {
|
|
1293
|
-
i = await r.getFreshToken(), o(i);
|
|
1294
|
-
} catch (n) {
|
|
1295
|
-
e.push(o), t || (r.presentLoginForm({ onLogin: s }), t = !0), r.log(n);
|
|
1296
|
-
}
|
|
1297
|
-
};
|
|
1113
|
+
async function Ze(r, e) {
|
|
1114
|
+
const { callback: t } = e;
|
|
1115
|
+
let s;
|
|
1116
|
+
try {
|
|
1117
|
+
s = await Qe(r), t(s);
|
|
1118
|
+
} catch (o) {
|
|
1119
|
+
console.log("Presenting login form to get a fresh token", o), r.callbacks.push(t), r.isLoginPresent || et(r);
|
|
1120
|
+
}
|
|
1298
1121
|
}
|
|
1299
|
-
function
|
|
1300
|
-
|
|
1301
|
-
const e = K(r);
|
|
1302
|
-
window.localStorage.removeItem(e), r.config.toolkit.dispatchAction({
|
|
1303
|
-
type: "layout:pop"
|
|
1304
|
-
});
|
|
1305
|
-
};
|
|
1122
|
+
function Xe(r) {
|
|
1123
|
+
Je(r);
|
|
1306
1124
|
}
|
|
1307
|
-
function
|
|
1308
|
-
|
|
1309
|
-
t.element.ownerDocument.defaultView.location.search
|
|
1310
|
-
).get("password_reset_confirmation"), i = (n) => {
|
|
1311
|
-
r.log("login success", { event: n });
|
|
1312
|
-
const { token: l } = n.detail;
|
|
1313
|
-
r.log("Login form dismissed", { args: [l] }), t.dispatchAction({
|
|
1314
|
-
type: "layout:pop"
|
|
1315
|
-
}), r.saveToken({ token: l }), e({ token: l });
|
|
1316
|
-
};
|
|
1317
|
-
t.dispatchAction({
|
|
1125
|
+
function et(r) {
|
|
1126
|
+
r.isLoginPresent = !0, r.toolkit.dispatchAction({
|
|
1318
1127
|
type: "layout:push",
|
|
1319
1128
|
detail: {
|
|
1320
|
-
|
|
1129
|
+
name: `${r.modName}::auth-layout`
|
|
1321
1130
|
}
|
|
1322
|
-
}),
|
|
1323
|
-
type: "layout:
|
|
1131
|
+
}), r.toolkit.dispatchAction({
|
|
1132
|
+
type: "layout:content:append",
|
|
1324
1133
|
detail: {
|
|
1325
|
-
|
|
1326
|
-
slot: "main",
|
|
1327
|
-
content: c`<auth-login-form
|
|
1328
|
-
api=${r.config.api}
|
|
1329
|
-
confirmation="${o}"
|
|
1330
|
-
@login-success=${i}>
|
|
1331
|
-
</auth-login-form>`
|
|
1134
|
+
content: We(r, tt(r))
|
|
1332
1135
|
}
|
|
1333
1136
|
});
|
|
1334
1137
|
}
|
|
1335
|
-
function
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
return window.localStorage.getItem(e);
|
|
1343
|
-
}
|
|
1344
|
-
async function dt(r) {
|
|
1345
|
-
const e = we(r);
|
|
1346
|
-
if (!e || e.length < 1)
|
|
1347
|
-
throw new Error("No token found");
|
|
1348
|
-
return Qe(e) ? (r.log("refreshing token", { args: [e] }), await x({
|
|
1349
|
-
baseUrl: r.config.api
|
|
1350
|
-
}).refreshToken({ token: e }).then(({ token: s }) => s)) : e;
|
|
1351
|
-
}
|
|
1352
|
-
function K({ storageKey: r = "token" }) {
|
|
1353
|
-
return r;
|
|
1138
|
+
function tt(r) {
|
|
1139
|
+
return (e) => {
|
|
1140
|
+
const { token: t } = e.detail;
|
|
1141
|
+
Ve(r, t), r.callbacks.forEach((s) => s(t)), r.callbacks = [], r.isLoginPresent = !1, r.toolkit.dispatchAction({
|
|
1142
|
+
type: "layout:pop"
|
|
1143
|
+
});
|
|
1144
|
+
};
|
|
1354
1145
|
}
|
|
1355
1146
|
export {
|
|
1356
|
-
|
|
1357
|
-
we as getToken,
|
|
1358
|
-
K as getTokenStorageKey,
|
|
1359
|
-
it as historyStateHandler,
|
|
1360
|
-
at as loginDestroyHandler,
|
|
1361
|
-
pt as makeAuth,
|
|
1362
|
-
ot as mount,
|
|
1363
|
-
lt as presentLoginForm,
|
|
1364
|
-
$e as renderApp,
|
|
1365
|
-
ct as saveToken,
|
|
1366
|
-
nt as tokenRequestHandler
|
|
1147
|
+
ot as init
|
|
1367
1148
|
};
|