Use "update_operator" func for operator modification everywhere

This commit is contained in:
Dmitriy Simushev 2014-10-28 12:26:14 +00:00
parent 1d9a837e37
commit 65d7cb3823
2 changed files with 25 additions and 50 deletions

View File

@ -19,7 +19,6 @@
namespace Mibew\Controller; namespace Mibew\Controller;
use Mibew\Database;
use Mibew\Http\Exception\BadRequestException; use Mibew\Http\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -72,17 +71,10 @@ class PasswordRecoveryController extends AbstractController
? openssl_random_pseudo_bytes(32) ? openssl_random_pseudo_bytes(32)
: (time() + microtime()) . mt_rand(0, 99999999))); : (time() + microtime()) . mt_rand(0, 99999999)));
$db = Database::getInstance(); // Update the operator
$db->query( $to_restore['dtmrestore'] = time();
("UPDATE {operator} " $to_restore['vcrestoretoken'] = $token;
. "SET dtmrestore = :now, vcrestoretoken = :token " update_operator($to_restore);
. "WHERE operatorid = :operatorid"),
array(
':now' => time(),
':token' => $token,
':operatorid' => $to_restore['operatorid'],
)
);
$href = $this->getRouter()->generate( $href = $this->getRouter()->generate(
'password_recovery_reset', 'password_recovery_reset',
@ -178,16 +170,11 @@ class PasswordRecoveryController extends AbstractController
if (count($page['errors']) == 0) { if (count($page['errors']) == 0) {
$page['isdone'] = true; $page['isdone'] = true;
$db = Database::getInstance(); // Update the operator
$db->query( $operator['vcrestoretoken'] = '';
("UPDATE {operator} " $operator['vcpassword'] = calculate_password_hash($operator['vclogin'], $password);
. "SET vcpassword = ?, vcrestoretoken = '' " update_operator($operator);
. "WHERE operatorid = ?"),
array(
calculate_password_hash($operator['vclogin'], $password),
$op_id,
)
);
$page['loginname'] = $operator['vclogin']; $page['loginname'] = $operator['vclogin'];
return $this->render('password_recovery_reset', $page); return $this->render('password_recovery_reset', $page);

View File

@ -93,11 +93,9 @@ function permission_descriptions()
*/ */
function update_operator_permissions($operator_id, $perm) function update_operator_permissions($operator_id, $perm)
{ {
$db = Database::getInstance(); $operator = operator_by_id($operator_id);
$db->query( $operator['iperm'] = $perm;
"UPDATE {operator} SET iperm = ? WHERE operatorid = ?", update_operator($operator);
array($perm, $operator_id)
);
} }
function operator_by_login($login) function operator_by_login($login)
@ -331,11 +329,9 @@ function update_operator($operator)
function update_operator_avatar($operator_id, $avatar) function update_operator_avatar($operator_id, $avatar)
{ {
$db = Database::getInstance(); $operator = operator_by_id($operator_id);
$db->query( $operator['vcavatar'] = $avatar;
"UPDATE {operator} SET vcavatar = ? WHERE operatorid = ?", update_operator($operator);
array($avatar, $operator_id)
);
} }
/** /**
@ -431,16 +427,10 @@ function delete_operator($operator_id)
*/ */
function notify_operator_alive($operator_id, $istatus) function notify_operator_alive($operator_id, $istatus)
{ {
$db = Database::getInstance(); $operator = operator_by_id($operator_id);
$db->query( $operator['istatus'] = $istatus;
("UPDATE {operator} SET istatus = :istatus, dtmlastvisited = :now " $operator['dtmlastvisited'] = time();
. "WHERE operatorid = :operatorid"), update_operator($operator);
array(
':istatus' => $istatus,
':now' => time(),
':operatorid' => $operator_id,
)
);
} }
/** /**
@ -784,10 +774,9 @@ function update_operator_groups($operator_id, $new_value)
*/ */
function disable_operator($operator_id) function disable_operator($operator_id)
{ {
Database::getInstance()->query( $operator = operator_by_id($operator_id);
'UPDATE {operator} SET idisabled = ? WHERE operatorid = ?', $operator['idisabled'] = 1;
array('1', $operator_id) update_operator($operator);
);
} }
/** /**
@ -797,10 +786,9 @@ function disable_operator($operator_id)
*/ */
function enable_operator($operator_id) function enable_operator($operator_id)
{ {
Database::getInstance()->query( $operator = operator_by_id($operator_id);
'UPDATE {operator} SET idisabled = ? WHERE operatorid = ?', $operator['idisabled'] = 0;
array('0', $operator_id) update_operator($operator);
);
} }
/** /**