This commit is contained in:
Juan Ferrer Toribio 2016-10-11 16:45:10 +02:00
parent 2fd4c05d92
commit b05cf79591
64 changed files with 228 additions and 172 deletions

View File

@ -1,3 +1,4 @@
#!/usr/bin/php -q
<?php
@include_once __DIR__.'/environ.php';
@ -6,4 +7,3 @@ require_once 'vn-autoload.php';
$cliApp = new Vn\Lib\CliApp ('hedera-web', __DIR__.'/rest');
$cliApp->run ();
?>

View File

@ -1,4 +1,4 @@
Copyright (C) 2015 - Juan Ferrer Toribio
Copyright (C) 2016 - Juan Ferrer Toribio
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,13 +1,13 @@
<?php
require_once (__DIR__.'/../php-vn-lib/configure.php');
require_once (__DIR__.'/../php-vn-lib/environ.php');
set_include_path (__DIR__.PATH_SEPARATOR.get_include_path ());
$vnAutoloadMap['vn/web'] = __DIR__.'/web';
const _DEBUG_MODE = TRUE;
const _CONFIG_DIR = '/home/juan/.config';
const _DEV_MODE = TRUE;
const _CONFIG_DIR = __DIR__.'/../../.config';
const _LOG_DIR = '/tmp';
const _DATA_DIR = '/tmp';

View File

@ -5,49 +5,68 @@ Hedera.Conf = new Class
,activate: function ()
{
this.$('user-model').setInfo ('u', 'user_view', 'hedera');
this.$('user-model').setInfo ('c', 'customer_view', 'hedera');
this.$('addresses').setInfo ('a', 'address_view', 'hedera');
}
,onPasswordChange: function ()
,onPassChangeClick: function ()
{
var newPassword = this.$('new-password').value;
var repeatedPassword = this.$('repeat-password').value;
this.$('old-password').value = '';
this.$('new-password').value = '';
this.$('repeat-password').value = '';
if (newPassword != '' && repeatedPassword != '')
var hasPassword = this.$('user-form').get ('hasPassword');
this.$('old-password').style.display = hasPassword ? 'block' : 'none';
this.$('change-password').show ();
if (hasPassword)
this.$('old-password').focus ();
else
this.$('new-password').focus ();
}
,onPassModifyClick: function ()
{
try {
var oldPassword = this.$('old-password').value;
var newPassword = this.$('new-password').value;
var repeatedPassword = this.$('repeat-password').value;
if (newPassword == '' && repeatedPassword == '')
throw new Error (_('Passwords empty'));
if (newPassword !== repeatedPassword)
throw new Error (_('Passwords doesn\'t match'));
var batch = new Sql.Batch ();
batch.addValue ('oldPassword', oldPassword);
batch.addValue ('newPassword', newPassword);
var query = 'CALL account.userChangePassword (#oldPassword, #newPassword)';
this.conn.execQuery (query, this.onPasswordUpdate.bind (this), batch);
}
catch (e)
{
if (newPassword === repeatedPassword)
{
var batch = new Sql.Batch ();
batch.addValue ('password', newPassword);
var query = 'UPDATE user_view SET password = SHA2(#password, 256) '
+'WHERE id = account.user_get_id () LIMIT 1';
this.conn.execQuery (query, this.onPasswordUpdate.bind (this), batch);
}
else
Htk.Toast.showError (_('PasswordsDoesntMatch'));
Htk.Toast.showError (e.message);
}
}
,onPasswordUpdate: function (resultSet)
{
if (!resultSet.fetchResult ())
return;
this.relogin ();
Htk.Toast.showMessage (_('PasswordsChanged'));
try {
resultSet.fetchResult ();
this.$('change-password').hide ();
Htk.Toast.showMessage (_('Password changed!'));
}
catch (e)
{
Htk.Toast.showError (_('Password doesn\'t meet the requirements'));
this.$('old-password').select ();
}
}
,relogin: function ()
,onPassInfoClick: function ()
{
this.conn.open (
this.$('user-form').get ('name')
,this.$('new-password').value
,Vn.Cookie.check ('vn_pass')
);
this.$('password-info').show ();
}
,onAddressesClick: function ()

View File

@ -17,3 +17,17 @@
{
margin-bottom: 0.5em;
}
.pass-change
{
max-width: 15em;
}
.pass-info
{
width: 15em;
}
.pass-info ul
{
list-style-type: none;
}

View File

@ -1,10 +1,19 @@
<vn>
<vn-group>
<db-form id="password-form">
<db-model property="model">
<custom>
SELECT length, nAlpha, nUpper, nDigits, nPunct
FROM account.userPassword
</custom>
</db-model>
</db-form>
<db-form id="user-form">
<db-model property="model" id="user-model" updatable="true">
<custom>
SELECT id, u.name, email, mail, c.user_id, c.default_address
FROM user_view u
SELECT u.id, u.name, u.hasPassword,
c.email, c.mail, c.user_id, c.default_address
FROM account.userView u
LEFT JOIN customer_view c
ON u.id = c.user_id
</custom>
@ -28,6 +37,10 @@
icon="place"
tip="_Addresses"
on-click="onAddressesClick"/>
<htk-bar-button
icon="preferences"
tip="_Change password"
on-click="onPassChangeClick"/>
</div>
<div id="form" class="conf">
<div class="box">
@ -36,19 +49,6 @@
<label for="user-name"><t>UserName</t></label>
<htk-text column="name" form="user-form"/>
</div>
<div class="form-group">
<label for="user-pass"><t>Password</t></label>
<input
id="new-password"
type="password"
placeholder="_NewPassword"
on-change="onPasswordChange"/>
<input
id="repeat-password"
type="password"
placeholder="_RepeatPassword"
on-change="onPasswordChange"/>
</div>
<div class="form-group">
<label for="email"><t>Email</t></label>
<htk-entry column="email" form="user-form"></htk-entry>
@ -60,4 +60,62 @@
</div>
</div>
</div>
<htk-popup
id="change-password"
modal="true">
<div property="child-node" class="dialog pass-change">
<div>
<input
id="old-password"
type="password"
placeholder="_Old password"/>
<input
id="new-password"
type="password"
placeholder="_New password"/>
<input
id="repeat-password"
type="password"
placeholder="_Repeat password"/>
</div>
<button class="thin" on-click="onPassModifyClick">
<t>Modify</t>
</button>
<button class="thin" on-click="onPassInfoClick">
<t>Info</t>
</button>
<div class="clear"/>
</div>
</htk-popup>
<htk-popup
id="password-info"
modal="true">
<div property="child-node" class="dialog pass-info">
<h3>
<t>Password requirements</t>
</h3>
<ul>
<li>
<htk-text form="password-form" column="length"/>
<t>characters long</t>
</li>
<li>
<htk-text form="password-form" column="nAlpha"/>
<t>alphabetic characters</t>
</li>
<li>
<htk-text form="password-form" column="nUpper"/>
<t>capital letters</t>
</li>
<li>
<htk-text form="password-form" column="nDigits"/>
<t>digits</t>
</li>
<li>
<htk-text form="password-form" column="nPunct"/>
<t>symbols</t>
</li>
</ul>
</div>
</htk-popup>
</vn>

View File

@ -22,18 +22,16 @@ Hedera.Photos = new Class
this._onResponse.bind (this));
}
,_onResponse: function (request, json, error)
,_onResponse: function (json, error)
{
this.$('submit').disabled = false;
if (json)
{
this.$('photo-id').value = '';
this.$('photo-id').focus ();
Htk.Toast.showMessage (_('ImageAdded'));
}
else
Htk.Toast.showError (error.message);
if (error)
throw error;
this.$('photo-id').value = '';
this.$('photo-id').focus ();
Htk.Toast.showMessage (_('ImageAdded'));
}
});

View File

@ -152,7 +152,6 @@
directory="catalog"
subdir="200x200"
form="item"
conn="conn"
column="Foto"
full-dir="900x900"/>
<div class="item-info">
@ -420,6 +419,7 @@
form="card"
column="Foto"
full-dir="900x900"
conn="conn"
editable="true"/>
<div class="item-info">
<h2>

View File

@ -127,17 +127,8 @@ Connection.implement
error = e;
}
if (error)
this.signalEmit ('error', error);
if (callback)
try {
callback (new Db.ResultSet (json, error));
}
catch (e)
{
this.signalEmit ('error', e);
}
}
});

View File

@ -324,38 +324,43 @@ Model.implement
this._cleanData ();
for (var i = 0; result = resultSet.fetchResult (); i++)
try {
for (var i = 0; result = resultSet.fetchResult (); i++)
if (i == this._resultIndex)
dataResult = result;
if (dataResult && typeof dataResult === 'object')
{
this.data = dataResult.data;
this.tables = dataResult.tables;
this.columns = dataResult.columns;
this.columnMap = dataResult.columnMap;
this._repairColumns ();
this._refreshRowIndexes (0);
this._refreshMainTable ();
for (column in this._requestedIndexes)
this._buildIndex (column);
var sortColumn = -1;
if (this._requestedSortName)
sortColumn = this.getColumnIndex (this._requestedSortName);
else if (this._requestedSortIndex !== -1
&& this.checkColExists (this._requestedSortIndex))
sortColumn = this._requestedSortIndex;
if (sortColumn !== -1)
this._realSort (sortColumn, this._sortWay);
this._setStatus (Status.READY);
if (!dataResult || typeof dataResult !== 'object')
throw new Error ('The provided statement doesn\'t return a result set');
}
else
catch (e)
{
this._setStatus (Status.ERROR);
throw e;
}
this.data = dataResult.data;
this.tables = dataResult.tables;
this.columns = dataResult.columns;
this.columnMap = dataResult.columnMap;
this._repairColumns ();
this._refreshRowIndexes (0);
this._refreshMainTable ();
for (column in this._requestedIndexes)
this._buildIndex (column);
var sortColumn = -1;
if (this._requestedSortName)
sortColumn = this.getColumnIndex (this._requestedSortName);
else if (this._requestedSortIndex !== -1
&& this.checkColExists (this._requestedSortIndex))
sortColumn = this._requestedSortIndex;
if (sortColumn !== -1)
this._realSort (sortColumn, this._sortWay);
this._setStatus (Status.READY);
}
,_refreshRowIndexes: function (start)

View File

@ -30,6 +30,9 @@ module.exports = new Class
,fetch: function ()
{
if (this.error)
throw this.error;
if (this.results !== null
&& this.results.length > 0)
return this.results.shift ();

View File

@ -181,7 +181,7 @@ module.exports = new Class
,_onEditClick: function (event)
{
event.stopPropagation ();
var editor = new Htk.ImageEditor ({conn: this.conn});
editor.setData (this.value, this._directory);
editor.on ('name-changed', this._onNameChange, this);

View File

@ -51,18 +51,16 @@ module.exports = new Class
this._onResponse.bind (this));
}
,_onResponse: function (request, json, error)
,_onResponse: function (json, error)
{
this.$('submit').disabled = false;
this.$('spinner').stop ();
if (json)
{
Toast.showMessage (_('ImageAdded'));
this.signalEmit ('file-uploaded', this.$('name').value);
}
else
Toast.showError (error.message);
if (error)
throw error;
Toast.showMessage (_('ImageAdded'));
this.signalEmit ('file-uploaded', this.$('name').value);
}
,setData: function (image, directory)

View File

@ -281,10 +281,18 @@ module.exports = new Class
error = e;
}
if (callback)
try {
callback (data, error);
error = null;
}
catch (e)
{
error = e;
}
if (error)
this.signalEmit ('error', error);
if (callback)
callback (data, error);
}
});

View File

@ -5,10 +5,8 @@
"devDependencies": {
"webpack": "*",
"webpack-dev-server": "*",
"split-by-name-webpack-plugin": "*",
"css-loader": "*",
"style-loader": "*",
"file-loader": "*",
"json-loader": "*",
"raw-loader": "*",
"bundle-loader": "*"

View File

@ -12,12 +12,12 @@ if ($result = $db->query ('SELECT name, content FROM metatag'))
$result->free ();
}
if (_DEBUG_MODE)
if (_DEV_MODE)
{
$this->includeJs ('http://localhost:8080/webpack-dev-server.js');
$this->includeJs ('http://localhost:8080/build/hedera-web.js');
$url = 'http://localhost:8080';
$this->includeJs ("$url/webpack-dev-server.js");
$this->includeJs ("$url/build/hedera-web.js");
}
else
$this->includeJs ('build/hedera-web.js');
?>

View File

@ -1,3 +0,0 @@
#!/bin/bash
php5 -d auto_prepend_file=configure.php "$@"

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Recover password</title>
</head>
<body>
<a href="https://verdnatura.es/#!form=account/conf">
Recover password
</a>
</body>
</html>

View File

@ -45,4 +45,3 @@ class Captcha extends Vn\Web\RestRequest
}
}
?>

View File

@ -23,4 +23,3 @@ class Log extends Vn\Web\JsonRequest
}
}
?>

View File

@ -91,4 +91,3 @@ class Login extends Vn\Web\JsonRequest
}
}
?>

View File

@ -9,4 +9,3 @@ class Logout extends Vn\Web\JsonRequest
}
}
?>

View File

@ -213,4 +213,3 @@ class Query extends Vn\Web\JsonRequest
}
?>

View File

@ -61,4 +61,3 @@ class RecoverPassword extends Vn\Web\JsonRequest
}
}
?>

View File

@ -10,4 +10,3 @@ class Supplant extends Vn\Web\JsonRequest
}
}
?>

View File

@ -109,4 +109,3 @@ class Add extends Vn\Web\JsonRequest
}
}
?>

View File

@ -20,4 +20,3 @@ class Invoice extends Vn\Web\RestRequest
}
}
?>

View File

@ -43,4 +43,3 @@ class Clean extends Edi\Method
}
}
?>

View File

@ -162,4 +162,3 @@ class Message
}
}
?>

View File

@ -42,4 +42,3 @@ abstract class Method extends \Vn\Lib\Method
}
}
?>

View File

@ -25,4 +25,3 @@ class Section
}
}
?>

View File

@ -35,4 +35,3 @@ class Segment
}
}
?>

View File

@ -218,4 +218,3 @@ class Load extends Edi\Method
}
}
?>

View File

@ -122,4 +122,4 @@ class Update extends Vn\Lib\Method
}
}
?>

View File

@ -144,4 +144,3 @@ class Image
}
}
?>

View File

@ -68,4 +68,3 @@ class Resize extends Vn\Lib\Method
}
}
?>

View File

@ -127,4 +127,3 @@ class Sync extends Vn\Lib\Method
}
}
?>

View File

@ -95,4 +95,3 @@ class Thumb extends Vn\Web\RestRequest
}
}
?>

View File

@ -145,4 +145,3 @@ class Upload extends Vn\Web\JsonRequest
}
}
?>

View File

@ -55,5 +55,4 @@ class Util
return $info;
}
}
?>

View File

@ -68,4 +68,3 @@ class Contact extends Vn\Web\JsonRequest
}
}
?>

View File

@ -49,4 +49,3 @@ class ExchangeRate extends Vn\Lib\Method
}
}
?>

View File

@ -92,4 +92,4 @@ class Mail extends Vn\Lib\Method
}
}
?>

View File

@ -49,4 +49,4 @@ class Sms extends Vn\Web\JsonRequest
}
}
?>

View File

@ -51,4 +51,3 @@ class VisitsSync extends Vn\Lib\Method
}
}
?>

View File

@ -104,4 +104,3 @@ class ConfirmMail extends Vn\Lib\Method
}
}
?>

View File

@ -13,4 +13,3 @@ class ConfirmPost extends Vn\Web\RestRequest
}
}
?>

View File

@ -94,4 +94,3 @@ function procesaNotificacionSIS ($XML)
return $xmlMessage;
*/}
?>

View File

@ -33,4 +33,3 @@ class Tpv
}
}
?>

View File

@ -54,4 +54,3 @@ class Transaction extends Vn\Web\JsonRequest
}
}
?>

View File

@ -73,4 +73,3 @@ class App extends \Vn\Lib\App
}
}
?>

View File

@ -53,4 +53,3 @@ class DbSessionHandler implements \SessionHandlerInterface
}
}
?>

View File

@ -14,7 +14,7 @@ class HtmlService extends Service
$db = $this->db;
if (!$this->isHttps ()
&& $db->getValue ('SELECT https FROM config') && !_DEBUG_MODE)
&& $db->getValue ('SELECT https FROM config') && !_DEV_MODE)
{
header ("Location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}");
exit (0);
@ -139,4 +139,3 @@ class HtmlService extends Service
}
}
?>

View File

@ -19,4 +19,3 @@ class JsonException
var $trace = NULL;
}
?>

View File

@ -14,4 +14,3 @@ class JsonReply
var $warnings = NULL;
}
?>

View File

@ -7,4 +7,3 @@ namespace Vn\Web;
**/
abstract class JsonRequest extends RestRequest {}
?>

View File

@ -58,12 +58,12 @@ class JsonService extends RestService
$json = new JsonException ();
if (_DEBUG_MODE || $errno & $eUser)
if (_DEV_MODE || $errno & $eUser)
$json->message = $message;
else
$json->message = 'Something went wrong';
if (_DEBUG_MODE)
if (_DEV_MODE)
{
$json->code = $errno;
$json->file = $file;
@ -91,7 +91,7 @@ class JsonService extends RestService
{
$json = new JsonException ();
if (_DEBUG_MODE || $e instanceof Lib\UserException)
if (_DEV_MODE || $e instanceof Lib\UserException)
{
$json->exception = get_class ($e);
$json->message = $e->getMessage ();
@ -102,7 +102,7 @@ class JsonService extends RestService
$json->message = 'Something went wrong';
}
if (_DEBUG_MODE)
if (_DEV_MODE)
{
$json->code = $e->getCode ();
$json->file = $e->getFile ();
@ -118,4 +118,3 @@ class JsonService extends RestService
}
}
?>

View File

@ -87,4 +87,3 @@ class Jwt
}
}
?>

View File

@ -19,4 +19,3 @@ abstract class RestRequest extends \Vn\Lib\Method
var $service;
}
?>

View File

@ -11,7 +11,7 @@ class RestService extends Service
{
function run ()
{
ini_set ('display_errors', _DEBUG_MODE);
ini_set ('display_errors', _DEV_MODE);
set_error_handler ([$this, 'errorHandler'], E_ALL);
set_exception_handler ([$this, 'exceptionHandler']);
@ -59,4 +59,3 @@ class RestService extends Service
}
}
?>

View File

@ -310,4 +310,3 @@ abstract class Service
}
}
?>

View File

@ -42,4 +42,3 @@ class Util
}
}
?>

View File

@ -1,7 +1,6 @@
var webpack = require ('webpack');
var path = require ('path');
var SplitPlugin = require ('./split-plugin');
var devMode = true;
@ -29,10 +28,8 @@ module.exports =
fallback: process.env.NODE_PATH
},
plugins: [
new SplitPlugin (),
/* new webpack.IgnorePlugin (new RegExp ('/.{2}/(forms|pages|rest)'))
new webpack.optimize.UglifyJsPlugin ({minimize: true})
*/ ],
devtool: 'source-map'
// new webpack.optimize.UglifyJsPlugin ({minimize: true})
],
// devtool: 'source-map'
};