0
1
Fork 0
hedera-web-mindshore/rest/user/account.php

41 lines
865 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) {
2021-01-15 13:52:26 +00:00
$sync = $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
);
2021-01-15 13:52:26 +00:00
if ($sync)
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)
2020-10-23 11:00:40 +00:00
$db->query('DELETE FROM account.userSync WHERE name = #',
[$userName]
);
2016-10-27 11:22:04 +00:00
}
}