Alfresco login webcomponent

This commit is contained in:
mauriziovitale84
2016-04-14 16:11:36 +01:00
parent d470f698ef
commit 9297bbd5ce
4 changed files with 261 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
{
"name": "alfresco-login",
"description": "Provide the Alfresco login .",
"keywords": [
"web-component",
"web-components",
"polymer",
"alfresco"
],
"main": "alfresco-login.html",
"license": "MIT",
"ignore": [
"/.*",
"/test/",
"/demo/",
"/bower_components/"
],
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0"
},
"_originalSource": "alfresco-login",
"_direct": true
}

View File

@@ -0,0 +1,96 @@
# Introduction
This repository contains an element for the Alfresco login REST API. The element is designed for use in Polymer 1.0.
## Install
Install the component using [Bower](http://bower.io/):
```sh
$ bower install alfresco-login --save
```
Or [download as ZIP](https://github.com/TODO/master.zip).
## Usage
1. Import Web Components' polyfill:
```html
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
```
2. Import Custom Element:
```html
<link rel="import" href="bower_components/alfresco-login/alfresco-login.html">
```
3. Start using it!
```html
<alfresco-login></alfresco-login>
```
## Options
Attribute | Options | Default | Description
--- | --- | --- | ---
`method` | *string* | `GET` | Type of HTTP Request.
## Events
Event | Description
--- | ---
`onsubmit` | The event is fired if a user signs in Alfresco successfully.
--- | ---
`onerror` | The event is fired if a user is not signed into Alfresco..
## Development
In order to run it locally you'll need to fetch some dependencies and a basic server setup.
* Install [Bower](http://bower.io/) & [Grunt](http://gruntjs.com/):
```sh
$ [sudo] npm install -g bower grunt-cli
```
* Install local dependencies:
```sh
$ bower install && npm install
```
* To test your project, start the development server and open `http://localhost:8000`.
```sh
$ grunt server
```
* To build the distribution files before releasing a new version.
```sh
$ grunt build
```
* To provide a live demo, send everything to `gh-pages` branch.
```sh
$ grunt deploy
```
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -m 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## History
For detailed changelog, check [Releases](https://github.com/TODO/alfresco-file-list/releases).
## License
[MIT License](http://opensource.org/licenses/MIT)

View File

@@ -0,0 +1,126 @@
<link rel="import" href="../../bower_components/polymer/polymer.html">
<!--
An element providing a solution to the login.
Example:
<alfresco-login method="GET" onsubmit="methodSuccess" onerror="methodError"></alfresco-login>
@demo
-->
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
<dom-module id="alfresco-login">
<style type="text/css">
:host([invalid]) input {
border-color: red;
}
</style>
<template>
<form id="login">
<paper-input name="username" id="username" label="Username"></paper-input>
<paper-input label="password input" name="password" id="password" type="password"></paper-input>
<button type="submit" class="btn btn-default" on-click="_submit">Login</button>
</form>
</template>
</dom-module>
<script>
Polymer({
is: 'alfresco-login',
behaviors: [
Polymer.IronValidatableBehavior
],
/**
* The submit event is fired if a user
* signs in Alfresco successfully.
*
* @event submit
*/
/**
* The error event is fired if a
* user is not signed into Alfresco.
*
* @event error
*/
properties: {
method: {
type: String,
value: 'GET'
},
headers: {
type: Object,
value: {}
}
},
ready: function(){
},
/**
* Login Alfesco
*
* @param {object}
*/
_submit: function() {
event.preventDefault();
var self = this;
var xhr = new XMLHttpRequest();
var url = 'http://192.168.99.100:8080/alfresco/service/api/login';
var parameterJson = '';
if (this.method === 'POST') {
parameterJson = JSON.stringify({username: username.value, password: password.value});
} else {
url += '?u='+username.value+'&pw='+password.value;
}
xhr.open(this.method, url, true);
for (key in this.headers) {
if (this.headers.hasOwnProperty(key)) {
xhr.setRequestHeader(key, this.headers[key]);
}
}
xhr.onload = function(e) {
if (xhr.status === 200) {
var token = '';
if (xhr.responseXML) {
token = xhr.responseXML.children[0].childNodes[0].nodeValue;
} else {
token = JSON.parse(xhr.responseText).data.ticket;
}
if (token) {
self.fire("submit", {ticket: token});
} else {
self.fire("error", {error:'Token error'});
}
} else {
self.fire("error", {error:'Login error'});
}
};
xhr.send(parameterJson);
}
});
</script>

View File

@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="alfresco-login.html">
</head>
<body>
<alfresco-login method="GET"></alfresco-login>
</body>
</html>