Peticiones XHR con token

This commit is contained in:
Juan Ferrer Toribio 2017-05-18 17:35:07 +02:00
parent 2c7a37c4b6
commit a2ac778c9a
48 changed files with 167 additions and 156 deletions

View File

@ -10,3 +10,4 @@ rules:
radix: 0
guard-for-in: 0
camelcase: 0
default-case: 0

View File

@ -5,6 +5,6 @@
"main": "index.js",
"repository": {
"type": "git",
"url": "http://git.verdnatura.es:/salix"
"url": "https://git.verdnatura.es/salix"
}
}

View File

@ -3,7 +3,7 @@
<div class="box">
<img src="./logo.svg"/>
<form name="form" ng-submit="$ctrl.submit()">
<vn-textfield label="User" model="$ctrl.email"></vn-textfield>
<vn-textfield vn-id="userField" label="User" model="$ctrl.email"></vn-textfield>
<vn-textfield label="Password" model="$ctrl.password" type="password"></vn-textfield>
<div class="footer">
<vn-submit label="Enter"></vn-submit>

View File

@ -10,6 +10,7 @@ export default class Controller {
}
submit() {
if (!(this.email && this.password)) {
this.focusUser();
this.showMessage('Please insert your email and password');
return;
}
@ -46,7 +47,8 @@ export default class Controller {
}
onLoginErr(json) {
this.loading = false;
this.model.password = '';
this.password = '';
this.focusUser();
let message;
@ -63,8 +65,12 @@ export default class Controller {
this.showMessage(message);
}
focusUser() {
this.$.userField.select();
this.$.userField.focus();
}
showMessage(message) {
this.$.snackbar.show({message: message});
this.snackbar.show({message: message});
}
}
Controller.$inject = ['$element', '$scope', '$window', '$http'];

View File

@ -5,6 +5,6 @@
"main": "index.js",
"repository": {
"type": "git",
"url": "http://git.verdnatura.es:/salix"
"url": "https://git.verdnatura.es/salix"
}
}

View File

@ -2,25 +2,25 @@
vn-id="watcher"
url="/client/api/Addresses"
id-field="id"
data="addressData.address"
data="$ctrl.address"
form="form">
</vn-watcher>
<form name="form" ng-submit="addressData.onSubmit()" pad-medium>
<form name="form" ng-submit="$ctrl.onSubmit()" pad-medium>
<vn-card >
<vn-vertical pad-large>
<vn-title>Consignatario</vn-title>
<vn-horizontal>
<vn-check vn-one label="Predeterminado" field="addressData.address.default"></vn-check>
<vn-check vn-one label="Predeterminado" field="$ctrl.address.default"></vn-check>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Consignatario" field="addressData.address.consignee" vn-focus></vn-textfield>
<vn-textfield vn-one label="Domicilio" field="addressData.address.street"></vn-textfield>
<vn-textfield vn-one label="Consignatario" field="$ctrl.address.consignee" vn-focus></vn-textfield>
<vn-textfield vn-one label="Domicilio" field="$ctrl.address.street"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Código Postal" field="addressData.address.postcode"></vn-textfield>
<vn-textfield vn-one label="Municipio" field="addressData.address.city"></vn-textfield>
<vn-textfield vn-one label="Código Postal" field="$ctrl.address.postcode"></vn-textfield>
<vn-textfield vn-one label="Municipio" field="$ctrl.address.city"></vn-textfield>
<vn-autocomplete vn-one
field="addressData.address.provinceFk"
field="$ctrl.address.provinceFk"
url="/client/api/Provinces"
show-field="name"
value-field="id"
@ -29,14 +29,14 @@
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one
field="addressData.address.agencyFk"
field="$ctrl.address.agencyFk"
url="/client/api/AgencyServices"
show-field="name"
value-field="id"
label="Agencia">
</vn-autocomplete>
<vn-textfield vn-one label="Teléfono" field="addressData.address.phone"></vn-textfield>
<vn-textfield vn-one label="Móvil" field="addressData.address.mobile"></vn-textfield>
<vn-textfield vn-one label="Teléfono" field="$ctrl.address.phone"></vn-textfield>
<vn-textfield vn-one label="Móvil" field="$ctrl.address.mobile"></vn-textfield>
</vn-horizontal>
</vn-vertical>
</vn-card>

View File

@ -2,7 +2,7 @@ import {module} from '../module';
class Controller {
constructor($scope, $state) {
this.$scope = $scope;
this.$ = $scope;
this.$state = $state;
this.address = {
client: parseInt($state.params.id),
@ -10,7 +10,7 @@ class Controller {
};
}
onSubmit() {
this.$scope.watcher.submit().then(
this.$.watcher.submit().then(
() => this.$state.go('clientCard.addresses')
);
}
@ -20,7 +20,6 @@ Controller.$inject = ['$scope', '$state'];
export const NAME = 'vnAddressCreate';
export const COMPONENT = {
template: require('./index.html'),
controllerAs: 'addressData',
controller: Controller
};
module.component(NAME, COMPONENT);

View File

@ -5,6 +5,6 @@
"main": "index.js",
"repository": {
"type": "git",
"url": "http://git.verdnatura.es:/salix"
"url": "https://git.verdnatura.es/salix"
}
}

View File

@ -34,14 +34,3 @@ export function getProviderName(name) {
export function getTemplateName(componentName, frameworkName) {
return componentName + '.' + frameworkName + '.html';
}
export function getVendorDependencies(vendors) {
let dependencies = [];
Object.keys(vendors).forEach(vendor => {
let name = vendors[vendor].name;
if (name) {
dependencies.push(name);
}
});
return dependencies;
}

View File

@ -1,7 +1,12 @@
/**
* Rewrited CSS rules from Material Design Lite.
* TODO: don't use !important
*/
.mdl-textfield {
width: 100%;
}
/* TODO: No utilizar !important */
.mdl-button {
font-weight: bolder;
color: #ffa410;

View File

@ -1,5 +1,10 @@
import * as vendors from 'vendor';
import {getVendorDependencies} from './lib/util';
const DEPENDENCIES = getVendorDependencies(vendors);
export const module = vendors.ng.module('vnCore', DEPENDENCIES);
let deps = [];
Object.keys(vendors).forEach(vendor => {
let name = vendors[vendor].name;
if (name)
deps.push(name);
});
export const module = vendors.ng.module('vnCore', deps);

View File

@ -48,6 +48,18 @@ export default class Textfield extends Component {
let clearButton = this.element.querySelector('button');
clearButton.style.visibility = show ? 'visible' : 'hidden';
}
/**
* Selects the textfield.
*/
select() {
this.input.select();
}
/**
* Puts the focus on the textfield.
*/
focus() {
this.input.focus();
}
}
Textfield.$inject = ['$element', '$scope', '$attrs'];

View File

@ -1,32 +1,39 @@
import {module} from '../../module';
import ngModule from '../../module';
import './style.scss';
export const NAME = 'vnApp';
export const COMPONENT = {
template: require('./app.html')
};
module.component(NAME, COMPONENT);
ngModule.component(NAME, COMPONENT);
vnAppLogger.$inject = ['$document'];
function vnAppLogger($document) {
return {
showMessage: function (message) {
showMessage: function(message) {
let snackbar = $document.find('vn-snackbar').controller('vnSnackbar');
snackbar.show({message: message});
},
showError: function(message) {
this.showMessage(`Error: ${message}`);
}
}
};
}
module.provider('vnAppLogger', function() {this.$get = vnAppLogger;});
ngModule.provider('vnAppLogger', function() {
this.$get = vnAppLogger;
});
vnAppInterceptor.$inject = ['$q', '$rootScope', 'vnAppLogger', '$translate'];
function vnAppInterceptor($q, $rootScope, logger, $translate) {
vnAppInterceptor.$inject = ['$q', '$rootScope', 'vnAppLogger', '$translate', '$cookies'];
function vnAppInterceptor($q, $rootScope, logger, $translate, $cookies) {
$rootScope.loading = false;
return {
request: function(config) {
$rootScope.loading = true;
let token = $cookies.get('vnToken');
if (token)
config.url = config.url += '?access_token=' + encodeURIComponent(token);
return config;
},
requestError: function(rejection) {
@ -34,9 +41,9 @@ function vnAppInterceptor($q, $rootScope, logger, $translate) {
},
response: function(response) {
switch (response.config.method) {
case 'PUT':
case 'POST':
logger.showMessage($translate.instant('Data saved!'));
case 'PUT':
case 'POST':
logger.showMessage($translate.instant('Data saved!'));
}
$rootScope.loading = false;
return response;
@ -49,10 +56,10 @@ function vnAppInterceptor($q, $rootScope, logger, $translate) {
}
};
}
module.factory('vnAppInterceptor', vnAppInterceptor);
ngModule.factory('vnAppInterceptor', vnAppInterceptor);
interceptorConfig.$inject = ['$httpProvider'];
function interceptorConfig($httpProvider) {
$httpProvider.interceptors.push('vnAppInterceptor');
}
module.config(interceptorConfig);
ngModule.config(interceptorConfig);

View File

@ -1,5 +1,5 @@
<vn-horizontal>
<ul style="list-style-type: none; margin: 0; padding: 0; width: 100%; color: #666;">
<vn-menu-item ng-repeat="item in action.items" item = "item"></vn-menu-item>
<vn-menu-item ng-repeat="item in $ctrl.items" item = "item"></vn-menu-item>
</ul>
</vn-horizontal>

View File

@ -1,12 +1,8 @@
import template from './actions.html';
import {module} from '../../module';
import ngModule from '../../module';
export const NAME = 'vnActions';
export const COMPONENT = {
template: template,
controllerAs: "action",
ngModule.component('vnActions', {
template: require('./actions.html'),
bindings: {
items: '<'
}
};
module.component(NAME, COMPONENT);
});

View File

@ -1,5 +1,5 @@
<vn-card >
<vn-vertical pad-medium-top pad-medium-bottom>
<vn-actions items="menu.items"></vn-actions>
<vn-actions items="$ctrl.items"></vn-actions>
</vn-vertical>
</vn-card>

View File

@ -1,13 +1,9 @@
import {module} from '../../module';
import template from './left-menu.html';
import ngModule from '../../module';
import './style.css';
export const NAME = 'vnLeftMenu';
export const COMPONENT = {
template: template,
controllerAs: "menu",
ngModule.component('vnLeftMenu', {
template: require('./left-menu.html'),
bindings: {
items: '<'
}
};
module.component(NAME, COMPONENT);
});

View File

@ -1,7 +1,7 @@
<li>
<a ui-sref="{{menu.item.href}}" style="display: block; text-decoration: none; color: inherit; padding: .5em 2em;">
<a ui-sref="{{$ctrl.item.href}}" style="display: block; text-decoration: none; color: inherit; padding: .5em 2em;">
<i class="material-icons" style="float: right; margin-left: .4em;">keyboard_arrow_right</i>
<i class="material-icons" style="vertical-align: middle; margin-right: .4em;">{{menu.item.icon}}</i>
<span>{{menu.item.description}}</span>
<i class="material-icons" style="vertical-align: middle; margin-right: .4em;">{{$ctrl.item.icon}}</i>
<span>{{$ctrl.item.description}}</span>
</a>
</li>

View File

@ -1,11 +1,8 @@
import {module} from '../../module';
import ngModule from '../../module';
export const NAME = 'vnMenuItem';
export const COMPONENT = {
ngModule.component('vnMenuItem', {
template: require('./menu-item.html'),
controllerAs: 'menu',
bindings: {
item: '<'
}
};
module.component(NAME, COMPONENT);
});

View File

@ -1,8 +1,8 @@
<div style="position: fixed; top: 0; right: 0; padding: .8em 1.5em; z-index: 10;">
<vn-icon icon="apps" id="apps" translate-attr="{title: 'Applications'}"></vn-icon>
<vn-icon icon="notifications" translate-attr="{title: 'Notifications'}"></vn-icon>
<vn-icon icon="language" translate-attr="{title: 'Change language'}" ng-click="mainMenu.onChangeLanguage()"></vn-icon>
<vn-icon icon="exit_to_app" translate-attr="{title: 'Logout'}" ng-click="mainMenu.onLogoutClick()"></vn-icon>
<vn-icon icon="language" translate-attr="{title: 'Change language'}" ng-click="$ctrl.onChangeLanguage()"></vn-icon>
<vn-icon icon="exit_to_app" translate-attr="{title: 'Logout'}" ng-click="$ctrl.onLogoutClick()"></vn-icon>
<vn-icon icon="account_circle" translate-attr="{title: 'Profile'}" style="font-size: 35px;"></vn-icon>
<ul class="mdl-menu mdl-js-menu mdl-menu--bottom-right" pad-medium for="apps">
<vn-horizontal>

View File

@ -1,22 +1,23 @@
import ngModule from '../../module';
import './style.scss';
import {module} from '../../module';
export const NAME = 'vnMainMenu';
export const COMPONENT = {
template: require('./main-menu.html'),
controllerAs: "mainMenu",
controller: controller
};
module.component(NAME, COMPONENT);
controller.$inject = ['$translate', '$window', '$document'];
function controller($translate, $window, $document) {
this.onLogoutClick = function() {
$window.location = 'salix/logout';
};
this.onChangeLanguage = function() {
let lang = $translate.use() == 'en' ? 'es' : 'en';
$translate.use(lang);
export default class Controller {
constructor($translate, $window) {
this.$translate = $translate;
this.$window = $window;
}
onLogoutClick() {
this.$window.location = 'salix/logout';
}
onChangeLanguage() {
let lang = this.$translate.use() == 'en' ? 'es' : 'en';
this.$translate.use(lang);
console.log(`Locale changed: ${lang}`);
};
}
}
}
Controller.$inject = ['$translate', '$window'];
ngModule.component('vnMainMenu', {
template: require('./main-menu.html'),
controller: Controller
});

View File

@ -1,7 +1,6 @@
import {module} from '../../module';
require('./style.css');
import ngModule from '../../module';
class Controller {
export default class Controller {
constructor($element, $scope, $document, $compile, vnPopover, $window) {
this.element = $element[0];
this.$scope = $scope;
@ -36,8 +35,7 @@ class Controller {
}
Controller.$inject = ['$element', '$scope', '$document', '$compile', 'vnPopover', '$window'];
export const NAME = 'vnSearchbar';
export const COMPONENT = {
ngModule.component('vnSearchbar', {
template: require('./searchbar.html'),
bindings: {
index: '<',
@ -46,5 +44,4 @@ export const COMPONENT = {
popover: '@'
},
controller: Controller
};
module.component(NAME, COMPONENT);
});

View File

@ -1,8 +1,6 @@
import {module} from '../../module';
import ngModule from '../../module';
export const NAME = 'vnTopbar';
export const COMPONENT = {
ngModule.component('vnTopbar', {
template: require('./topbar.html'),
transclude: true
};
module.component(NAME, COMPONENT);
});

View File

@ -1,13 +1,13 @@
import {module} from './module';
import ngModule from './module';
config.$inject = ['$translatePartialLoaderProvider'];
export function config($translatePartialLoaderProvider) {
$translatePartialLoaderProvider.addPart('salix');
}
module.config(config);
ngModule.config(config);
run.$inject = ['$window', '$rootScope'];
export function run($window, $rootScope) {
$window.validations = {};
}
module.run(run);
ngModule.run(run);

View File

@ -1,6 +1,6 @@
import './spliting';
import deps from 'spliting/modules.json';
import {module} from './module';
import ngModule from './module';
import {splitingRegister} from 'core';
function loader(moduleName) {
@ -44,4 +44,4 @@ function config($stateProvider, $urlRouterProvider) {
});
}
}
module.config(config);
ngModule.config(config);

View File

@ -1,4 +1,5 @@
import {ng} from 'vendor';
import 'core';
export const module = ng.module('salix', ['vnCore']);
const ngModule = ng.module('salix', ['vnCore']);
export default ngModule;

View File

@ -1,4 +1,4 @@
import {module} from './module';
import ngModule from './module';
const HOOK_ABORTED_TRANSITION = 3;
@ -11,4 +11,4 @@ export function run($rootScope, $state) {
window.myAppErrorLog.push(error);
});
}
module.run(run);
ngModule.run(run);

View File

@ -1 +1 @@
export * from './src/vendor';
export * from './src/vendor';

View File

@ -5,6 +5,6 @@
"main": "index.js",
"repository": {
"type": "git",
"url": "http://git.verdnatura.es:/salix"
"url": "https://git.verdnatura.es/salix"
}
}

5
client/vendor/src/angular-cookies.js vendored Normal file
View File

@ -0,0 +1,5 @@
import 'angular-cookies';
export const angularCookies = {
name: 'ngCookies'
};

View File

@ -1,5 +1,5 @@
import 'angular-paging';
export const ngPaging = {
export const angularPaging = {
name: 'bw.paging'
};

View File

@ -1,6 +1,6 @@
import 'angular-translate';
import 'angular-translate-loader-partial';
export const ngTranslate = {
export const angularTranslate = {
name: 'pascalprecht.translate'
};

View File

@ -0,0 +1,5 @@
import 'angular-ui-router';
export const angularUiRouter = {
name: 'ui.router'
};

View File

@ -1,8 +1,8 @@
import * as angular from 'angular';
import * as angular from 'angular';
export const ng = {
module: angular.module,
bootstrap: angular.bootstrap,
$$minErr :angular.$$minErr,
$$minErr: angular.$$minErr,
angular: angular
}
};

View File

@ -1,4 +1,4 @@
import * as mdl from 'material-design-lite';
import 'material-design-lite/dist/material.orange-deep_orange.min.css';
export const materialdesignlite = mdl;
export const materialDesignLite = mdl;

View File

@ -1,7 +1,5 @@
import 'oclazyload';
import {getComponentName} from './util';
import 'oclazyload';
export const oclazyload = {
name: 'oc.lazyLoad',
oclazyload: getComponentName('$ocLazyLoad',true)
}
export const ocLazyLoad = {
name: 'oc.lazyLoad'
};

View File

@ -1,7 +0,0 @@
import 'angular-ui-router';
import {getComponentName} from './util';
export const uirouter = {
name: 'ui.router',
state: getComponentName('$state',true)
}

View File

@ -1,11 +0,0 @@
export function getComponentName(name, isProvider) {
if (isProvider) {
return {
name: name,
provider: name + "Provider"
};
}
return {
name: name
};
}

View File

@ -1,3 +1,3 @@
import * as validatorJs from 'validator';
import * as validatorJs from 'validator';
export const validator = validatorJs;

View File

@ -1,8 +1,9 @@
export * from './angular';
export * from './ui-router';
export * from './angular-cookies';
export * from './angular-translate';
export * from './angular-paging';
export * from './angular-ui-router';
export * from './mg-crud';
export * from './oc-lazy-load';
export * from './angular-translate';
export * from './material-design-lite';
export * from './angular-paging';
export * from './validator';

View File

@ -11,13 +11,13 @@ goto caseUsage
:caseStart
call "%0" stop
echo "Starting nginx."
echo Starting nginx.
if not exist "%nginxPrefix%\temp" (mkdir "%nginxPrefix%\temp")
start /I nginx -c "%nginxConf%" -p "%nginxPrefix%"
goto caseEnd
:caseStop
echo "Stoping nginx."
echo Stoping nginx.
if exist "%nginxPrefix%\temp\nginx.pid" (nginx -c "%nginxConf%" -p "%nginxPrefix%" -s stop)
goto caseEnd

View File

@ -9,7 +9,8 @@
"url": "http://git.verdnatura.es:/salix"
},
"dependencies": {
"angular": "^1.6.1",
"angular": "^1.6.4",
"angular-cookies": "^1.6.4",
"angular-paging": "^2.2.2",
"angular-translate": "^2.13.1",
"angular-translate-loader-partial": "^2.13.1",

View File

@ -2,6 +2,7 @@
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3000,
"aclErrorStatus": 403,
"remoting": {
"context": false,
"rest": {

View File

@ -145,8 +145,14 @@
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"principalId": "$authenticated",
"permission": "ALLOW"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}
],
"methods": {}

View File

@ -2,6 +2,7 @@
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3002,
"aclErrorStatus": 403,
"logoutSessionsOnSensitiveChanges": true,
"remoting": {
"context": false,

View File

@ -15,7 +15,7 @@ module.exports = function (app) {
validateToken(token, function(isValid) {
if (isValid) {
res.cookie('vnToken', token, {httpOnly: true});
res.cookie('vnToken', token/*, {httpOnly: true}*/);
res.redirect(continueUrl ? continueUrl : '/salix');
}
else

View File

@ -2,6 +2,7 @@
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3001,
"aclErrorStatus": 403,
"remoting": {
"context": false,
"rest": {