fipamo/brain/data/Member.inc.php

55 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php
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;
}
}
2021-05-06 21:45:39 +02:00
public static function updateData(string $key, string $data, $secret = null)
{
$folks = (new Settings())->getFolks();
2021-05-06 21:45:39 +02:00
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
2021-05-06 21:45:39 +02:00
if (!isset($secret)) {
$member = [
"handle" => $found["handle"],
"email" => $found["email"],
"role" => $found["role"],
"avatar" => $found["avi"],
];
Session::set("member", $member);
}
}
}