[Major] now firing strolch-session-valid on session validation/login

This commit is contained in:
Robert von Burg 2017-07-11 13:18:34 +02:00
parent ecc021aaba
commit f396b45776
2 changed files with 38 additions and 13 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "strolch-wc-auth", "name": "strolch-wc-auth",
"description": "Strolch WebComponent Auth", "description": "Strolch WebComponent Auth",
"version": "0.4.4", "version": "0.5.0",
"authors": "Robert von Burg", "authors": "Robert von Burg",
"keywords": [ "keywords": [
"strolch", "strolch",
@ -17,14 +17,14 @@
"homepage": "https://github.com/4treesCH/strolch-wc-auth", "homepage": "https://github.com/4treesCH/strolch-wc-auth",
"ignore": [], "ignore": [],
"dependencies": { "dependencies": {
"strolchjs": "4treesCH/strolchjs#^0.1.3", "strolchjs": "4treesCH/strolchjs#^0.1.4",
"strolch-wc-localize-behavior": "4treesCH/strolch-wc-localize-behavior#^1.0.2",
"paper-material": "PolymerElements/paper-material#^1.0.6", "paper-material": "PolymerElements/paper-material#^1.0.6",
"paper-card": "PolymerElements/paper-card#^1.1.2", "paper-card": "PolymerElements/paper-card#^1.1.2",
"paper-dialog": "PolymerElements/paper-dialog#^1.1.0", "paper-dialog": "PolymerElements/paper-dialog#^1.1.0",
"paper-button": "PolymerElements/paper-button#^1.0.13", "paper-button": "PolymerElements/paper-button#^1.0.13",
"iron-a11y-keys": "PolymerElements/iron-a11y-keys#^1.0.6", "iron-a11y-keys": "PolymerElements/iron-a11y-keys#^1.0.6",
"paper-input": "PolymerElements/paper-input#^1.1.17", "paper-input": "PolymerElements/paper-input#^1.1.17",
"iron-ajax": "PolymerElements/iron-ajax#^1.4.3", "iron-ajax": "PolymerElements/iron-ajax#^1.4.3"
"strolch-wc-localize-behavior": "4treesCH/strolch-wc-localize-behavior#^1.0.2"
} }
} }

View File

@ -69,6 +69,7 @@
label="{{localize('password')}}" label="{{localize('password')}}"
required required
type="password" type="password"
on-focus="onFocus"
auto-validate></paper-input> auto-validate></paper-input>
</div> </div>
<div class="card-actions"> <div class="card-actions">
@ -125,12 +126,14 @@
label="{{localize('password')}}" label="{{localize('password')}}"
required required
type="password" type="password"
on-focus="onFocus"
auto-validate></paper-input> auto-validate></paper-input>
<paper-input id="password2" <paper-input id="password2"
bind-value="{{password2}}" bind-value="{{password2}}"
label="{{localize('repeat')}}" label="{{localize('repeat')}}"
required required
type="password" type="password"
on-focus="onFocus"
auto-validate></paper-input> auto-validate></paper-input>
</div> </div>
<div class="card-actions"> <div class="card-actions">
@ -153,6 +156,14 @@
</div> </div>
<paper-dialog id="dlg" modal on-iron-overlay-closed="onCloseDlg">
<h2>[[dlgTitle]]</h2>
<p>[[dlgText]]</p>
<div class="buttons">
<paper-button dialog-confirm autofocus>Close</paper-button>
</div>
</paper-dialog>
<iron-ajax id="ajaxAuthCheck" <iron-ajax id="ajaxAuthCheck"
handle-as="json" handle-as="json"
method="HEAD" method="HEAD"
@ -178,9 +189,6 @@
], ],
properties: { properties: {
app: {
type: Object
},
basePath: { basePath: {
type: String, type: String,
value: function () { value: function () {
@ -205,8 +213,8 @@
code: { code: {
type: String type: String
}, },
dlgTitle : { dlgTitle: {
type:String type: String
} }
}, },
@ -214,12 +222,20 @@
// do nothing // do nothing
}, },
onFocus: function (evt) {
evt.target.$.input.select();
},
onCloseDlg: function (evt) {
this.$.username.inputElement.select();
},
attached: function () { attached: function () {
// this component has its own locales resources to load // this component has its own locales resources to load
this.loadResources(this.resolveUrl("./locales.json")); this.loadResources(this.resolveUrl("./locales.json"));
// default the language to english, if there is none given by the app // default the language to english, if there is none given by the app
if(!this.language) this.language = "en"; if (!this.language) this.language = "en";
}, },
reload: function () { reload: function () {
@ -243,7 +259,9 @@
sessionValidated: function () { sessionValidated: function () {
console.log("Session validated."); console.log("Session validated.");
Strolch.sessionVerified = true; Strolch.sessionVerified = true;
this.app.sessionValid(); this.fire('strolch-session-valid', {
sessionVerified: true
});
}, },
sessionInvalid: function () { sessionInvalid: function () {
console.log("Session invalid."); console.log("Session invalid.");
@ -263,7 +281,7 @@
dlgText = data.detail.error; dlgText = data.detail.error;
} }
this.app.showError(this.dlgTitle, dlgText); this.showError(this.dlgTitle, dlgText);
}, },
logout: function () { logout: function () {
@ -378,7 +396,7 @@
this.$.password2.invalid = true; this.$.password2.invalid = true;
var dlgTitle = "Reset failed"; var dlgTitle = "Reset failed";
var dlgText = 'Passwords do not match.'; var dlgText = 'Passwords do not match.';
this.app.showError(dlgTitle, dlgText); this.showError(dlgTitle, dlgText);
} }
console.log('Doing reset...'); console.log('Doing reset...');
@ -396,6 +414,13 @@
'password': btoa(this.password1) 'password': btoa(this.password1)
}; };
this.$.ajaxAuth.generateRequest(); this.$.ajaxAuth.generateRequest();
},
showError: function (title, text) {
this.dlgTitle = title;
this.dlgText = text;
console.log('ERROR: ' + this.dlgTitle + ': ' + this.dlgText);
this.$.dlg.open();
} }
}); });