#17 Login successful message

This commit is contained in:
mauriziovitale84
2016-04-29 15:23:34 +01:00
parent 43a870c18a
commit 5238ee1187
13 changed files with 256 additions and 5 deletions

View File

@@ -0,0 +1,2 @@
export declare class HomeComponent {
}

View File

@@ -0,0 +1,37 @@
System.register(['angular2/core'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1;
var HomeComponent;
return {
setters:[
function (core_1_1) {
core_1 = core_1_1;
}],
execute: function() {
HomeComponent = (function () {
function HomeComponent() {
}
HomeComponent = __decorate([
core_1.Component({
selector: 'home',
template: 'Welcome'
}),
__metadata('design:paramtypes', [])
], HomeComponent);
return HomeComponent;
}());
exports_1("HomeComponent", HomeComponent);
}
}
});
//# sourceMappingURL=home.component.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"home.component.js","sourceRoot":"","sources":["home.component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;YAOA;gBAAA;gBAEA,CAAC;gBAPD;oBAAC,gBAAS,CAAC;wBACP,QAAQ,EAAE,MAAM;wBAChB,QAAQ,EAAE,SAAS;qBACtB,CAAC;;iCAAA;gBAIF,oBAAC;YAAD,CAAC,AAFD,IAEC;YAFD,yCAEC,CAAA"}

View File

@@ -0,0 +1,10 @@
import {Component} from 'angular2/core';
@Component({
selector: 'home',
template: 'Welcome'
})
export class HomeComponent {
}

View File

@@ -0,0 +1,178 @@
/* This work is licensed under Creative Commons GNU LGPL License.
License: http://creativecommons.org/licenses/LGPL/2.1/
Version: 0.9
Author: Stefan Goessner/2006
Web: http://goessner.net/
*/
var parseXml;
if (typeof window.DOMParser != "undefined") {
parseXml = function(xmlStr) {
return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");
};
} else if (typeof window.ActiveXObject != "undefined" &&
new window.ActiveXObject("Microsoft.XMLDOM")) {
parseXml = function(xmlStr) {
var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(xmlStr);
return xmlDoc;
};
} else {
throw new Error("No XML parser found");
}
function xml2json(xml, tab) {
var X = {
toObj: function(xml) {
var o = {};
if (xml.nodeType==1) { // element node ..
if (xml.attributes.length) // element with attributes ..
for (var i=0; i<xml.attributes.length; i++)
o["@"+xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue||"").toString();
if (xml.firstChild) { // element has child nodes ..
var textChild=0, cdataChild=0, hasElementChild=false;
for (var n=xml.firstChild; n; n=n.nextSibling) {
if (n.nodeType==1) hasElementChild = true;
else if (n.nodeType==3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) textChild++; // non-whitespace text
else if (n.nodeType==4) cdataChild++; // cdata section node
}
if (hasElementChild) {
if (textChild < 2 && cdataChild < 2) { // structured element with evtl. a single text or/and cdata node ..
X.removeWhite(xml);
for (var n=xml.firstChild; n; n=n.nextSibling) {
if (n.nodeType == 3) // text node
o["#text"] = X.escape(n.nodeValue);
else if (n.nodeType == 4) // cdata node
o["#cdata"] = X.escape(n.nodeValue);
else if (o[n.nodeName]) { // multiple occurence of element ..
if (o[n.nodeName] instanceof Array)
o[n.nodeName][o[n.nodeName].length] = X.toObj(n);
else
o[n.nodeName] = [o[n.nodeName], X.toObj(n)];
}
else // first occurence of element..
o[n.nodeName] = X.toObj(n);
}
}
else { // mixed content
if (!xml.attributes.length)
o = X.escape(X.innerXml(xml));
else
o["#text"] = X.escape(X.innerXml(xml));
}
}
else if (textChild) { // pure text
if (!xml.attributes.length)
o = X.escape(X.innerXml(xml));
else
o["#text"] = X.escape(X.innerXml(xml));
}
else if (cdataChild) { // cdata
if (cdataChild > 1)
o = X.escape(X.innerXml(xml));
else
for (var n=xml.firstChild; n; n=n.nextSibling)
o["#cdata"] = X.escape(n.nodeValue);
}
}
if (!xml.attributes.length && !xml.firstChild) o = null;
}
else if (xml.nodeType==9) { // document.node
o = X.toObj(xml.documentElement);
}
else
alert("unhandled node type: " + xml.nodeType);
return o;
},
toJson: function(o, name, ind) {
var json = name ? ("\""+name+"\"") : "";
if (o instanceof Array) {
for (var i=0,n=o.length; i<n; i++)
o[i] = X.toJson(o[i], "", ind+"\t");
json += (name?":[":"[") + (o.length > 1 ? ("\n"+ind+"\t"+o.join(",\n"+ind+"\t")+"\n"+ind) : o.join("")) + "]";
}
else if (o == null)
json += (name&&":") + "null";
else if (typeof(o) == "object") {
var arr = [];
for (var m in o)
arr[arr.length] = X.toJson(o[m], m, ind+"\t");
json += (name?":{":"{") + (arr.length > 1 ? ("\n"+ind+"\t"+arr.join(",\n"+ind+"\t")+"\n"+ind) : arr.join("")) + "}";
}
else if (typeof(o) == "string")
json += (name&&":") + "\"" + o.toString() + "\"";
else
json += (name&&":") + o.toString();
return json;
},
innerXml: function(node) {
var s = ""
if ("innerHTML" in node)
s = node.innerHTML;
else {
var asXml = function(n) {
var s = "";
if (n.nodeType == 1) {
s += "<" + n.nodeName;
for (var i=0; i<n.attributes.length;i++)
s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue||"").toString() + "\"";
if (n.firstChild) {
s += ">";
for (var c=n.firstChild; c; c=c.nextSibling)
s += asXml(c);
s += "</"+n.nodeName+">";
}
else
s += "/>";
}
else if (n.nodeType == 3)
s += n.nodeValue;
else if (n.nodeType == 4)
s += "<![CDATA[" + n.nodeValue + "]]>";
return s;
};
for (var c=node.firstChild; c; c=c.nextSibling)
s += asXml(c);
}
return s;
},
escape: function(txt) {
return txt.replace(/[\\]/g, "\\\\")
.replace(/[\"]/g, '\\"')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r');
},
removeWhite: function(e) {
e.normalize();
for (var n = e.firstChild; n; ) {
if (n.nodeType == 3) { // text node
if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) { // pure whitespace text node
var nxt = n.nextSibling;
e.removeChild(n);
n = nxt;
}
else
n = n.nextSibling;
}
else if (n.nodeType == 1) { // element node
X.removeWhite(n);
n = n.nextSibling;
}
else // any other node
n = n.nextSibling;
}
return e;
}
};
xml = parseXml(xml);
if (xml.nodeType == 9) // document node
xml = xml.documentElement;
var json = X.toJson(X.toObj(X.removeWhite(xml)), xml.nodeName, "\t");
return "{\n" + tab + (tab ? json.replace(/\t/g, tab) : json.replace(/\t|\n/g, "")) + "\n}";
}

View File

@@ -21,6 +21,7 @@
<script src="node_modules/material-design-lite/material.min.js"></script> <script src="node_modules/material-design-lite/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="/app/js/xml2json.js"></script>
<!-- 2. Configure SystemJS --> <!-- 2. Configure SystemJS -->
<script> <script>
System.config({ System.config({

View File

@@ -5,5 +5,6 @@
"input-required-message": "Required", "input-required-message": "Required",
"input-min-message": "Your username needs to be at least 4 characters.", "input-min-message": "Your username needs to be at least 4 characters.",
"login-button": "Login", "login-button": "Login",
"login-error-message": "You have entered an invalid username or password" "login-error-message": "You have entered an invalid username or password",
"login-success-message": "Login successful"
} }

View File

@@ -5,5 +5,6 @@
"input-required-message": "Campo obbligatorio", "input-required-message": "Campo obbligatorio",
"input-min-message": "Inserire un nome utente di 4 caratteri minimo.", "input-min-message": "Inserire un nome utente di 4 caratteri minimo.",
"login-button": "Accedi", "login-button": "Accedi",
"login-error-message": "Nome utente o password non validi" "login-error-message": "Nome utente o password non validi",
"login-success-message": "Login effettuata con successo"
} }

View File

@@ -9,6 +9,7 @@ export declare class AlfrescoLoginComponent {
translate: TranslateService; translate: TranslateService;
form: ControlGroup; form: ControlGroup;
error: boolean; error: boolean;
success: boolean;
/** /**
* Constructor * Constructor
* @param fb * @param fb

View File

@@ -26,6 +26,7 @@
<div class="mdl-card__actions mdl-card--border"> <div class="mdl-card__actions mdl-card--border">
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" [disabled]="!form.valid">{{'login-button' | translate }}</button> <button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored" [disabled]="!form.valid">{{'login-button' | translate }}</button>
<div *ngIf="error" class="mdl-card__supporting-text" style="color: red;">{{'login-error-message' | translate }}</div> <div *ngIf="error" class="mdl-card__supporting-text" style="color: red;">{{'login-error-message' | translate }}</div>
<div *ngIf="success" class="mdl-card__supporting-text" style="color: blue;">{{'login-success-message' | translate }}</div>
</div> </div>
<div class="mdl-card__menu"> <div class="mdl-card__menu">
<div class="mdl-spinner mdl-js-spinner"></div> <div class="mdl-spinner mdl-js-spinner"></div>

View File

@@ -42,6 +42,7 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './alfre
this.router = router; this.router = router;
this.method = 'GET'; this.method = 'GET';
this.error = false; this.error = false;
this.success = false;
this.form = fb.group({ this.form = fb.group({
username: ['', common_1.Validators.compose([common_1.Validators.required, common_1.Validators.minLength(4)])], username: ['', common_1.Validators.compose([common_1.Validators.required, common_1.Validators.minLength(4)])],
password: ['', common_1.Validators.required] password: ['', common_1.Validators.required]
@@ -60,8 +61,16 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './alfre
event.preventDefault(); event.preventDefault();
} }
this.auth.login(this.method, value.username, value.password) this.auth.login(this.method, value.username, value.password)
.subscribe(function (token) { return _this.router.navigate(['Home']); }, function () { .subscribe(function (token) {
try {
_this.router.navigate(['Home']);
}
catch (Error) {
_this.success = true;
}
}, function () {
_this.error = true; _this.error = true;
_this.success = false;
}); });
}; };
/** /**

View File

@@ -1 +1 @@
{"version":3,"file":"alfresco-login.component.js","sourceRoot":"","sources":["alfresco-login.component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAiCA;gBAOI;;;;;mBAKG;gBACH,gCAAY,EAAc,EACP,IAAkC,EAClC,MAAa,EACpB,SAA0B;oBAFnB,SAAI,GAAJ,IAAI,CAA8B;oBAClC,WAAM,GAAN,MAAM,CAAO;oBAdvB,WAAM,GAAU,KAAK,CAAC;oBAI/B,UAAK,GAAW,KAAK,CAAC;oBAalB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC;wBACjB,QAAQ,EAAE,CAAC,EAAE,EAAE,mBAAU,CAAC,OAAO,CAAC,CAAC,mBAAU,CAAC,QAAQ,EAAE,mBAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;wBAClF,QAAQ,EAAE,CAAC,EAAE,EAAE,mBAAU,CAAC,QAAQ,CAAC;qBACtC,CAAC,CAAC;oBAEH,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;gBACpC,CAAC;gBAED;;;;mBAIG;gBACH,yCAAQ,GAAR,UAAS,KAAS,EAAE,KAAK;oBAAzB,iBAYC;oBAXG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;oBACnB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;wBACR,KAAK,CAAC,cAAc,EAAE,CAAC;oBAC3B,CAAC;oBACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;yBACvD,SAAS,CACV,UAAC,KAAS,IAAK,OAAA,KAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,EAA9B,CAA8B,EAC7C;wBACI,KAAI,CAAC,KAAK,GAAG,IAAI,CAAC;oBACtB,CAAC,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AC;YAAD,CAAC,AAnFD,IAmFC;YAnFD,2DAmFC,CAAA"}

View File

@@ -37,6 +37,7 @@ export class AlfrescoLoginComponent {
form:ControlGroup; form:ControlGroup;
error:boolean = false; error:boolean = false;
success:boolean = false;
/** /**
* Constructor * Constructor
@@ -69,9 +70,17 @@ export class AlfrescoLoginComponent {
} }
this.auth.login(this.method, value.username, value.password) this.auth.login(this.method, value.username, value.password)
.subscribe( .subscribe(
(token:any) => this.router.navigate(['Home']), (token:any) => {
try {
this.router.navigate(['Home']);
} catch (Error) {
this.success = true;
}
},
() => { () => {
this.error = true; this.error = true;
this.success = false;
} }
); );
} }