@wral/studio.mods.auth 1.0.1 → 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/dist/auth.cjs.js +119 -205
- package/dist/auth.es.js +466 -696
- 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/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/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Vellum Auth Mod
|
|
2
2
|
|
|
3
|
-
This mod provides an Authentication mechanism via JWTs.
|
|
3
|
+
This mod provides an Authentication mechanism via JWTs. This mod is compatible
|
|
4
|
+
with Vellum 1.0.
|
|
4
5
|
|
|
5
6
|
## Usage
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ In a vellum project, add the following mod:
|
|
|
8
9
|
|
|
9
10
|
```html
|
|
10
11
|
<vellum-app>
|
|
11
|
-
<vellum-mod name="auth" src="https://cdn.wral.studio/mods/auth/release/
|
|
12
|
+
<vellum-mod name="auth" src="https://cdn.wral.studio/mods/auth/release/v2.0.0/auth.es.js"
|
|
12
13
|
api="https://api.wral.com/auth"
|
|
13
14
|
force-login>
|
|
14
15
|
</vellum-mod>
|
|
@@ -18,7 +19,6 @@ In a vellum project, add the following mod:
|
|
|
18
19
|
### Attributes
|
|
19
20
|
* `api`: _required_ auth api endpoint (without version or trailing slash)
|
|
20
21
|
* `force-login`: _optional_ force login on first page load
|
|
21
|
-
* session-key: _optional_ session key to use. Defaults to `token`
|
|
22
22
|
|
|
23
23
|
### Requesting an auth token
|
|
24
24
|
|
package/dist/auth.cjs.js
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe=require("./lib.cjs.js");/**
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/const
|
|
5
|
+
*/const q=globalThis,G=q.ShadowRoot&&(q.ShadyCSS===void 0||q.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,V=Symbol(),K=new WeakMap;let ae=class{constructor(e,t,s){if(this._$cssResult$=!0,s!==V)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(G&&e===void 0){const s=t!==void 0&&t.length===1;s&&(e=K.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),s&&K.set(t,e))}return e}toString(){return this.cssText}};const ge=r=>new ae(typeof r=="string"?r:r+"",void 0,V),J=(r,...e)=>{const t=r.length===1?r[0]:e.reduce((s,o,i)=>s+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;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.")})(o)+r[i+1],r[0]);return new ae(t,r,V)},$e=(r,e)=>{if(G)r.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const s=document.createElement("style"),o=q.litNonce;o!==void 0&&s.setAttribute("nonce",o),s.textContent=t.cssText,r.appendChild(s)}},Y=G?r=>r:r=>r instanceof CSSStyleSheet?(e=>{let t="";for(const s of e.cssRules)t+=s.cssText;return ge(t)})(r):r;/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2017 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const{is:
|
|
9
|
+
*/const{is:ye,defineProperty:be,getOwnPropertyDescriptor:_e,getOwnPropertyNames:ve,getOwnPropertySymbols:we,getPrototypeOf:Ae}=Object,$=globalThis,Z=$.trustedTypes,Ee=Z?Z.emptyScript:"",I=$.reactiveElementPolyfillSupport,U=(r,e)=>r,W={toAttribute(r,e){switch(e){case Boolean:r=r?Ee:null;break;case Object:case Array:r=r==null?r:JSON.stringify(r)}return r},fromAttribute(r,e){let t=r;switch(e){case Boolean:t=r!==null;break;case Number:t=r===null?null:Number(r);break;case Object:case Array:try{t=JSON.parse(r)}catch{t=null}}return t}},le=(r,e)=>!ye(r,e),X={attribute:!0,type:String,converter:W,reflect:!1,hasChanged:le};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),$.litPropertyMetadata??($.litPropertyMetadata=new WeakMap);class S extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=X){if(t.state&&(t.attribute=!1),this._$Ei(),this.elementProperties.set(e,t),!t.noAccessor){const s=Symbol(),o=this.getPropertyDescriptor(e,s,t);o!==void 0&&be(this.prototype,e,o)}}static getPropertyDescriptor(e,t,s){const{get:o,set:i}=_e(this.prototype,e)??{get(){return this[t]},set(n){this[t]=n}};return{get(){return o==null?void 0:o.call(this)},set(n){const l=o==null?void 0:o.call(this);i.call(this,n),this.requestUpdate(e,l,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??X}static _$Ei(){if(this.hasOwnProperty(U("elementProperties")))return;const e=Ae(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(U("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(U("properties"))){const t=this.properties,s=[...ve(t),...we(t)];for(const o of s)this.createProperty(o,t[o])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[s,o]of t)this.elementProperties.set(s,o)}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const o=this._$Eu(t,s);o!==void 0&&this._$Eh.set(o,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const s=new Set(e.flat(1/0).reverse());for(const o of s)t.unshift(Y(o))}else e!==void 0&&t.push(Y(e));return t}static _$Eu(e,t){const s=t.attribute;return s===!1?void 0:typeof s=="string"?s:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var e;this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),(e=this.constructor.l)==null||e.forEach(t=>t(this))}addController(e){var t;(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&((t=e.hostConnected)==null||t.call(e))}removeController(e){var t;(t=this._$EO)==null||t.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const s of t.keys())this.hasOwnProperty(s)&&(e.set(s,this[s]),delete this[s]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return $e(e,this.constructor.elementStyles),e}connectedCallback(){var e;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(e=this._$EO)==null||e.forEach(t=>{var s;return(s=t.hostConnected)==null?void 0:s.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var s;return(s=t.hostDisconnected)==null?void 0:s.call(t)})}attributeChangedCallback(e,t,s){this._$AK(e,s)}_$EC(e,t){var i;const s=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,s);if(o!==void 0&&s.reflect===!0){const n=(((i=s.converter)==null?void 0:i.toAttribute)!==void 0?s.converter:W).toAttribute(t,s.type);this._$Em=e,n==null?this.removeAttribute(o):this.setAttribute(o,n),this._$Em=null}}_$AK(e,t){var i;const s=this.constructor,o=s._$Eh.get(e);if(o!==void 0&&this._$Em!==o){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;this._$Em=o,this[o]=l.fromAttribute(t,n.type),this._$Em=null}}requestUpdate(e,t,s){if(e!==void 0){if(s??(s=this.constructor.getPropertyOptions(e)),!(s.hasChanged??le)(this[e],t))return;this.P(e,t,s)}this.isUpdatePending===!1&&(this._$ES=this._$ET())}P(e,t,s){this._$AL.has(e)||this._$AL.set(e,t),s.reflect===!0&&this._$Em!==e&&(this._$Ej??(this._$Ej=new Set)).add(e)}async _$ET(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var s;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[i,n]of this._$Ep)this[i]=n;this._$Ep=void 0}const o=this.constructor.elementProperties;if(o.size>0)for(const[i,n]of o)n.wrapped!==!0||this._$AL.has(i)||this[i]===void 0||this.P(i,this[i],n)}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),(s=this._$EO)==null||s.forEach(o=>{var i;return(i=o.hostUpdate)==null?void 0:i.call(o)}),this.update(t)):this._$EU()}catch(o){throw e=!1,this._$EU(),o}e&&this._$AE(t)}willUpdate(e){}_$AE(e){var t;(t=this._$EO)==null||t.forEach(s=>{var o;return(o=s.hostUpdated)==null?void 0:o.call(s)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Ej&&(this._$Ej=this._$Ej.forEach(t=>this._$EC(t,this[t]))),this._$EU()}updated(e){}firstUpdated(e){}}S.elementStyles=[],S.shadowRootOptions={mode:"open"},S[U("elementProperties")]=new Map,S[U("finalized")]=new Map,I==null||I({ReactiveElement:S}),($.reactiveElementVersions??($.reactiveElementVersions=[])).push("2.0.4");/**
|
|
10
10
|
* @license
|
|
11
11
|
* Copyright 2017 Google LLC
|
|
12
12
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
13
|
-
*/const
|
|
14
|
-
\f\r]`,
|
|
15
|
-
\f\r"'\`<>=]|("|')|))|$)`,"g"),
|
|
13
|
+
*/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=`[
|
|
14
|
+
\f\r]`,x=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,te=/-->/g,se=/>/g,b=RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^
|
|
15
|
+
\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=new WeakMap,v=A.createTreeWalker(A,129);function ue(r,e){if(!Q(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return ee!==void 0?ee.createHTML(e):e}const xe=(r,e)=>{const t=r.length-1,s=[];let o,i=e===2?"<svg>":e===3?"<math>":"",n=x;for(let l=0;l<t;l++){const a=r[l];let d,h,c=-1,m=0;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);const f=n===b&&r[l+1].startsWith("/>")?" ":"";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)}return[ue(r,i+(r[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),s]};class R{constructor({strings:e,_$litType$:t},s){let o;this.parts=[];let i=0,n=0;const l=e.length-1,a=this.parts,[d,h]=xe(e,t);if(this.el=R.createElement(d,s),v.currentNode=this.el.content,t===2||t===3){const c=this.el.content.firstChild;c.replaceWith(...c.childNodes)}for(;(o=v.nextNode())!==null&&a.length<l;){if(o.nodeType===1){if(o.hasAttributes())for(const c of o.getAttributeNames())if(c.endsWith(he)){const m=h[n++],f=o.getAttribute(c).split(g),y=/([.?@])?(.*)/.exec(m);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)}else c.startsWith(g)&&(a.push({type:6,index:i}),o.removeAttribute(c));if(de.test(o.tagName)){const c=o.textContent.split(g),m=c.length-1;if(m>0){o.textContent=M?M.emptyScript:"";for(let f=0;f<m;f++)o.append(c[f],k()),v.nextNode(),a.push({type:2,index:++i});o.append(c[m],k())}}}else if(o.nodeType===8)if(o.data===ce)a.push({type:2,index:i});else{let c=-1;for(;(c=o.data.indexOf(g,c+1))!==-1;)a.push({type:7,index:i}),c+=g.length-1}i++}}static createElement(e,t){const s=A.createElement("template");return s.innerHTML=e,s}}function P(r,e,t=r,s){var n,l;if(e===C)return e;let o=s!==void 0?(n=t._$Co)==null?void 0:n[s]:t._$Cl;const i=O(e)?void 0:e._$litDirective$;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}class Ue{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:s}=this._$AD,o=((e==null?void 0:e.creationScope)??A).importNode(t,!0);v.currentNode=o;let i=v.nextNode(),n=0,l=0,a=s[0];for(;a!==void 0;){if(n===a.index){let d;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]}n!==(a==null?void 0:a.index)&&(i=v.nextNode(),n++)}return v.currentNode=A,o}p(e){let t=0;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++}}class H{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,s,o){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}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){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)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==u&&O(this._$AH)?this._$AA.nextSibling.data=e:this.T(A.createTextNode(e)),this._$AH=e}$(e){var i;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);if(((i=this._$AH)==null?void 0:i._$AD)===o)this._$AH.p(t);else{const n=new Ue(o,this),l=n.u(this.options);n.p(t),this.T(l),this._$AH=n}}_$AC(e){let t=ie.get(e.strings);return t===void 0&&ie.set(e.strings,t=new R(e)),t}k(e){Q(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let s,o=0;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++;o<t.length&&(this._$AR(s&&s._$AB.nextSibling,o),t.length=o)}_$AR(e=this._$AA.nextSibling,t){var s;for((s=this._$AP)==null?void 0:s.call(this,!1,!0,t);e&&e!==this._$AB;){const o=e.nextSibling;e.remove(),e=o}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class D{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,s,o,i){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}_$AI(e,t=this,s,o){const i=this.strings;let n=!1;if(i===void 0)e=P(this,e,t,0),n=!O(e)||e!==this._$AH&&e!==C,n&&(this._$AH=e);else{const l=e;let a,d;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}n&&!o&&this.j(e)}j(e){e===u?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Te extends D{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===u?void 0:e}}class ke extends D{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==u)}}class Oe extends D{constructor(e,t,s,o,i){super(e,t,s,o,i),this.type=5}_$AI(e,t=this){if((e=P(this,e,t,0)??u)===C)return;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);o&&this.element.removeEventListener(this.name,this,s),i&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class Re{constructor(e,t,s){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(e){P(this,e)}}const j=T.litHtmlPolyfillSupport;j==null||j(R,H),(T.litHtmlVersions??(T.litHtmlVersions=[])).push("3.2.1");const Ne=(r,e,t)=>{const s=(t==null?void 0:t.renderBefore)??e;let o=s._$litPart$;if(o===void 0){const i=(t==null?void 0:t.renderBefore)??null;s._$litPart$=o=new H(e.insertBefore(k(),i),i,void 0,t??{})}return o._$AI(r),o};/**
|
|
16
16
|
* @license
|
|
17
17
|
* Copyright 2017 Google LLC
|
|
18
18
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
19
|
-
*/class
|
|
19
|
+
*/class w extends S{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t;const e=super.createRenderRoot();return(t=this.renderOptions).renderBefore??(t.renderBefore=e.firstChild),e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=Ne(t,this.renderRoot,this.renderOptions)}connectedCallback(){var e;super.connectedCallback(),(e=this._$Do)==null||e.setConnected(!0)}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this._$Do)==null||e.setConnected(!1)}render(){return C}}var ne;w._$litElement$=!0,w.finalized=!0,(ne=globalThis.litElementHydrateSupport)==null||ne.call(globalThis,{LitElement:w});const B=globalThis.litElementPolyfillSupport;B==null||B({LitElement:w});(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.1.1");class He extends w{static get styles(){return J`
|
|
20
|
+
.login-layout {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
gap: 1rem;
|
|
24
|
+
justify-content: center;
|
|
25
|
+
align-items: center;
|
|
26
|
+
min-height: 100vh;
|
|
27
|
+
background-color: var(--color-gray-100);
|
|
28
|
+
}
|
|
29
|
+
.login-layout > * {
|
|
30
|
+
max-width: 400px;
|
|
31
|
+
}
|
|
32
|
+
`}render(){return p`
|
|
33
|
+
<div class="login-layout">
|
|
34
|
+
<slot name="main"></slot>
|
|
35
|
+
</div>
|
|
36
|
+
`}}customElements.get("mod-auth-layout")===void 0&&customElements.define("mod-auth-layout",He);function Le(){return p`<mod-auth-layout></mod-auth-layout>`}function N(r){return{api:(e,t)=>E(r,e,t),mintToken:({username:e,password:t})=>Fe({config:r,username:e,password:t}),refreshToken:({token:e})=>qe({config:r,token:e}),pubkey:()=>Me({config:r}),updatePassword:({token:e,currentPassword:t,newPassword:s})=>De({config:r,token:e,currentPassword:t,newPassword:s}),triggerResetPassword:({username:e})=>Ie({config:r,username:e}),confirmResetPassword:({username:e,newPassword:t,confirmationCode:s})=>ze({config:r,username:e,newPassword:t,confirmationCode:s})}}function Fe({config:r,username:e,password:t}){return E(r,"/v1/user/login",{method:"POST",body:{username:e,password:t}})}function qe({config:r,token:e}){return E(r,"/v1/refresh",{method:"POST",body:{token:e}})}function Me({config:r}){return E(r,"/v1/pubkey",{method:"GET"})}function De({config:r,token:e,currentPassword:t,newPassword:s}){return E(r,"/v1/user/password",{method:"PUT",body:{currentPassword:t,newPassword:s},headers:{Authorization:`Bearer ${e}`}})}function Ie({config:r,username:e}){return E(r,"/v1/user/password/reset",{method:"POST",body:{username:e}})}function ze({config:r,username:e,newPassword:t,confirmationCode:s}){return E(r,"/v1/user/password/reset/confirm",{method:"POST",body:{username:e,newPassword:t,confirmationCode:s}})}async function E(r,e,t){var d;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,{headers:Object.assign({},{"Content-Type":"application/json"},t==null?void 0:t.headers),body:t!=null&&t.body?JSON.stringify(t.body):void 0}),a=await fetch(i.toString(),l);if(!a.ok){const h=new Error("API request failed.");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"))try{h.body=await a.json()}catch{h.body="Failed to parse response body."}throw h}if(a.status!==204)return await a.json()}const _=Object.freeze({REQUEST:"request",CONFIRM:"confirm",FINISHED:"finished"});class je extends w{static get properties(){return{api:{type:String}}}static get styles(){return J`
|
|
20
37
|
:host {
|
|
21
|
-
display:
|
|
22
|
-
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: column;
|
|
40
|
+
justify-content: center;
|
|
41
|
+
align-items: center;
|
|
42
|
+
}
|
|
43
|
+
form {
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
23
46
|
}
|
|
24
47
|
form input[type="text"],
|
|
25
48
|
form input[type="password"] {
|
|
@@ -27,14 +50,14 @@
|
|
|
27
50
|
margin: 5px 0 15px 0;
|
|
28
51
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
29
52
|
box-sizing: border-box;
|
|
30
|
-
border: 1px solid var(--color-gray-300, #
|
|
31
|
-
border-radius: var(--radius-sm,
|
|
32
|
-
color: var(--color-gray-
|
|
33
|
-
background-color: var(--color-gray-
|
|
53
|
+
border: 1px solid var(--color-gray-300, #CCC);
|
|
54
|
+
border-radius: var(--radius-sm, 3px);
|
|
55
|
+
color: var(--color-gray-700, #333);
|
|
56
|
+
background-color: var(--color-gray-50, #FFF);
|
|
34
57
|
}
|
|
35
58
|
form input[type="submit"] {
|
|
36
|
-
background-color:var(--color-primary, inherit);
|
|
37
|
-
color: var(--color-gray-
|
|
59
|
+
background-color: var(--color-primary, inherit);
|
|
60
|
+
color: var(--color-gray-50, #fff);
|
|
38
61
|
border: none;
|
|
39
62
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
40
63
|
border-radius: var(--radius-dynamic, 5px);
|
|
@@ -45,16 +68,16 @@
|
|
|
45
68
|
}
|
|
46
69
|
form label {
|
|
47
70
|
font-size: 14px;
|
|
48
|
-
color: var(--color-gray-
|
|
71
|
+
color: var(--color-gray-700, #333);
|
|
49
72
|
font-weight: bold;
|
|
50
73
|
margin-bottom: var(--spacing-sm, 0.5rem);
|
|
51
74
|
}
|
|
52
75
|
.error {
|
|
53
76
|
color: var(--color-danger, red);
|
|
54
|
-
font-size:
|
|
77
|
+
font-size: 14px;
|
|
55
78
|
}
|
|
56
|
-
`}constructor(){super(),this.errors={},this.stage=
|
|
57
|
-
|
|
79
|
+
`}constructor(){super(),this.errors={},this.stage=_.REQUEST}connectedCallback(){super.connectedCallback(),this.confirmToken&&this.stage!==_.FINISHED&&this.setStage(_.CONFIRM)}setStage(e){this.stage!==e&&(this.stage=e,this.requestUpdate())}handleSubmitRequest(e){e.preventDefault();const t=e.target.username.value;this.username=t,N({baseUrl:this.api}).triggerResetPassword({username:t}).then(()=>{this.setStage(_.CONFIRM)}).catch(o=>{this.errors.general=o.message||"Unable to send password reset request. Please try again later."}).finally(()=>{this.requestUpdate()})}handleSubmitConfirm(e){e.preventDefault();const t=e.target.password.value,s=e.target["confirm-password"].value;if(t!==s){this.errors["confirm-password"]="Passwords do not match",this.requestUpdate();return}const o=this.confirmToken||e.target.confirmation.value;if(!o){this.errors.general="Confirmation code is required",this.requestUpdate();return}const i=N({baseUrl:this.api});i.confirmResetPassword({username:this.username,newPassword:t,confirmationCode:o}).then(()=>{i.mintToken({username:this.username,password:t}).then(({token:n})=>{this.dispatchEvent(new CustomEvent("login-success",{detail:{token:n},bubbles:!0,composed:!0,cancelable:!0}))})}).catch(n=>{this.errors.general=n.message||"Unable to send password reset request. Please try again later."}).finally(()=>{this.requestUpdate()})}render(){switch(this.stage){case _.FINISHED:return p`<p>Your password has been reset.</p>`;case _.CONFIRM:return this.renderConfirmForm();case _.REQUEST:default:return this.renderRequestForm()}}renderRequestForm(){return p`<form @submit="${this.handleSubmitRequest}">
|
|
80
|
+
<p>Enter your username or email address to request a password reset.</p>
|
|
58
81
|
<label for="username">Username/Email</label>
|
|
59
82
|
<input
|
|
60
83
|
type="text"
|
|
@@ -63,17 +86,17 @@
|
|
|
63
86
|
required
|
|
64
87
|
/>
|
|
65
88
|
<p class="error">${this.errors.general}</p>
|
|
66
|
-
<input type="submit" value="Request
|
|
67
|
-
</form>`}renderConfirmForm(){return
|
|
68
|
-
|
|
89
|
+
<input type="submit" value="Request Password Reset" />
|
|
90
|
+
</form>`}renderConfirmForm(){return p`<form @submit="${this.handleSubmitConfirm}">
|
|
91
|
+
<p>You should have received a confirmation code to reset your password.</p>
|
|
69
92
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
93
|
+
${this.confirmToken?"":p`<label for="confirmation">Confirmation Code</label>
|
|
94
|
+
<input
|
|
95
|
+
type="text"
|
|
96
|
+
name="confirmation"
|
|
97
|
+
placeholder="Confirmation Code"
|
|
98
|
+
required
|
|
99
|
+
/>`}
|
|
77
100
|
|
|
78
101
|
<label for="password">New Password</label>
|
|
79
102
|
<input
|
|
@@ -82,8 +105,6 @@
|
|
|
82
105
|
placeholder="Password"
|
|
83
106
|
required
|
|
84
107
|
/>
|
|
85
|
-
${this.errors.password?c`<p class="error">${this.errors.password}</p>`:""}
|
|
86
|
-
|
|
87
108
|
<label for="confirm-password">Confirm Password</label>
|
|
88
109
|
<input
|
|
89
110
|
type="password"
|
|
@@ -91,17 +112,17 @@
|
|
|
91
112
|
placeholder="Confirm Password"
|
|
92
113
|
required
|
|
93
114
|
/>
|
|
94
|
-
${this.errors["confirm-password"]?
|
|
115
|
+
${this.errors["confirm-password"]?p`<p class="error">${this.errors["confirm-password"]}</p>`:""}
|
|
116
|
+
|
|
117
|
+
${this.errors.general?p`<p class="error">${this.errors.general}</p>`:""}
|
|
95
118
|
|
|
96
|
-
${this.errors.general?c`<p class="error">${this.errors.general}</p>`:""}
|
|
97
119
|
<input type="submit" value="Reset Password" />
|
|
98
|
-
</form>`}}class
|
|
120
|
+
</form>`}}customElements.get("auth-forgot-password-form")||window.customElements.define("auth-forgot-password-form",je);class Be extends w{static get properties(){return{api:{type:String,attribute:"api"}}}static get styles(){return J`
|
|
99
121
|
:host {
|
|
100
122
|
display: block;
|
|
101
|
-
font-family: Arial, sans-serif;
|
|
102
123
|
}
|
|
103
124
|
.login-form {
|
|
104
|
-
background-color: var(--color-gray-
|
|
125
|
+
background-color: var(--color-gray-50);
|
|
105
126
|
padding: var(--spacing-xl, 3rem);
|
|
106
127
|
border-radius: var(--radius-md, 5px);
|
|
107
128
|
box-shadow: var(--drop-shadow-md, none);
|
|
@@ -112,14 +133,14 @@
|
|
|
112
133
|
margin: 5px 0 15px 0;
|
|
113
134
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
114
135
|
box-sizing: border-box;
|
|
115
|
-
border: 1px solid var(--color-gray-300, #
|
|
116
|
-
border-radius: var(--radius-sm,
|
|
117
|
-
color: var(--color-gray-
|
|
118
|
-
background-color: var(--color-gray-
|
|
136
|
+
border: 1px solid var(--color-gray-300, #CCC);
|
|
137
|
+
border-radius: var(--radius-sm, 3px);
|
|
138
|
+
color: var(--color-gray-700, #333);
|
|
139
|
+
background-color: var(--color-gray-100, #FFF);
|
|
119
140
|
}
|
|
120
141
|
form input[type="submit"] {
|
|
121
142
|
background-color: var(--color-primary, inherit);
|
|
122
|
-
color: var(--color-gray-
|
|
143
|
+
color: var(--color-gray-50, #fff);
|
|
123
144
|
border: none;
|
|
124
145
|
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
125
146
|
border-radius: var(--radius-dynamic, 5px);
|
|
@@ -130,15 +151,15 @@
|
|
|
130
151
|
}
|
|
131
152
|
form label {
|
|
132
153
|
font-size: 14px;
|
|
133
|
-
color: var(--color-gray-
|
|
154
|
+
color: var(--color-gray-900, #333);
|
|
134
155
|
font-weight: bold;
|
|
135
156
|
margin-bottom: var(--spacing-sm, 0.5rem);
|
|
136
157
|
}
|
|
137
158
|
a.forgot {
|
|
138
159
|
color: var(--color-primary, inherit);
|
|
139
160
|
text-decoration: none;
|
|
140
|
-
font-size: 12px;
|
|
141
161
|
font-weight: bold;
|
|
162
|
+
font-size: 12px;
|
|
142
163
|
}
|
|
143
164
|
.error {
|
|
144
165
|
color: var(--color-error, red);
|
|
@@ -153,7 +174,7 @@
|
|
|
153
174
|
.header .intro {
|
|
154
175
|
width: 200px;
|
|
155
176
|
margin-bottom: 0;
|
|
156
|
-
color: var(--color-gray-
|
|
177
|
+
color: var(--color-gray-300, #333);
|
|
157
178
|
}
|
|
158
179
|
.header .brand {
|
|
159
180
|
font-size: 32px;
|
|
@@ -165,174 +186,67 @@
|
|
|
165
186
|
font-weight: bold;
|
|
166
187
|
font-style: normal;
|
|
167
188
|
}
|
|
168
|
-
`}static get states(){return{DEFAULT:"DEFAULT",FORGOT:"FORGOT",CHALLENGE_CHANGE_PW:"CHALLENGE_CHANGE_PW"}}constructor(){super(),this.formState=
|
|
189
|
+
`}static get states(){return{DEFAULT:"DEFAULT",FORGOT:"FORGOT",CHALLENGE_CHANGE_PW:"CHALLENGE_CHANGE_PW"}}constructor(){super(),this.formState=this.constructor.states.DEFAULT,this.errors=[],this.isBusy=!1}login({username:e,password:t}){return N({baseUrl:this.api}).mintToken({username:e,password:t})}emitLoginSuccess(e){this.dispatchEvent(new CustomEvent("login-success",{detail:{token:e},bubbles:!0,composed:!0,cancelable:!0}))}handleSubmitLogin(e){e.preventDefault();const t=e.explicitOriginalTarget.parentElement,s=new FormData(t).entries().reduce((o,[i,n])=>(o[i]=n,o),{});this.isBusy=!0,this.errors=[],this.requestUpdate(),this.login(s).then(({token:o,challenge:i})=>{if((i==null?void 0:i.name)==="NEW_PASSWORD_REQUIRED"){this.token=o,this.username=s.username,this.password=s.password,this.setState(this.constructor.states.CHALLENGE_CHANGE_PW);return}this.emitLoginSuccess(o)}).catch(o=>{console.error(o),this.errors=[o.message],this.requestUpdate()})}onSubmitChangePasswordChallenge(e){e.preventDefault();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"];if(o!==i){this.errors=["Passwords do not match"],this.requestUpdate();return}N({baseUrl:this.api}).updatePassword({token:this.token,currentPassword:this.password,newPassword:o}).then(()=>{this.emitLoginSuccess(this.token)}).catch(l=>{console.error(l),this.errors=[l.message],this.requestUpdate()})}setState(e){this.formState=e,this.isBusy=!1,this.errors=[],this.requestUpdate()}render(){return p`<div class="login-form">
|
|
169
190
|
${this.renderHeader()}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
</div>`}renderHeader(){return
|
|
174
|
-
<div class="intro">
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
<
|
|
178
|
-
<
|
|
179
|
-
</div>
|
|
180
|
-
</div>`}renderLoginForm(){return c`
|
|
181
|
-
<form>
|
|
182
|
-
<label for="username">User</label>
|
|
183
|
-
<input
|
|
184
|
-
type="text"
|
|
185
|
-
name="username"
|
|
186
|
-
placeholder="Email or Username"
|
|
187
|
-
required
|
|
188
|
-
/>
|
|
189
|
-
|
|
190
|
-
<label for="password">Password</label>
|
|
191
|
-
<input
|
|
192
|
-
type="password"
|
|
193
|
-
name="password"
|
|
194
|
-
placeholder="Password"
|
|
195
|
-
required
|
|
196
|
-
/>
|
|
197
|
-
<div>
|
|
198
|
-
<a href="#" class="forgot"
|
|
199
|
-
@click=${()=>{this.setState(y.states.FORGOT)}}
|
|
200
|
-
>Forgot password</a>
|
|
201
|
-
</div>
|
|
202
|
-
|
|
203
|
-
${this.errors?this.errors.map(e=>c`<p class="error">${e}</p>`):""}
|
|
204
|
-
<input type="submit" value="Log in" @click=${this.onSubmit} />
|
|
205
|
-
|
|
206
|
-
</form>`}renderForgotPasswordForm(){return c`
|
|
207
|
-
<auth-forgot-password-form
|
|
208
|
-
api=${this.api}>
|
|
209
|
-
</auth-forgot-password-form>
|
|
210
|
-
`}renderChangePasswordForm(){return c`
|
|
211
|
-
<p>You have logged in successfully, but you must change your password.</p>
|
|
212
|
-
<form @submit=${this.onSubmitChangePasswordChallenge}>
|
|
213
|
-
<input type="hidden" name="username" value="${this.username}" />
|
|
214
|
-
<label for="password">New Password</label>
|
|
191
|
+
${this.formState===this.constructor.states.DEFAULT?this.renderLoginForm():""}
|
|
192
|
+
${this.formState===this.constructor.states.CHALLENGE_CHANGE_PW?this.renderChangePasswordForm():""}
|
|
193
|
+
${this.formState===this.constructor.states.FORGOT?this.renderForgotPasswordForm():""}
|
|
194
|
+
</div>`}renderHeader(){return p`<div class="header">
|
|
195
|
+
<div class="intro">Welcome to</div>
|
|
196
|
+
<div class="brand"><em>WRAL</em>.studio</div>
|
|
197
|
+
</div>`}renderLoginForm(){return p`
|
|
198
|
+
<form>
|
|
199
|
+
<label for="username">User</label>
|
|
215
200
|
<input
|
|
216
|
-
type="
|
|
217
|
-
name="
|
|
218
|
-
placeholder="
|
|
201
|
+
type="text"
|
|
202
|
+
name="username"
|
|
203
|
+
placeholder="Email or Username"
|
|
219
204
|
required
|
|
220
205
|
/>
|
|
221
|
-
|
|
206
|
+
|
|
207
|
+
<label for="password">Password</label>
|
|
222
208
|
<input
|
|
223
209
|
type="password"
|
|
224
|
-
name="
|
|
225
|
-
placeholder="
|
|
210
|
+
name="password"
|
|
211
|
+
placeholder="Password"
|
|
226
212
|
required
|
|
227
213
|
/>
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
`}}customElements.define("auth-login-form",y);customElements.define("auth-forgot-password-form",Ve);function Ke(){return function(s){const e=q`
|
|
232
|
-
.login-layout {
|
|
233
|
-
display: flex;
|
|
234
|
-
flex-direction: column;
|
|
235
|
-
gap: 1rem;
|
|
236
|
-
justify-content: center;
|
|
237
|
-
align-items: center;
|
|
238
|
-
min-height: 100vh;
|
|
239
|
-
background-color: var(--color-gray-100, #f5f5f5);
|
|
240
|
-
}
|
|
241
|
-
.login-layout > * {
|
|
242
|
-
max-width: 400px;
|
|
243
|
-
}
|
|
244
|
-
`;return c`
|
|
245
|
-
<style>${e}</style>
|
|
246
|
-
<div class="login-layout">
|
|
247
|
-
${s.main}
|
|
248
|
-
</div>
|
|
249
|
-
`}}function Qe(s){return JSON.parse(window.atob(s.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")))}function Je(s,e=300,t=Date.now()){return Qe(s).exp*1e3-e<t}function ge(s){return(s.startsWith("/")?s:`/${s}`).replace(/\/{2,}/g,"/").replace(new RegExp("(?<=.)\\/$"),"")}function ye(s,e,t){const r=Ze(s,t);e.pushState(t,t.title,r),s.requestRender(t)}function Ye(s,e){const{mount:t}=s.config,{history:r}=s.config.toolkit.element.ownerDocument.defaultView;return e.startsWith(t)?{path:ge(e.slice(t.length)),push:o=>ye(s,r,o)}:null}function Ze(s,e){const{mount:t}=s.config;return ge(`${t}/${e.path}`)}function Xe(s,e){const{history:t}=e.config.toolkit.element.ownerDocument.defaultView;return c`
|
|
250
|
-
<h1>Auth Dashboard</h1>
|
|
251
|
-
<ul>
|
|
252
|
-
<li><a href="#" @click=${((o,i)=>()=>{ye(e,t,{path:o,title:i})})("/change-password")}>Change Password</a></li>
|
|
253
|
-
<li><a href="#" @click=${e.handleDestroyAuth}>Logout</a></li>
|
|
254
|
-
</ul>
|
|
255
|
-
`}function et(s,e){return c`
|
|
256
|
-
<auth-change-password-form .auth=${e}></auth-change-password-form>
|
|
257
|
-
`}class tt extends b{static get styles(){return q`
|
|
258
|
-
:host {
|
|
259
|
-
color: var(--color-text);
|
|
260
|
-
display: block;
|
|
261
|
-
font-family: var(--font-body);
|
|
262
|
-
}
|
|
263
|
-
h1,h2,h3,h4,h5,h6,label { font-family: var(--font-heading) }
|
|
264
|
-
label {
|
|
265
|
-
display: block;
|
|
266
|
-
font-size: var(--font-size-base);
|
|
267
|
-
margin-top: var(--spacing-md, 0.5rem);
|
|
268
|
-
}
|
|
269
|
-
input[type="text"],
|
|
270
|
-
input[type="password"] {
|
|
271
|
-
width: 100%;
|
|
272
|
-
margin: 5px 0 15px 0;
|
|
273
|
-
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
274
|
-
box-sizing: border-box;
|
|
275
|
-
border: 1px solid var(--color-gray-300, #ccc);
|
|
276
|
-
border-radius: var(--radius-sm, 5px);
|
|
277
|
-
color: var(--color-gray-9, #333);
|
|
278
|
-
background-color: var(--color-gray-0, transparent);
|
|
279
|
-
}
|
|
280
|
-
input[type="submit"] {
|
|
281
|
-
background-color: var(--color-primary, inherit);
|
|
282
|
-
color: var(--color-gray-0, #fff);
|
|
283
|
-
border: none;
|
|
284
|
-
padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
|
|
285
|
-
border-radius: var(--radius-dynamic, 5px);
|
|
286
|
-
width: 200px;
|
|
287
|
-
cursor: pointer;
|
|
288
|
-
}
|
|
289
|
-
.error {
|
|
290
|
-
color: var(--color-error);
|
|
291
|
-
}
|
|
292
|
-
`}static get properties(){return{auth:{type:Object}}}constructor(){super(),this.errors={},this.success=null}connectedCallback(){super.connectedCallback(),G.getToken(this)}async onSubmit(e){if(e.preventDefault(),e.target.newPassword.value!==e.target.confirmPassword.value){this.errors.confirmPassword="Passwords do not match",this.requestUpdate();return}if(e.target.newPassword.value===e.target.currentPassword.value){this.errors.newPassword="The new password is the same as your current password.",this.requestUpdate();return}await G.getToken(this),await x({baseUrl:this.auth.config.api}).updatePassword({currentPassword:e.target.currentPassword.value,newPassword:e.target.newPassword.value}).then(()=>{this.errors={},this.success="Password changed.",this.requestUpdate()}).catch(r=>{this.errors.submit=r.message,this.requestUpdate()})}render(){return c`
|
|
293
|
-
<h1>Change your password</h1>
|
|
294
|
-
<p>Enter your current password and choose a new password.</p>
|
|
295
|
-
<form @submit=${this.onSubmit}>
|
|
296
|
-
<div class="field">
|
|
297
|
-
<label for="currentPassword">Current Password</label>
|
|
298
|
-
<input
|
|
299
|
-
type="password"
|
|
300
|
-
name="currentPassword"
|
|
301
|
-
placeholder="Current Password"
|
|
302
|
-
required
|
|
303
|
-
/>
|
|
304
|
-
${this.errors.currentPassword?c`<p class="error">${this.errors.currentPassword}</p>`:""}
|
|
305
|
-
</div>
|
|
306
|
-
<div class="field">
|
|
307
|
-
<label for="newPassword">New Password</label>
|
|
308
|
-
<input
|
|
309
|
-
type="password"
|
|
310
|
-
name="newPassword"
|
|
311
|
-
placeholder="New Password"
|
|
312
|
-
required
|
|
313
|
-
/>
|
|
314
|
-
${this.errors.newPassword?c`<p class="error">${this.errors.newPassword}</p>`:""}
|
|
214
|
+
<div>
|
|
215
|
+
<a href="#" class="forgot"
|
|
216
|
+
@click=${()=>{this.setState(this.constructor.states.FORGOT)}}>Forgot password</a>
|
|
315
217
|
</div>
|
|
316
|
-
|
|
317
|
-
<label for="confirmPassword">Confirm Password</label>
|
|
318
|
-
<input
|
|
319
|
-
type="password"
|
|
320
|
-
name="confirmPassword"
|
|
321
|
-
placeholder="Confirm Password"
|
|
322
|
-
required
|
|
323
|
-
/>
|
|
324
|
-
${this.errors.confirmPassword?c`<p class="error">${this.errors.confirmPassword}</p>`:""}
|
|
325
|
-
</div>
|
|
326
|
-
<input type="submit" value="Change Password" />
|
|
327
|
-
${this.errors.submit?c`<p class="error">${this.errors.submit}</p>`:""}
|
|
328
|
-
${this.success?c`<p class="success">${this.success}</p>`:""}
|
|
329
|
-
</form>
|
|
330
|
-
`}}customElements.get("auth-change-password-form")||customElements.define("auth-change-password-form",tt);const rt=[{path:"/",render:Xe},{path:"/change-password",render:et}];function st(s,e){const{path:t}=s,r=rt.find(o=>o.path===t);if(r)return r.render(s,e)}const ot=q`
|
|
331
|
-
:host {
|
|
218
|
+
${this.errors?this.errors.map(e=>p`<p class="error">${e}</p>`):""}
|
|
332
219
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
220
|
+
<input type="submit" value="Log in" @click=${this.handleSubmitLogin}
|
|
221
|
+
?disabled=${this.isBusy}
|
|
222
|
+
/>
|
|
223
|
+
</form>
|
|
224
|
+
`}renderForgotPasswordForm(){return p`
|
|
225
|
+
<auth-forgot-password-form
|
|
226
|
+
api=${this.api}>
|
|
227
|
+
</auth-forgot-password-form>
|
|
228
|
+
`}renderChangePasswordForm(){return p`
|
|
229
|
+
<p>You have logged in successfully, but you must change your password.</p>
|
|
230
|
+
<form @submit="${this.onSubmitChangePasswordChallenge}">
|
|
231
|
+
<input type="hidden" name="username" value="${this.username}" />
|
|
232
|
+
<label for="password">New Password</label>
|
|
233
|
+
<input
|
|
234
|
+
type="password"
|
|
235
|
+
name="password"
|
|
236
|
+
placeholder="Password"
|
|
237
|
+
required
|
|
238
|
+
/>
|
|
239
|
+
<label for="confirm-password">Confirm Password</label>
|
|
240
|
+
<input
|
|
241
|
+
type="password"
|
|
242
|
+
name="confirm-password"
|
|
243
|
+
placeholder="Confirm Password"
|
|
244
|
+
required
|
|
245
|
+
/>
|
|
246
|
+
${this.errors?this.errors.map(e=>p`<p class="error">${e}</p>`):""}
|
|
247
|
+
<input type="submit" value="Change Password" />
|
|
248
|
+
</form>
|
|
249
|
+
`}}customElements.get("auth-login-form")||customElements.define("auth-login-form",Be);function We(r,e){return p`<auth-login-form slot="main"
|
|
250
|
+
api=${r==null?void 0:r.apiBaseUrl}
|
|
251
|
+
@login-success=${e}>
|
|
252
|
+
</auth-login-form>`}function Ge({tokenKey:r}){return window.localStorage.getItem(r)}function Ve({tokenKey:r},e){window.localStorage.setItem(r,e)}function Je({tokenKey:r}){window.localStorage.removeItem(r)}async function Qe(r){const e=Ge(r);if(!e||e.length<1)throw new Error("No token found");return Ke(e)?await N({baseUrl:r.apiBaseUrl}).refreshToken({token:e}).then(({token:s})=>s):e}function Ke(r,e=300,t=Date.now()){return Ye(r).exp*1e3-e<t}function Ye(r){return JSON.parse(window.atob(r.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")))}function Ze(r,e){var n,l,a,d,h,c,m,f,y;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={modName:t,toolkit:r,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",debug:s?(...L)=>console.log("[auth]",...L):()=>{},tokenKey:`${t}::token`,callbacks:[],isLoginPresent:!1};Object.entries({"auth:requestToken":Xe,"auth:destroy":et}).forEach(([L,pe])=>{const me=(...F)=>i.debug("[action]",L,...F);r.dispatchAction({type:"action:register",detail:{actionType:L,modName:t,handler:(...F)=>{me("handler",...F),pe(i,...F)}}})}),r.dispatchAction({type:"layout:register",detail:{name:`${t}::auth-layout`,templateFn:Le}}),o&&fe.getToken(e.element)}async function Xe(r,e){const{callback:t}=e;let s;try{s=await Qe(r),t(s)}catch(o){console.log("Presenting login form to get a fresh token",o),r.callbacks.push(t),r.isLoginPresent||tt(r)}}function et(r){Je(r)}function tt(r){r.isLoginPresent=!0,r.toolkit.dispatchAction({type:"layout:push",detail:{name:`${r.modName}::auth-layout`}}),r.toolkit.dispatchAction({type:"layout:content:append",detail:{content:We(r,st(r))}})}function st(r){return e=>{const{token:t}=e.detail;Ve(r,t),r.callbacks.forEach(s=>s(t)),r.callbacks=[],r.isLoginPresent=!1,r.toolkit.dispatchAction({type:"layout:pop"})}}exports.init=Ze;
|