hedera-web/rest/core/account.php

43 lines
883 B
PHP
Raw Normal View History

2016-10-27 11:22:04 +00:00
<?php
2018-05-23 10:14:20 +00:00
class Account {
static function trySync($db, $userName, $password = NULL) {
$isSync = $db->getValue(
'SELECT COUNT(*) > 0 FROM account.userSync WHERE name = #',
2017-11-28 15:07:21 +00:00
[$userName]
2017-05-30 13:27:49 +00:00
);
if ($isSync)
return;
2018-05-23 10:14:20 +00:00
self::sync($db, $userName, $password);
2017-05-30 13:27:49 +00:00
}
static function sync($db, $userName, $password = NULL) {
2019-07-02 08:48:14 +00:00
$bcryptPassword = password_hash($password, PASSWORD_BCRYPT);
2019-06-04 12:14:48 +00:00
$userId = $db->getValue(
'SELECT id FROM account.user WHERE `name` = #',
2017-11-28 15:07:21 +00:00
[$userName]
2017-05-02 12:33:48 +00:00
);
2019-06-04 12:14:48 +00:00
$db->query(
2019-07-02 08:48:14 +00:00
'UPDATE account.user SET
bcryptPassword = #
WHERE id = #',
[$bcryptPassword, $userId]
2019-06-04 12:14:48 +00:00
);
2017-05-30 13:27:49 +00:00
$hasAccount = $db->getValue(
'SELECT COUNT(*) > 0
FROM account.user u
JOIN account.account a ON u.id = a.id
WHERE u.name = #',
[$userName]
2019-08-07 12:36:20 +00:00
);
if (!$hasAccount)
$db->getValue('DELETE FROM account.userSync WHERE name = #',
[$userName]
);
2016-10-27 11:22:04 +00:00
}
}