Merge con master

This commit is contained in:
Juan Ferrer Toribio 2017-05-02 15:48:47 +02:00
commit 25e9b37b75
11 changed files with 67 additions and 70 deletions

View File

@ -60,7 +60,7 @@ Hedera.Conf = new Class
} }
else else
{ {
Htk.Toast.showError (_('Password doesn\'t meet the requirements')); Htk.Toast.showError (error.message);
this.$('old-password').select (); this.$('old-password').select ();
} }
} }

View File

@ -2,15 +2,8 @@
class Account class Account
{ {
const USER = 1 << 1; static function sync ($db, $user, $password = NULL)
const PASS = 1 << 2;
static function sync ($db, $user, $password = NULL, $sync = self::USER)
{ {
$conf = $db->getRow (
'SELECT sambaHost, homesHost, sshUser, sshPass FROM account.accountConfig');
$sshPass = base64_decode ($conf['sshPass']);
$hasAccount = $db->getValue ( $hasAccount = $db->getValue (
'SELECT COUNT(*) > 0 'SELECT COUNT(*) > 0
FROM account.user u FROM account.user u
@ -22,41 +15,49 @@ class Account
if (!$hasAccount) if (!$hasAccount)
return; return;
$sambaSsh = new SshConnection ($conf['sambaHost'] $conf = $db->getRow (
'SELECT sambaHost, homesHost, sshUser, sshPass
FROM account.accountConfig'
);
$sshPass = base64_decode ($conf['sshPass']);
$samba = new SshConnection ($conf['sambaHost']
,$conf['sshUser']
,$sshPass
);
$homes = new SshConnection ($conf['homesHost']
,$conf['sshUser'] ,$conf['sshUser']
,$sshPass ,$sshPass
); );
if ($sync & self::USER)
{
$userId = $db->getValue ('SELECT id FROM account.user WHERE name = #', [$user]);
$accConf = $db->getRow ('SELECT uidBase, domain FROM account.accountConfig');
$escUser = SshConnection::escape ($user); $escUser = SshConnection::escape ($user);
// Creates the Samba user and initializes it's home directory
$userId = $db->getValue (
'SELECT id FROM account.user WHERE name = #', [$user]);
$accConf = $db->getRow (
'SELECT uidBase, domain FROM account.accountConfig');
$escUid = SshConnection::escape ($accConf['uidBase'] + $userId); $escUid = SshConnection::escape ($accConf['uidBase'] + $userId);
$escMail = SshConnection::escape ("$user@{$accConf['domain']}"); $escMail = SshConnection::escape ("$user@{$accConf['domain']}");
$sambaSsh->exec ( $samba->exec (
"/mnt/cluster/scripts/create-user.sh $escUser $escUid $escMail"); "/mnt/cluster/scripts/create-user.sh $escUser $escUid $escMail");
$homes->exec (
$homesSsh = new SshConnection ($conf['homesHost']
,$conf['sshUser']
,$sshPass
);
$homesSsh->exec (
"/mnt/storage/scripts/create-user.sh $escUser"); "/mnt/storage/scripts/create-user.sh $escUser");
}
if ($sync & self::PASS && !empty ($password)) // Syncronizes the Samba password
{
$escUser = SshConnection::escape ($user); if (empty ($password))
return;
$escPassword = SshConnection::escape ($password); $escPassword = SshConnection::escape ($password);
$sambaSsh->exec ( $samba->exec (
"/mnt/cluster/scripts/set-password.sh $escUser $escPassword"); "/mnt/cluster/scripts/set-password.sh $escUser $escPassword");
new SshConnection ($conf['homesHost'], $user, $password); new SshConnection ($conf['homesHost'], $user, $password);
} }
}
} }
class SshConnection class SshConnection
@ -97,4 +98,3 @@ class SshConnection
return '"'. str_replace ('"', '\\"', $str) .'"'; return '"'. str_replace ('"', '\\"', $str) .'"';
} }
} }

View File

@ -16,7 +16,7 @@ class ChangePassword extends Vn\Web\JsonRequest
$db->query ('CALL account.userChangePassword (#, #)', $db->query ('CALL account.userChangePassword (#, #)',
[$oldPassword, $newPassword]); [$oldPassword, $newPassword]);
Account::sync ($db, $_SESSION['user'], $newPassword, Account::PASS | Account::USER); Account::sync ($db, $_SESSION['user'], $newPassword);
return TRUE; return TRUE;
} }
} }

7
rest/core/locale/es.json Executable file
View File

@ -0,0 +1,7 @@
{
"InvalidAction": "Acción inválida"
,"EmptyQuery": "Consulta vacía"
,"Invalid password": "Contraseña inválida"
,"Password does not meet requirements":
"La nueva contraseña no reune los requisitos de seguridad necesarios"
}

View File

@ -53,34 +53,16 @@ class Query extends Vn\Web\JsonRequest
} }
catch (Vn\Db\Exception $e) catch (Vn\Db\Exception $e)
{ {
$row = NULL; if ($e->getCode () == 1644)
$code = $e->getCode (); {
$message = $e->getMessage (); $dbMessage = $e->getMessage ();
$sql = 'SELECT description FROM sql_message WHERE code = #';
$message = $db->getValue ($sql, [$dbMessage]);
switch ($code) if ($message)
{ throw new Lib\UserException ($message, $dbMessage);
case 1644: // ER_SIGNAL_EXCEPTION
{
$sql = 'SELECT description, #code code
FROM sql_message WHERE code = #code';
$row = $db->getRow ($sql, ['code' => $message]);
break;
}
case 1305: // ER_SP_DOES_NOT_EXIST
{
if (strpos ($message, 'EXCEPTION') === FALSE)
break;
$sql = 'SELECT description, @err code
FROM sql_message WHERE code = @err';
$row = $db->getRow ($sql);
break;
}
} }
if ($row)
throw new Lib\UserException ($row['description'], $row['code']);
else
throw $e; throw $e;
} }

View File

@ -19,7 +19,7 @@ class SetPassword extends Vn\Web\JsonRequest
$db->query ('CALL account.userSetPassword (#, #)', $db->query ('CALL account.userSetPassword (#, #)',
[$setUser, $setPassword]); [$setUser, $setPassword]);
Account::sync ($db, $setUser, $setPassword, Account::PASS); Account::sync ($db, $setUser, $setPassword);
return TRUE; return TRUE;
} }
} }

View File

@ -12,7 +12,7 @@ class SyncUser extends Vn\Web\JsonRequest
function run ($db) function run ($db)
{ {
Account::sync ($db, $_REQUEST['syncUser'], NULL, Account::USER); Account::sync ($db, $_REQUEST['syncUser'], NULL);
return TRUE; return TRUE;
} }
} }

View File

@ -84,7 +84,7 @@ class Load extends Edi\Method
$ediMessage->parse ($ediString, $this->ediSchema); $ediMessage->parse ($ediString, $this->ediSchema);
$db->query ('START TRANSACTION'); $db->query ('START TRANSACTION');
$db->query ('CALL message_new (#mailId, #sender, @message)', $db->query ('CALL messageNew (#mailId, #sender, @message)',
[ [
'mailId' => $mailId, 'mailId' => $mailId,
'sender' => $sender 'sender' => $sender

View File

@ -1,6 +1,5 @@
CALL batch_new ( CALL batchNew (
@message, #bgm, #aaj, #fec, #hor, #ref, #agj, #cat, #pac, @message, #art, #bgm, #aaj, #fec, #hor, #ref, #agj, #cat, #pac,
#sub, #kop, #ptd, #pro, #ori, #ptj, #qty, #pri, #klo, #s1, #s2, #s3, #sub, #kop, #ptd, #pro, #ori, #ptj, #qty, #pri, #klo, #s1, #s2, #s3,
#s4, #s5, #s6, #k1, #k2, #p1, #p2, #auction, #package #s4, #s5, #s6, #k1, #k2, #p1, #p2, #auction, #package
) )

View File

@ -50,9 +50,17 @@ class RestService extends Service
if ($method::PARAMS !== NULL && !$method->checkParams ($_REQUEST, $method::PARAMS)) if ($method::PARAMS !== NULL && !$method->checkParams ($_REQUEST, $method::PARAMS))
throw new UserException (s('Missing parameters')); throw new UserException (s('Missing parameters'));
Locale::addPath ("rest/{$_REQUEST['method']}"); Locale::addPath ('rest/'. dirname ($_REQUEST['method']));
try {
$res = $method->run ($methodDb); $res = $method->run ($methodDb);
}
catch (Db\Exception $e)
{
if ($e->getCode () == 1644)
throw new UserException (s($e->getMessage ()));
}
$db->query ('CALL account.userLogout ()'); $db->query ('CALL account.userLogout ()');
return $res; return $res;

View File

@ -2,6 +2,7 @@
namespace Vn\Web; namespace Vn\Web;
use Vn\Db;
use Vn\Lib\Locale; use Vn\Lib\Locale;
use Vn\Lib\UserException; use Vn\Lib\UserException;
@ -148,7 +149,7 @@ abstract class Service
$db->query ('CALL account.userLogin (#, #)', $db->query ('CALL account.userLogin (#, #)',
[$user, $_POST['password']]); [$user, $_POST['password']]);
} }
catch (\Vn\Db\Exception $e) catch (Db\Exception $e)
{ {
if ($e->getMessage () == 'INVALID_CREDENTIALS') if ($e->getMessage () == 'INVALID_CREDENTIALS')
{ {