#17 Alfresco Login component library

This commit is contained in:
mauriziovitale84 2016-04-22 11:10:32 +01:00
parent 3074d5ee04
commit 5fc8ea1773
19 changed files with 580 additions and 0 deletions

View File

@ -0,0 +1,5 @@
npm-debug.log
node_modules
jspm_packages
.idea
typings

View File

@ -0,0 +1,9 @@
# Alfresco Components for Angular 2
Components included:
TBD
### Build
npm install
npm run build

View File

@ -0,0 +1,11 @@
import { Login } from './src/login.component';
import { Authentication } from './src/authentication.service';
export * from './src/login.component';
export * from './src/authentication.service';
declare var _default: {
directives: typeof Login[];
providers: typeof Authentication[];
};
export default _default;
export declare const ALFRESCO_LOGIN_DIRECTIVES: [any];
export declare const ALFRESCO_AUTHENTICATION: [any];

View File

@ -0,0 +1,37 @@
System.register(['./src/login.component', './src/authentication.service'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var login_component_1, authentication_service_1;
var ALFRESCO_LOGIN_DIRECTIVES, ALFRESCO_AUTHENTICATION;
var exportedNames_1 = {
'ALFRESCO_LOGIN_DIRECTIVES': true,
'ALFRESCO_AUTHENTICATION': true
};
function exportStar_1(m) {
var exports = {};
for(var n in m) {
if (n !== "default"&& !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n];
}
exports_1(exports);
}
return {
setters:[
function (login_component_1_1) {
login_component_1 = login_component_1_1;
exportStar_1(login_component_1_1);
},
function (authentication_service_1_1) {
authentication_service_1 = authentication_service_1_1;
exportStar_1(authentication_service_1_1);
}],
execute: function() {
exports_1("default",{
directives: [login_component_1.Login],
providers: [authentication_service_1.Authentication]
});
exports_1("ALFRESCO_LOGIN_DIRECTIVES", ALFRESCO_LOGIN_DIRECTIVES = [login_component_1.Login]);
exports_1("ALFRESCO_AUTHENTICATION", ALFRESCO_AUTHENTICATION = [authentication_service_1.Authentication]);
}
}
});
//# sourceMappingURL=ng2-alfresco-login.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ng2-alfresco-login.js","sourceRoot":"","sources":["ng2-alfresco-login.ts"],"names":[],"mappings":";;;;QAWa,yBAAyB,EACzB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;YANpC,oBAAe;gBACX,UAAU,EAAE,CAAC,uBAAK,CAAC;gBACnB,SAAS,EAAE,CAAC,uCAAc,CAAC;aAC9B,EAAA;YAEY,uCAAA,yBAAyB,GAAU,CAAC,uBAAK,CAAC,CAAA,CAAC;YAC3C,qCAAA,uBAAuB,GAAU,CAAC,uCAAc,CAAC,CAAA,CAAC"}

View File

@ -0,0 +1,13 @@
import {Login} from './src/login.component';
import {Authentication} from './src/authentication.service';
export * from './src/login.component';
export * from './src/authentication.service';
export default {
directives: [Login],
providers: [Authentication]
}
export const ALFRESCO_LOGIN_DIRECTIVES: [any] = [Login];
export const ALFRESCO_AUTHENTICATION: [any] = [Authentication];

View File

@ -0,0 +1,23 @@
{
"name": "ng2-alfresco-login",
"version": "0.1.0",
"scripts": {
"build": "typings install && tsc",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.15",
"systemjs": "0.19.26",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings":"^0.7.12"
}
}

View File

@ -0,0 +1,16 @@
import { Observable } from 'rxjs/Rx';
import { Http } from 'angular2/http';
export declare class Authentication {
http: Http;
token: string;
private _host;
private _baseUrl;
constructor(http: Http);
isLoggedIn(): boolean;
login(method: string, username: string, password: string): Observable<void>;
loginGet(username: string, password: string): Observable<void>;
loginPost(username: string, password: string): Observable<void>;
saveJwt(jwt: any): void;
logout(): Observable<boolean>;
private handleError(error);
}

View File

@ -0,0 +1,99 @@
System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], 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, Rx_1, http_1;
var Authentication;
return {
setters:[
function (core_1_1) {
core_1 = core_1_1;
},
function (Rx_1_1) {
Rx_1 = Rx_1_1;
},
function (http_1_1) {
http_1 = http_1_1;
}],
execute: function() {
Authentication = (function () {
function Authentication(http) {
this.http = http;
this._host = 'http://192.168.99.100:8080';
this._baseUrl = this._host + '/alfresco/service/api/';
this.token = localStorage.getItem('token');
}
Authentication.prototype.isLoggedIn = function () {
return !!localStorage.getItem('token');
};
Authentication.prototype.login = function (method, username, password) {
if (method === 'GET') {
return this.loginGet(username, password);
}
else {
return this.loginPost(username, password);
}
};
Authentication.prototype.loginGet = function (username, password) {
var _this = this;
var searchParams = new http_1.URLSearchParams();
searchParams.set('u', username);
searchParams.set('pw', password);
return this.http.get(this._baseUrl + 'login', { search: searchParams })
.map(function (res) {
var data = JSON.parse(xml2json(res.text(), ' '));
_this.token = data.ticket;
_this.saveJwt(_this.token);
})
.catch(this.handleError);
};
Authentication.prototype.loginPost = function (username, password) {
var _this = this;
var credentials = '{ username: ' + username + ', password: ' + password + ' }';
var headers = new http_1.Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this._baseUrl + 'login', credentials, {
headers: headers
})
.map(function (res) {
var response = res.json();
_this.token = response.data.ticket;
_this.saveJwt(_this.token);
})
.catch(this.handleError);
};
Authentication.prototype.saveJwt = function (jwt) {
if (jwt) {
localStorage.setItem('token', jwt);
}
};
Authentication.prototype.logout = function () {
this.token = undefined;
localStorage.removeItem('token');
return Rx_1.Observable.of(true);
};
Authentication.prototype.handleError = function (error) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Rx_1.Observable.throw(error.json().error || 'Server error');
};
Authentication = __decorate([
core_1.Injectable(),
__metadata('design:paramtypes', [http_1.Http])
], Authentication);
return Authentication;
}());
exports_1("Authentication", Authentication);
}
}
});
//# sourceMappingURL=authentication.service.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["authentication.service.ts"],"names":[],"mappings":"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"}

View File

@ -0,0 +1,80 @@
import {Injectable} from 'angular2/core';
import {Observable} from 'rxjs/Rx';
import {Http, Headers, URLSearchParams, Response} from 'angular2/http';
declare let xml2json:any;
@Injectable()
export class Authentication {
token:string;
private _host:string = 'http://192.168.99.100:8080';
private _baseUrl:string = this._host + '/alfresco/service/api/';
constructor(public http:Http) {
this.token = localStorage.getItem('token');
}
isLoggedIn() {
return !!localStorage.getItem('token');
}
login(method:string, username:string, password:string) {
if (method === 'GET') {
return this.loginGet(username, password);
} else {
return this.loginPost(username, password);
}
}
loginGet(username:string, password:string) {
const searchParams = new URLSearchParams();
searchParams.set('u', username);
searchParams.set('pw', password);
return this.http.get(this._baseUrl + 'login', {search: searchParams})
.map((res:any) => {
let data = JSON.parse(xml2json(res.text(), ' '));
this.token = data.ticket;
this.saveJwt(this.token);
})
.catch(this.handleError);
}
loginPost(username:string, password:string) {
let credentials = '{ username: ' + username + ', password: ' + password + ' }';
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this._baseUrl + 'login', credentials, {
headers: headers
})
.map((res:any) => {
let response = res.json();
this.token = response.data.ticket;
this.saveJwt(this.token);
})
.catch(this.handleError);
}
saveJwt(jwt) {
if (jwt) {
localStorage.setItem('token', jwt);
}
}
logout() {
this.token = undefined;
localStorage.removeItem('token');
return Observable.of(true);
}
private handleError(error:Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}

View File

@ -0,0 +1,92 @@
.login-card-wide.mdl-card {
width: 512px;
margin: auto;
}
.login-card-wide > .mdl-card__menu {
color: #000;
}
.ng-invalid.ng-invalid.ng-touched {
border-color: rgb(222, 50, 38);
box-shadow: none;
}
.ng-invalid.ng-invalid.ng-touched + label {
color: rgb(222, 50, 38);
font-size: 12px;
}
.ng-invalid.ng-invalid.ng-touched + label:after {
background-color: rgb(222, 50, 38);
}
.ng-invalid.ng-invalid.ng-touched ~ .mdl-tooltip--validation {
background-color: rgb(222, 50, 38);
}
.ng-invalid.ng-touched:not(:focus) + label::before {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
/* Preferred icon size */
display: inline-block;
width: 1em;
height: 1em;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
content: "warning";
position: absolute;
right: 0;
bottom: 20px;
}
.ng-valid.ng-touched:not(:focus) + label::before {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px;
/* Preferred icon size */
display: inline-block;
width: 1em;
height: 1em;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
content: "done";
position: absolute;
right: 0;
bottom: 20px;
}

View File

@ -0,0 +1,12 @@
import { Router } from 'angular2/router';
import { ControlGroup, FormBuilder } from 'angular2/common';
import { Authentication } from './authentication.service';
export declare class Login {
auth: Authentication;
router: Router;
form: ControlGroup;
error: boolean;
isErrorStyle(field: ControlGroup): boolean;
constructor(fb: FormBuilder, auth: Authentication, router: Router);
onSubmit(value: any, event: any): void;
}

View File

@ -0,0 +1,34 @@
<div class="login-card-wide mdl-card mdl-shadow--4dp">
<form [ngFormModel]="form" (submit)="onSubmit(form.value, $event)">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text ">Login</h2>
</div>
<div class="mdl-card__supporting-text">
<div [ngClass]="{'is-invalid': isErrorStyle(form.controls.username)}" class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label ">
<label for="username" class="mdl-textfield__label">Username</label>
<input type="text" class="mdl-textfield__input" id="username" ngControl="username" />
<span class="mdl-tooltip mdl-tooltip--validation" for="username" *ngIf="form.controls.username.hasError('required')">
<span>Required.</span>
</span>
<span class="mdl-tooltip mdl-tooltip--validation" for="username" *ngIf="form.controls.username.hasError('minlength')">
<span>Your username needs to be at least 4 characters.</span>
</span>
</div>
<div [ngClass]="{'is-invalid': isErrorStyle(form.controls.password)}" class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<label for="password" class="mdl-textfield__label">Password</label>
<input type="password" class="mdl-textfield__input" id="password" ngControl="password" />
<span class="mdl-tooltip mdl-tooltip--validation" for="password" *ngIf="form.controls.password.hasError('required')">
<span>Required.</span>
</span>
</div>
</div>
<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>
<div *ngIf="error">You have entered an invalid username or password</div>
</div>
<div class="mdl-card__menu">
<div class="mdl-spinner mdl-js-spinner"></div>
</div>
</form>
</div>

View File

@ -0,0 +1,75 @@
System.register(['angular2/core', 'angular2/router', 'angular2/common', './authentication.service'], 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, router_1, common_1, authentication_service_1;
var Login;
return {
setters:[
function (core_1_1) {
core_1 = core_1_1;
},
function (router_1_1) {
router_1 = router_1_1;
},
function (common_1_1) {
common_1 = common_1_1;
},
function (authentication_service_1_1) {
authentication_service_1 = authentication_service_1_1;
}],
execute: function() {
Login = (function () {
function Login(fb, auth, router) {
this.auth = auth;
this.router = router;
this.error = false;
this.form = fb.group({
username: ['', common_1.Validators.compose([common_1.Validators.required, common_1.Validators.minLength(4)])],
password: ['', common_1.Validators.required]
});
}
Login.prototype.isErrorStyle = function (field) {
componentHandler.upgradeAllRegistered();
if (field.valid) {
return false;
}
else {
return true;
}
};
Login.prototype.onSubmit = function (value, event) {
var _this = this;
if (event) {
event.preventDefault();
}
this.auth.login('POST', value.username, value.password)
.subscribe(function (token) { return _this.router.navigate(['Home']); }, function () {
_this.error = true;
});
};
Login = __decorate([
core_1.Component({
selector: 'login',
moduleId: 'node_modules/ng2-alfresco-login/src/',
directives: [router_1.ROUTER_DIRECTIVES, common_1.FORM_DIRECTIVES],
templateUrl: 'login.component.html',
styleUrls: ['login.component.css'],
}),
__metadata('design:paramtypes', [common_1.FormBuilder, authentication_service_1.Authentication, router_1.Router])
], Login);
return Login;
}());
exports_1("Login", Login);
}
}
});
//# sourceMappingURL=login.component.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"login.component.js","sourceRoot":"","sources":["login.component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAcA;gBAaI,eAAY,EAAc,EAAS,IAAmB,EAAS,MAAa;oBAAzC,SAAI,GAAJ,IAAI,CAAe;oBAAS,WAAM,GAAN,MAAM,CAAO;oBAX5E,UAAK,GAAW,KAAK,CAAC;oBAYlB,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;gBACP,CAAC;gBAdD,4BAAY,GAAZ,UAAa,KAAkB;oBAC3B,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;oBACxC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;wBACd,MAAM,CAAC,KAAK,CAAC;oBACjB,CAAC;oBAAC,IAAI,CAAC,CAAC;wBACJ,MAAM,CAAC,IAAI,CAAC;oBAChB,CAAC;gBACL,CAAC;gBASD,wBAAQ,GAAR,UAAS,KAAS,EAAE,KAAK;oBAAzB,iBAWC;oBAVG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;wBACR,KAAK,CAAC,cAAc,EAAE,CAAC;oBAC3B,CAAC;oBACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;yBAClD,SAAS,CACN,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,CACJ,CAAC;gBACV,CAAC;gBAvCL;oBAAC,gBAAS,CAAC;wBACP,QAAQ,EAAE,OAAO;wBACjB,QAAQ,EAAE,sCAAsC;wBAChD,UAAU,EAAE,CAAC,0BAAiB,EAAE,wBAAe,CAAC;wBAChD,WAAW,EAAE,sBAAsB;wBACnC,SAAS,EAAE,CAAC,qBAAqB,CAAC;qBAErC,CAAC;;yBAAA;gBAiCF,YAAC;YAAD,CAAC,AAhCD,IAgCC;YAhCD,yBAgCC,CAAA"}

View File

@ -0,0 +1,47 @@
import {Component} from 'angular2/core';
import {Router, ROUTER_DIRECTIVES} from 'angular2/router';
import {FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators} from 'angular2/common';
import {Authentication} from './authentication.service';
declare let componentHandler;
@Component({
selector: 'login',
moduleId: 'node_modules/ng2-alfresco-login/src/',
directives: [ROUTER_DIRECTIVES, FORM_DIRECTIVES],
templateUrl: 'login.component.html',
styleUrls: ['login.component.css'],
})
export class Login {
form:ControlGroup;
error:boolean = false;
isErrorStyle(field:ControlGroup) {
componentHandler.upgradeAllRegistered();
if (field.valid) {
return false;
} else {
return true;
}
}
constructor(fb:FormBuilder, public auth:Authentication, public router:Router) {
this.form = fb.group({
username: ['', Validators.compose([Validators.required, Validators.minLength(4)])],
password: ['', Validators.required]
});
}
onSubmit(value:any, event) {
if (event) {
event.preventDefault();
}
this.auth.login('POST', value.username, value.password)
.subscribe(
(token:any) => this.router.navigate(['Home']),
() => {
this.error = true;
}
);
}
}

View File

@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"declaration": true
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}

View File

@ -0,0 +1,6 @@
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#5c182b9af717f73146399c2485f70f1e2ac0ff2b"
}
}