2022-03-19 00:00:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace brain\data;
|
|
|
|
|
|
|
|
use brain\utility\DocTools;
|
2022-05-17 04:14:38 +02:00
|
|
|
|
2022-03-19 00:00:51 +01:00
|
|
|
use function _\find;
|
|
|
|
|
|
|
|
class Member
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
2022-05-17 04:14:38 +02:00
|
|
|
|
2022-03-19 00:00:51 +01:00
|
|
|
public static function verifyKey(string $key)
|
|
|
|
{
|
|
|
|
if (isset($key)) {
|
|
|
|
$folks = (new Settings())->getFolks();
|
2022-05-17 02:41:15 +02:00
|
|
|
$found = find($folks, ['key' => $key]);
|
2022-03-19 00:00:51 +01:00
|
|
|
if ($found) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-05-17 04:14:38 +02:00
|
|
|
|
2022-03-19 00:00:51 +01:00
|
|
|
public static function updateData(string $key, string $data, $secret = null)
|
|
|
|
{
|
|
|
|
$folks = (new Settings())->getFolks();
|
|
|
|
if (isset($secret)) {
|
2022-05-17 02:41:15 +02:00
|
|
|
$found = find($folks, ['secret' => $secret]);
|
2022-03-19 00:00:51 +01:00
|
|
|
} else {
|
2022-05-17 02:41:15 +02:00
|
|
|
$member = Session::get('member');
|
|
|
|
$found = find($folks, ['handle' => $member['handle']]);
|
2022-03-19 00:00:51 +01:00
|
|
|
}
|
|
|
|
$found[$key] = $data;
|
|
|
|
//record time updated
|
2022-05-17 02:41:15 +02:00
|
|
|
$updated = new \Moment\Moment();
|
|
|
|
$found['updated'] = $updated->format("Y-m-d\TH:i:sP");
|
|
|
|
$newFolks = [];
|
2022-03-19 00:00:51 +01:00
|
|
|
array_push($newFolks, $found);
|
|
|
|
//save updated file
|
2022-05-17 02:41:15 +02:00
|
|
|
DocTools::writeSettings('../config/folks.json', $newFolks);
|
2022-03-19 00:00:51 +01:00
|
|
|
//update member data in session
|
|
|
|
|
|
|
|
if (!isset($secret)) {
|
|
|
|
$member = [
|
2022-05-17 02:41:15 +02:00
|
|
|
'handle' => $found['handle'],
|
|
|
|
'email' => $found['email'],
|
|
|
|
'role' => $found['role'],
|
|
|
|
'avatar' => $found['avi'],
|
|
|
|
'key' => $found['key'],
|
2022-03-19 00:00:51 +01:00
|
|
|
];
|
2022-05-17 02:41:15 +02:00
|
|
|
Session::set('member', $member);
|
2022-03-19 00:00:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|