identity manager

This commit is contained in:
Mike Macgirvin 2023-05-03 20:20:57 +10:00
parent 586ddf62bd
commit 0a08d42971
3 changed files with 36 additions and 30 deletions

View file

@ -20,19 +20,25 @@ class Identities extends Controller
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = (argc() > 2) ? intval(argv(2)) : null;
$id = (isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null);
}
else {
$id = ($_REQUEST['id'] ? intval($_REQUEST['id']) - 1 : null);
$id = (argc() > 2) ? intval(argv(2)) : null;
}
$identities = $this->getIdentities();
$delete = ($_REQUEST['drop'] ? boolval($_REQUEST['drop']) : false);
$edit = ($_REQUEST['edit'] ? boolval($_REQUEST['edit']) : false);
$description = (($_REQUEST['description']) ? escape_tags(trim($_REQUEST['description'])) : '' );
$url = (($_REQUEST['url']) ? escape_tags(trim($_REQUEST['url'])) : '' );
if (!$edit && !$delete && $_SERVER['REQUEST_METHOD'] !== 'POST') {
return;
}
if ($delete && isset($id)) {
unset($identities['id']);
unset($identities[$id]);
}
else {
if (isset($id) && $description && $url) {
@ -42,16 +48,18 @@ class Identities extends Controller
}
}
if ($identities) {
PConfig::Set(local_channel(), 'system', 'identities', $identities);
PConfig::Set(local_channel(), 'system', 'identities', array_values($identities));
}
else {
PConfig::Delete(local_channel(), 'system','identities');
}
$this->check_identities();
// build_sync_packet
if ($delete) {
goaway(z_root() . '/settings/identities');
}
else
{
$this->check_identity($url);
}
}
public function get()
@ -105,44 +113,39 @@ class Identities extends Controller
PConfig::Set(local_channel(),'system','identities', $identities);
}
protected function check_identities()
protected function check_identity($url)
{
$channel = App::get_channel();
$myUrl = z_root() . '/channel/' . $channel['channel_address'];
$myIdentity = $channel['channel_hash'];
$identities = $this->getIdentities();
$links = $this->loadIdentities($myIdentity);
foreach ($identities as $identity) {
$currentRecord = $this->matchRecord($identity[1], $links);
$currentRecord = $this->matchRecord($url, $links);
$validator = new Relme();
$isMe = $validator->RelmeValidate($identity[1], $myUrl);
$isMe = $validator->RelmeValidate($url, $myUrl);
if ($isMe) {
if ($currentRecord) {
q("update linkid set sigtype = %d where link_id = %d",
intval($isMe ? IDLINK_RELME : IDLINK_NONE),
intval(IDLINK_RELME),
intval($currentRecord['link_id'])
);
}
else {
q("insert into linkid (ident, link, ikey, lkey, isig, lsig, sigtype) values ( '%s', '%s', '', '', '', '', %d) ",
dbesc($myIdentity),
dbesc($identity[1]),
intval($isMe ? IDLINK_RELME : IDLINK_NONE)
dbesc($url),
intval(IDLINK_RELME)
);
}
$links = $this->loadIdentities($myIdentity);
}
foreach ($links as $link) {
if (! $this->matchLinks($link['link'], $identities)) {
q("delete from linkid where link_id = %d",
intval($link['link_id'])
else {
q("delete from linkid where ident = '%s' and link = '%s'",
dbesc($myIdentity),
dbesc($url)
);
}
}
q("delete from linkid where sigtype = %d",
intval(IDLINK_NONE)
);
return $isMe;
}
protected function loadIdentities($myIdentity)

View file

@ -2900,7 +2900,7 @@ function i_am_mentioned($channel,$item,$check_groups = false) {
*/
function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $group = false, $edit = false) {
btlogger('start_chain: ' . $channel['channel_id'] . ' item: ' . $item_id);
// btlogger('start_chain: ' . $channel['channel_id'] . ' item: ' . $item_id);
$moderated = perm_is_allowed($channel['channel_id'], $item['author_xchan'], 'moderated');
$source = check_item_source($channel['channel_id'],$item);

View file

@ -15,7 +15,7 @@
<div class="">
<div class="float-start" ><a href="{{$identity.1}}" >{{$identity.0}}</a> <i class="fa {{if $identity.2}}_green fa-check-square-o{{else}}_red fa-square-o{{/if}}"></i></div>
<div class="float-end" ><a href="settings/identities/{{$key}}?drop=1" class="btn btn-default btn-outline-secondary"><i class="fa fa-remove" title="{{$drop}}"></i></a></div>
<div class="float-end" ><a href="settings/identities/{{$key}}" class="btn btn-default btn-outline-secondary" style="margin-right:5px;"><i class="fa fa-pencil" title="{{$edit}}"></i></a></div>
<div class="float-end" ><a href="settings/identities/{{$key}}?edit=1" class="btn btn-default btn-outline-secondary" style="margin-right:5px;"><i class="fa fa-pencil" title="{{$edit}}"></i></a></div>
<div class="clear" ></div>
</div>
{{/foreach}}
@ -25,6 +25,9 @@
<form action="settings/identities" method="POST">
{{include file="field_input.tpl" field=$description}}
{{include file="field_input.tpl" field=$url}}
{{if isset($id) }}
<input type="hidden" name="id" value="{{$id}}">
{{/if}}
<div class="settings-submit-wrapper" >
<button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
</div>