fipamo/brain/data/Member.php
Are0h 63eaba08e2 Added config for PHP formatting (PSR2)
I needed some consistent php formatting, so I plugged in a php fixer
config and then reformatted all PHP files so it's all consistent.

Fixed an ID issue with the page-edit template that was causing page
editing to fail.
2022-05-16 17:41:15 -07:00

58 lines
1.6 KiB
PHP

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