mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Basic login for React app
This commit is contained in:
@@ -41,4 +41,41 @@
|
||||
float: right;
|
||||
}
|
||||
|
||||
#login {
|
||||
width: 400px;
|
||||
height: 340px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto;
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border: 1px gray;
|
||||
box-shadow: 0px 12px 12px -10px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
#login .logo {
|
||||
background: url('../img/logo_dark.svg') no-repeat;
|
||||
width: 196px;
|
||||
height: 45px;
|
||||
margin: 20px auto;
|
||||
}
|
||||
|
||||
#login form > div {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
#login label {
|
||||
margin-top: 5px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#login input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#login .error {
|
||||
color: red;
|
||||
}
|
93
react-app/img/logo_dark.svg
Normal file
93
react-app/img/logo_dark.svg
Normal file
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 187 43" style="enable-background:new 0 0 187 43;" width="187" height="43" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#77777A;}
|
||||
.st1{fill:none;}
|
||||
.st2{fill:#77BC1F;}
|
||||
.st3{fill:#F38B00;}
|
||||
.st4{fill:#0071CE;}
|
||||
.st5{fill:#002F87;}
|
||||
.st6{fill:#F9BE00;}
|
||||
.st7{fill:#00AF41;}
|
||||
</style>
|
||||
<g>
|
||||
<path class="st0" d="M59.7,4.4h3.2l11.9,30.2h-3.1L68,25.2H54.2l-3.7,9.4h-3.1L59.7,4.4z M55.1,22.7H67L61.1,7.2L55.1,22.7z"/>
|
||||
<rect x="75.6" y="4.4" class="st0" width="2.7" height="30.2"/>
|
||||
<path class="st0" d="M90.4,15h-4.3v19.6h-2.7V15h-3.7v-2.2h3.7v-2c0-3.8,1-6.4,5.3-6.4c0.8,0,1.4,0,2.2,0.2v2.3
|
||||
c-0.7-0.1-1.3-0.2-1.9-0.2c-3,0-2.9,1.9-2.9,4.2v1.9h4.3V15z"/>
|
||||
<path class="st0" d="M91.4,12.7h2.5v5.1H94c1.4-3.5,4.3-5.6,8.3-5.4v2.7c-4.8-0.3-8.2,3.3-8.2,7.8v11.6h-2.7V12.7z"/>
|
||||
<path class="st0" d="M104.2,24.4c0.1,3.9,2.1,8.6,7.2,8.6c3.9,0,6-2.3,6.9-5.6h2.7c-1.1,4.9-4,7.8-9.6,7.8c-7,0-9.9-5.3-9.9-11.6
|
||||
c0-5.8,2.9-11.6,9.9-11.6c7.1,0,9.9,6.1,9.6,12.3H104.2z M118.4,22.1c-0.1-4-2.6-7.8-7-7.8c-4.4,0-6.8,3.8-7.2,7.8H118.4z"/>
|
||||
<path class="st0" d="M136.3,19.1c-0.1-3.3-2.7-4.8-5.7-4.8c-2.4,0-5.2,0.9-5.2,3.8c0,2.4,2.7,3.2,4.6,3.7l3.6,0.8
|
||||
c3,0.5,6.2,2.2,6.2,6c0,4.7-4.7,6.6-8.8,6.6c-5.1,0-8.6-2.4-9-7.7h2.7c0.2,3.6,2.9,5.4,6.5,5.4c2.5,0,6-1.1,6-4.1
|
||||
c0-2.5-2.4-3.4-4.8-4l-3.4-0.8c-3.5-0.9-6.1-2.1-6.1-5.8c0-4.4,4.4-6.1,8.2-6.1c4.4,0,7.9,2.3,8,7H136.3z"/>
|
||||
<path class="st0" d="M157.6,19.6c-0.7-3.3-2.7-5.2-6.2-5.2c-5.1,0-7.7,4.6-7.7,9.3c0,4.7,2.6,9.3,7.7,9.3c3.3,0,6-2.6,6.4-6.2h2.7
|
||||
c-0.7,5.2-4.2,8.5-9.1,8.5c-6.7,0-10.4-5.3-10.4-11.6c0-6.3,3.7-11.6,10.4-11.6c4.7,0,8.3,2.5,8.9,7.5H157.6z"/>
|
||||
<path class="st0" d="M182.3,23.7c0,6.3-3.6,11.6-10.4,11.6s-10.4-5.3-10.4-11.6c0-6.3,3.6-11.6,10.4-11.6S182.3,17.4,182.3,23.7
|
||||
M164.3,23.7c0,4.7,2.6,9.3,7.7,9.3c5.2,0,7.7-4.7,7.7-9.3c0-4.7-2.5-9.3-7.7-9.3C166.8,14.4,164.3,19,164.3,23.7"/>
|
||||
<polygon class="st0" points="181.4,11.7 183.8,11.7 183.8,12 182.8,12 182.8,14.8 182.5,14.8 182.5,12 181.4,12 "/>
|
||||
<polygon class="st0" points="184,11.7 184.4,11.7 185.5,14.4 186.6,11.7 187,11.7 187,14.8 186.7,14.8 186.7,12.1 186.7,12.1
|
||||
185.6,14.8 185.3,14.8 184.3,12.1 184.3,14.8 184,14.8 "/>
|
||||
<path class="st1" d="M21.6,21.5v8.6l0,0.3c0,4.9-4,8.9-9,8.9c-4.9,0-9-4-9-8.9c0-0.5,0-1.1,0.1-1.6c3.5,2.4,8.3,2.1,11.4-1
|
||||
L21.6,21.5L21.6,21.5L21.6,21.5z"/>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st2" d="M15.3,27.8l5.2-5.2h-7.8c-4.3,0-7.8,3.5-7.8,7.8c0,4.3,3.5,7.8,7.8,7.8c0.3,0,0.7,0,1-0.1
|
||||
C11.9,34.8,12.5,30.6,15.3,27.8z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st2" d="M21.6,30.4v-7.3l-5.5,5.5l0,0c-3.1,3-3.1,8,0,11c3.1,3,8,3,11.1,0c0.2-0.2,0.4-0.5,0.6-0.7
|
||||
C24.2,37.7,21.6,34.3,21.6,30.4z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st2" d="M27.9,27.8l-5.2-5.2v7.8c0,4.3,3.5,7.8,7.8,7.8c4.3,0,7.8-3.5,7.8-7.8c0-0.3,0-0.6-0.1-1
|
||||
C34.9,31.1,30.7,30.6,27.9,27.8z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st2" d="M39.8,16c-0.2-0.2-0.5-0.4-0.7-0.6c-1.2,3.6-4.5,6.1-8.5,6.1h-7.3l5.5,5.5l0,0c3.1,3,8,3,11.1,0
|
||||
C42.8,23.9,42.8,19,39.8,16z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st3" d="M30.5,4.8c-0.3,0-0.7,0-1,0.1c1.7,3.3,1.2,7.5-1.7,10.3l-5.2,5.2h7.8c4.3,0,7.8-3.5,7.8-7.8
|
||||
C38.4,8.3,34.9,4.8,30.5,4.8z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path class="st4" d="M27.1,3.4c-3.1-3-8-3-11.1,0c-0.2,0.2-0.4,0.5-0.6,0.7c3.6,1.2,6.2,4.5,6.2,8.5v7.3l5.5-5.5l0,0
|
||||
C30.2,11.4,30.2,6.4,27.1,3.4z"/>
|
||||
</g>
|
||||
</g>
|
||||
<path class="st4" d="M15.3,15.2l0.2,0.2l5,4.9h0l0-7.8v0c0-4.3-3.5-7.8-7.8-7.8c-4.3,0-7.8,3.5-7.8,7.8c0,0.3,0,0.6,0.1,1
|
||||
C8.3,11.9,12.5,12.4,15.3,15.2z"/>
|
||||
<path class="st1" d="M21.6,21.5L0,21.5c0-2.3,0.9-4.6,2.6-6.3c3.5-3.5,9.2-3.5,12.7,0L21.6,21.5L21.6,21.5z"/>
|
||||
<path class="st1" d="M21.6,21.5v8.6l0,0.3c0,4.9-4,8.9-9,8.9c-4.9,0-9-4-9-8.9c0-4.9,4-8.9,9-8.9H21.6L21.6,21.5z"/>
|
||||
<path class="st4" d="M4.2,27.6c0.1-0.2,0.1-0.4,0.2-0.5c0,0,0,0,0-0.1c0.1-0.2,0.2-0.4,0.3-0.6c0,0,0-0.1,0.1-0.1
|
||||
c0.1-0.2,0.2-0.4,0.3-0.5c0,0,0,0,0-0.1c0.1-0.2,0.2-0.3,0.3-0.5c0,0,0-0.1,0.1-0.1c0.1-0.2,0.2-0.3,0.4-0.5c0,0,0.1-0.1,0.1-0.1
|
||||
c0.1-0.1,0.3-0.3,0.4-0.4c0,0,0,0,0,0c0.1-0.1,0.3-0.3,0.4-0.4c0,0,0.1-0.1,0.1-0.1c0.2-0.1,0.3-0.3,0.5-0.4c0,0,0,0,0.1,0
|
||||
c0.2-0.1,0.3-0.2,0.5-0.3c0,0,0.1,0,0.1-0.1c0.2-0.1,0.3-0.2,0.5-0.3c0,0,0.1,0,0.1-0.1c0.2-0.1,0.4-0.2,0.5-0.3c0,0,0,0,0,0
|
||||
C9.4,22.1,9.6,22,9.8,22c0,0,0.1,0,0.1,0c0.2-0.1,0.4-0.1,0.6-0.2c0,0,0.1,0,0.1,0c0.2,0,0.4-0.1,0.6-0.1c0,0,0.1,0,0.1,0
|
||||
c0.2,0,0.4-0.1,0.6-0.1c0,0,0.1,0,0.1,0c0.2,0,0.4,0,0.7,0H20L14.5,16c-3.1-3-8-3-11.1,0c-3.1,3-3.1,8,0,11
|
||||
C3.7,27.2,3.9,27.4,4.2,27.6C4.2,27.6,4.2,27.6,4.2,27.6z"/>
|
||||
<path class="st5" d="M14.5,16l4.4,4.3H13l-0.3,0c-3.6,0-6.6-2.4-7.5-5.7C8.1,13,12,13.5,14.5,16L14.5,16L14.5,16z"/>
|
||||
<path class="st5" d="M20.5,12.6v6.2l-4.2-4.1l-0.2-0.2c-2.5-2.5-3-6.3-1.3-9.3C18.1,6,20.5,9,20.5,12.6L20.5,12.6L20.5,12.6z"/>
|
||||
<path class="st5" d="M27.1,14.4l-4.4,4.3v-5.8l0-0.3c0-3.6,2.4-6.6,5.7-7.5C30.1,8,29.7,11.9,27.1,14.4L27.1,14.4L27.1,14.4z"/>
|
||||
<path class="st6" d="M30.5,20.3h-6.2l4.2-4.1l0.2-0.2c2.5-2.5,6.4-2.9,9.3-1.3C37.2,17.9,34.1,20.3,30.5,20.3L30.5,20.3L30.5,20.3z
|
||||
"/>
|
||||
<path class="st7" d="M28.7,27l-4.4-4.3h5.9l0.3,0c3.6,0,6.6,2.4,7.5,5.7C35.1,29.9,31.3,29.5,28.7,27L28.7,27L28.7,27z"/>
|
||||
<path class="st7" d="M22.8,30.4v-6.2l4.2,4.1l0.2,0.2c2.5,2.5,3,6.3,1.3,9.3C25.2,36.9,22.8,33.9,22.8,30.4L22.8,30.4L22.8,30.4z"
|
||||
/>
|
||||
<path class="st7" d="M16.1,28.6l4.4-4.3v5.8l0,0.3c0,3.6-2.4,6.6-5.7,7.5C13.1,34.9,13.6,31.1,16.1,28.6L16.1,28.6L16.1,28.6z"/>
|
||||
<path class="st7" d="M12.7,22.6h6.2l-4.2,4.1L14.5,27C12,29.5,8.1,30,5.1,28.3C6.1,25,9.1,22.6,12.7,22.6L12.7,22.6L12.7,22.6z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 5.7 KiB |
@@ -52,6 +52,9 @@
|
||||
<paper-item>Share</paper-item>
|
||||
<paper-item>Settings</paper-item>
|
||||
<paper-item>Help</paper-item>
|
||||
<paper-item>
|
||||
<paper-item-body><a href="login.html#logout">Logout</a></paper-item-body>
|
||||
</paper-item>
|
||||
</paper-menu>
|
||||
</paper-menu-button>
|
||||
|
||||
|
152
react-app/login.html
Normal file
152
react-app/login.html
Normal file
@@ -0,0 +1,152 @@
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>SFS - React</title>
|
||||
|
||||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
<!--REACT-->
|
||||
<script src="build/react.js"></script>
|
||||
<script src="build/react-dom.js"></script>
|
||||
|
||||
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
|
||||
|
||||
<!--POLYMER COMPONENTS-->
|
||||
<link rel="import" href="bower_components/paper-scroll-header-panel/paper-scroll-header-panel.html">
|
||||
<link rel="import" href="bower_components/paper-toolbar/paper-toolbar.html">
|
||||
<link rel="import" href="bower_components/iron-icons/iron-icons.html">
|
||||
<link rel="import" href="bower_components/paper-icon-button/paper-icon-button.html">
|
||||
<link rel="import" href="bower_components/paper-styles/color.html">
|
||||
<link rel="import" href="bower_components/paper-menu-button/paper-menu-button.html">
|
||||
<link rel="import" href="bower_components/iron-flex-layout/iron-flex-layout.html">
|
||||
<link rel="import" href="bower_components/paper-drawer-panel/paper-drawer-panel.html">
|
||||
|
||||
<!--ALFRESCO CUSTOM WEBCOMPONENTS-->
|
||||
<link rel="import" href="webcomponents/file-upload/file-upload.html">
|
||||
<link rel="import" href="webcomponents/alfresco-file-list/src/alfresco-file-list.html">
|
||||
|
||||
<!--STYLES-->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
|
||||
<link rel="import" href="css/style.html">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script src="src/auth.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<paper-scroll-header-panel fixed>
|
||||
|
||||
<!-- Do not show toolbar on login page -->
|
||||
<!--
|
||||
<paper-toolbar>
|
||||
<img src="img/logo_small.png" class="logo-header">
|
||||
<div class="spacer">
|
||||
<div class="search-box bottom">
|
||||
<input placeholder="Search files and folders">
|
||||
<paper-icon-button class="search-header-search-icon" icon="search"></paper-icon-button>
|
||||
</div>
|
||||
</div>
|
||||
<img className="nav-logo" src="http://facebook.github.io/react/img/logo.svg" width="60" height="60" />
|
||||
|
||||
<paper-menu-button>
|
||||
<paper-icon-button icon="menu" class="dropdown-trigger"></paper-icon-button>
|
||||
<paper-menu class="dropdown-content">
|
||||
<paper-item>Share</paper-item>
|
||||
<paper-item>Help</paper-item>
|
||||
</paper-menu>
|
||||
</paper-menu-button>
|
||||
|
||||
</paper-toolbar>
|
||||
-->
|
||||
|
||||
<div class="content">
|
||||
<div id="content">
|
||||
|
||||
<div id="login">
|
||||
<div class="logo"></div>
|
||||
<div class="messages"></div>
|
||||
<form name="loginForm">
|
||||
<div class="form-group">
|
||||
<label for="userName">Username</label>
|
||||
<input id="userName" name="username" type="text" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="userName">Password</label>
|
||||
<input id="password" name="password" type="password" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button id="loginButton" class="btn btn-primary">Log In</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
var alfUrl = 'http://192.168.99.100:8080/alfresco', loginUrl = '/service/api/login',
|
||||
logoutUrl = '/service/api/login/ticket';
|
||||
|
||||
function onLogin(e) {
|
||||
e.preventDefault();
|
||||
var username = document.getElementById('userName').value, password = document.getElementById('password').value;
|
||||
console.log('Login attempt', username, password);
|
||||
if (username !== '' && password !== '') {
|
||||
doLoginXhr(username, password);
|
||||
}
|
||||
}
|
||||
|
||||
function doLoginXhr(username, password) {
|
||||
sendXhr({
|
||||
url: loginUrl,
|
||||
jsonData: {
|
||||
username: username,
|
||||
password: password
|
||||
}
|
||||
}).then(onLoginSuccess, onLoginFailure);
|
||||
}
|
||||
|
||||
function onLoginSuccess(resp) {
|
||||
console.log('Login success', resp.json.data.ticket);
|
||||
setTicket(resp.json.data.ticket);
|
||||
window.location = location.protocol + "//" + location.host + "/index.html";
|
||||
}
|
||||
|
||||
function onLoginFailure(json) {
|
||||
document.querySelector('#login .messages').innerHTML = '<span class="error">Could not log in with the specified username and password, please try again</span>';
|
||||
document.querySelector('#password').value = "";
|
||||
console.log('Login failed', json);
|
||||
}
|
||||
|
||||
function doLogoutXhr() {
|
||||
if (getTicket()) {
|
||||
sendXhr({
|
||||
url: logoutUrl + '/' + getTicket(),
|
||||
method: "DELETE"
|
||||
}).then(onLogoutSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
function onLogoutSuccess(resp, json) {
|
||||
console.log('Logout success', json);
|
||||
deleteTicket();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var loginForm = document.querySelector('form[name="loginForm"]');
|
||||
loginForm.addEventListener('submit', onLogin);
|
||||
|
||||
if (location.hash == '#logout') {
|
||||
doLogoutXhr();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</paper-scroll-header-panel>
|
||||
|
||||
|
||||
</body>
|
||||
<script src="build/helloworld.js"></script>
|
||||
</html>
|
57
react-app/src/auth.js
vendored
Normal file
57
react-app/src/auth.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
var alfUrl = 'http://192.168.99.100:8080/alfresco', loginUrl = '/service/api/login',
|
||||
logoutUrl = '/service/api/login/ticket';
|
||||
|
||||
function sendXhr(options) {
|
||||
if (!options.url) {
|
||||
throw 'URL must be specified';
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
var xhr = new XMLHttpRequest(), url = alfUrl + options.url, ticket = getTicket(), defaultMethod, requestBody = null;
|
||||
if (ticket && url != loginUrl) {
|
||||
console.log('Adding ticket ' + ticket);
|
||||
url += (url.indexOf('?') == -1 ? '?' : '&') + 'alf_ticket=' + ticket;
|
||||
}
|
||||
if (options.data) {
|
||||
requestBody = options.data;
|
||||
} else if (options.jsonData) {
|
||||
requestBody = JSON.stringify(options.jsonData);
|
||||
}
|
||||
defaultMethod = requestBody === null ? 'GET' : 'POST';
|
||||
xhr.addEventListener('load', function reqListener () {
|
||||
var status = this.status,
|
||||
json = this.responseText !== null && this.responseText.indexOf('{') == 0 ?
|
||||
JSON.parse(this.responseText) : null;
|
||||
this.json = json;
|
||||
if (status >= 200 && status < 300) {
|
||||
resolve(this);
|
||||
} else {
|
||||
reject(this);
|
||||
}
|
||||
});
|
||||
xhr.addEventListener('error', function reqListener () {
|
||||
reject(this);
|
||||
});
|
||||
xhr.open(options.method || defaultMethod, url);
|
||||
if (options.acceptType) {
|
||||
xhr.setRequestHeader('Accept', options.acceptType);
|
||||
}
|
||||
if (requestBody) {
|
||||
xhr.setRequestHeader('Content-Type', options.contentType || 'application/json');
|
||||
xhr.send(requestBody);
|
||||
} else {
|
||||
xhr.send();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getTicket() {
|
||||
return sessionStorage.getItem('loginTicket');
|
||||
}
|
||||
|
||||
function setTicket(ticket) {
|
||||
sessionStorage.setItem('loginTicket', ticket);
|
||||
}
|
||||
|
||||
function deleteTicket() {
|
||||
sessionStorage.removeItem('loginTicket');
|
||||
}
|
@@ -6,6 +6,7 @@
|
||||
|
||||
<!-- Importing Web Component's Polyfill -->
|
||||
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
|
||||
<script src="src/auth.js"></script>
|
||||
|
||||
<!-- Importing Custom Elements -->
|
||||
<link rel="import" href="src/alfresco-file-list.html">
|
||||
|
@@ -135,6 +135,15 @@
|
||||
};
|
||||
}
|
||||
|
||||
.paper-toolbar-0 {
|
||||
color: black;
|
||||
}
|
||||
|
||||
paper-item a {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
@@ -198,6 +207,65 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
var alfUrl = 'http://192.168.99.100:8080/alfresco', loginUrl = '/service/api/login',
|
||||
logoutUrl = '/service/api/login/ticket';
|
||||
|
||||
function sendXhr(options) {
|
||||
if (!options.url) {
|
||||
throw 'URL must be specified';
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
var xhr = new XMLHttpRequest(), url = alfUrl + options.url, ticket = getTicket(), defaultMethod, requestBody = null;
|
||||
if (ticket && url != loginUrl) {
|
||||
console.log('Adding ticket ' + ticket);
|
||||
url += (url.indexOf('?') == -1 ? '?' : '&') + 'alf_ticket=' + ticket;
|
||||
}
|
||||
if (options.data) {
|
||||
requestBody = options.data;
|
||||
} else if (options.jsonData) {
|
||||
requestBody = JSON.stringify(options.jsonData);
|
||||
}
|
||||
defaultMethod = requestBody === null ? 'GET' : 'POST';
|
||||
xhr.addEventListener('load', function reqListener () {
|
||||
var status = this.status,
|
||||
json = this.responseText !== null && this.responseText.indexOf('{') == 0 ?
|
||||
JSON.parse(this.responseText) : null;
|
||||
this.json = json;
|
||||
if (status >= 200 && status < 300) {
|
||||
resolve(this);
|
||||
} else {
|
||||
reject(this);
|
||||
}
|
||||
});
|
||||
xhr.addEventListener('error', function reqListener () {
|
||||
reject(this);
|
||||
});
|
||||
xhr.open(options.method || defaultMethod, url);
|
||||
if (options.acceptType) {
|
||||
xhr.setRequestHeader('Accept', options.acceptType);
|
||||
}
|
||||
if (requestBody) {
|
||||
xhr.setRequestHeader('Content-Type', options.contentType || 'application/json');
|
||||
xhr.send(requestBody);
|
||||
} else {
|
||||
xhr.send();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getTicket() {
|
||||
return sessionStorage.getItem('loginTicket');
|
||||
}
|
||||
|
||||
function setTicket(ticket) {
|
||||
sessionStorage.setItem('loginTicket', ticket);
|
||||
}
|
||||
|
||||
function deleteTicket() {
|
||||
sessionStorage.removeItem('loginTicket');
|
||||
}
|
||||
|
||||
HTMLImports.whenReady(function() {
|
||||
Polymer({
|
||||
is: "alfresco-file-list",
|
||||
@@ -205,7 +273,7 @@
|
||||
host: 'http://192.168.99.100:8080',
|
||||
|
||||
baseUrl: function(){
|
||||
return this.host + '/alfresco/service/slingshot/doclib/doclist/all/site/';
|
||||
return '/service/slingshot/doclib/doclist/all/site/';
|
||||
},
|
||||
|
||||
properties: {
|
||||
@@ -246,21 +314,19 @@
|
||||
},
|
||||
|
||||
fetchFolderFolder: function(slug) {
|
||||
function error () {
|
||||
console.log("error");
|
||||
function error (resp) {
|
||||
console.log("error", resp);
|
||||
deleteTicket();
|
||||
if (resp.status == 401) {
|
||||
window.location = location.protocol + '//' + location.host + '/login.html';
|
||||
}
|
||||
}
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", (XMLHttpRequestProgressEvent)=>{
|
||||
this.data =JSON.parse(XMLHttpRequestProgressEvent.currentTarget.response).items;
|
||||
});
|
||||
|
||||
xhr.addEventListener("error", error);
|
||||
|
||||
this.lastSlug = slug;
|
||||
xhr.open("GET", (this.baseUrl() + slug));
|
||||
xhr.withCredentials = true;
|
||||
xhr.setRequestHeader("Authorization", 'Basic ' + btoa('admin:admin'));
|
||||
xhr.send();
|
||||
function success (resp) {
|
||||
this.data = resp.json.items;
|
||||
}
|
||||
sendXhr({
|
||||
url: this.baseUrl() + slug
|
||||
}).then(success.bind(this), error);
|
||||
},
|
||||
|
||||
thumbBaseUrl: function () {
|
||||
|
Reference in New Issue
Block a user