aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2022-01-06 21:09:18 +0000
committerMario <mario@mariovavti.com>2022-01-06 21:09:18 +0000
commitf1c0034a18482ff85a1979fce94f3abd8622af0b (patch)
tree6a44d912c4d62ad2908591187bbec5ec4e63623e
parent7342cb81a3cffc1cd8ae3e32c2035e5c07376b53 (diff)
downloadvolse-hubzilla-f1c0034a18482ff85a1979fce94f3abd8622af0b.tar.gz
volse-hubzilla-f1c0034a18482ff85a1979fce94f3abd8622af0b.tar.bz2
volse-hubzilla-f1c0034a18482ff85a1979fce94f3abd8622af0b.zip
more work on access tokens
-rw-r--r--Zotlabs/Module/Tokens.php88
-rw-r--r--include/security.php4
-rw-r--r--view/pdl/mod_tokens.pdl7
-rw-r--r--view/tpl/tokens.tpl21
-rw-r--r--view/tpl/widget_menu.tpl10
5 files changed, 73 insertions, 57 deletions
diff --git a/Zotlabs/Module/Tokens.php b/Zotlabs/Module/Tokens.php
index 672bd619e..eedbfcf30 100644
--- a/Zotlabs/Module/Tokens.php
+++ b/Zotlabs/Module/Tokens.php
@@ -24,6 +24,51 @@ class Tokens extends Controller {
return;
check_form_security_token_redirectOnErr('tokens', 'tokens');
+
+ if(isset($_POST['delete'])) {
+ $r = q("select * from atoken where atoken_id = %d and atoken_uid = %d",
+ intval($_POST['atoken_id']),
+ intval(local_channel())
+ );
+
+ if (!$r) {
+ return;
+ }
+
+ $atoken = $r[0];
+ $atoken_xchan = substr($channel['channel_hash'], 0, 16) . '.' . $atoken['atoken_guid'];
+
+ $atoken['deleted'] = true;
+
+ $r = q("SELECT abook.*, xchan.*
+ FROM abook left join xchan on abook_xchan = xchan_hash
+ WHERE abook_channel = %d and abook_xchan = '%s' LIMIT 1",
+ intval($channel['channel_id']),
+ dbesc($atoken_xchan)
+ );
+
+ if (!$r) {
+ return;
+ }
+
+ $clone = $r[0];
+
+ unset($clone['abook_id']);
+ unset($clone['abook_account']);
+ unset($clone['abook_channel']);
+ $clone['deleted'] = true;
+
+ $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
+ if ($abconfig) {
+ $clone['abconfig'] = $abconfig;
+ }
+
+ atoken_delete($atoken['atoken_id']);
+ Libsync::build_sync_packet($channel['channel_id'], [ 'abook' => [ $clone ], 'atoken' => [ $atoken ] ], true);
+
+ return;
+ }
+
$token_errs = 0;
if(array_key_exists('token',$_POST)) {
$atoken_id = (($_POST['atoken_id']) ? intval($_POST['atoken_id']) : 0);
@@ -209,48 +254,10 @@ class Tokens extends Controller {
$atoken_abook = $atoken_abook[0];
}
-
- if($atoken && argc() > 2 && argv(2) === 'drop') {
- $atoken['deleted'] = true;
-
- $r = q("SELECT abook.*, xchan.*
- FROM abook left join xchan on abook_xchan = xchan_hash
- WHERE abook_channel = %d and abook_xchan = '%s' LIMIT 1",
- intval($channel['chnnel_id']),
- dbesc($atoken_xchan)
- );
- if (! $r) {
- return;
- }
-
- $clone = $r[0];
-
- unset($clone['abook_id']);
- unset($clone['abook_account']);
- unset($clone['abook_channel']);
- $clone['deleted'] = true;
-
- $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
- if ($abconfig) {
- $clone['abconfig'] = $abconfig;
- }
-
- atoken_delete($id);
- Libsync::build_sync_packet($channel['channel_id'], [ 'abook' => [ $clone ], 'atoken' => [ $atoken ] ], true);
-
- $atoken = null;
- $atoken_xchan = '';
- $atoken_abook = null;
- }
}
- $t = q("select * from atoken where atoken_uid = %d",
- intval(local_channel())
- );
-
$desc = t('Use this form to create temporary access identifiers to share things with non-members. These identities may be used in Access Control Lists and visitors may login using these credentials to access private content.');
- //TODO: assign role
$pcat = new Permcat(local_channel());
$pcatlist = $pcat->listing();
$default_role = get_pconfig(local_channel(), 'system', 'default_permcat');
@@ -261,7 +268,6 @@ class Tokens extends Controller {
$roles_dict[$role['name']] = $role['localname'];
}
-
if (!$current_permcat) {
notice(t('Please select a role for this guest!') . EOL);
$permcats[] = '';
@@ -279,12 +285,12 @@ class Tokens extends Controller {
'$permcat' => ['permcat', t('Select a role for this guest'), $current_permcat, '', $permcats],
'$title' => t('Guest Access'),
'$desc' => $desc,
- '$tokens' => $t,
'$atoken' => $atoken,
'$name' => array('name', t('Login Name') . ' <span class="required">*</span>', (($atoken) ? $atoken['atoken_name'] : ''),''),
'$token'=> array('token', t('Login Password') . ' <span class="required">*</span>',(($atoken) ? $atoken['atoken_token'] : new_token()), ''),
'$expires'=> array('expires', t('Expires (yyyy-mm-dd)'), (($atoken['atoken_expires'] && $atoken['atoken_expires'] > NULL_DATE) ? datetime_convert('UTC',date_default_timezone_get(),$atoken['atoken_expires']) : ''), ''),
- '$submit' => t('Submit')
+ '$submit' => t('Submit'),
+ '$delete' => t('Delete')
));
return $o;
}
diff --git a/include/security.php b/include/security.php
index 7f5f3193f..881adb818 100644
--- a/include/security.php
+++ b/include/security.php
@@ -170,6 +170,10 @@ function atoken_delete($atoken_id) {
intval($c[0]['channel_id']),
dbesc($atoken_xchan)
);
+
+ q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'",
+ dbesc($atoken_xchan)
+ );
}
/**
diff --git a/view/pdl/mod_tokens.pdl b/view/pdl/mod_tokens.pdl
new file mode 100644
index 000000000..97bdc3ab4
--- /dev/null
+++ b/view/pdl/mod_tokens.pdl
@@ -0,0 +1,7 @@
+[region=aside]
+[widget=tokens][/widget]
+[/region]
+[region=right_aside]
+[widget=notifications][/widget]
+[widget=newmember][/widget]
+[/region]
diff --git a/view/tpl/tokens.tpl b/view/tpl/tokens.tpl
index 443fb5392..835c1a6db 100644
--- a/view/tpl/tokens.tpl
+++ b/view/tpl/tokens.tpl
@@ -16,22 +16,11 @@
{{include file="field_input.tpl" field=$expires}}
{{include file="field_select.tpl" field=$permcat}}
- <div class="settings-submit-wrapper mb-3">
- <button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
+ <div class="mb-2 clearfix">
+ {{if $atoken}}
+ <button type="submit" name="delete" class="btn btn-outline-danger">{{$delete}}</button>
+ {{/if}}
+ <button type="submit" name="submit" class="btn btn-primary float-end">{{$submit}}</button>
</div>
</div>
-
- {{if $tokens}}
- <div class="section-content-wrapper-np">
- <table id="atoken-index">
- {{foreach $tokens as $t}}
- <tr id="atoken-index-{{$t.atoken_id}}" class="atoken-index-row">
- <td width="99%"><a href="tokens/{{$t.atoken_id}}">{{$t.atoken_name}}</a></td>
- <td width="1%" class="atoken-index-tool"><i class="fa fa-trash-o drop-icons" onClick="dropItem('tokens/{{$t.atoken_id}}/drop', '#atoken-index-{{$t.atoken_id}}')"></i></td>
- </tr>
- {{/foreach}}
- </table>
-
- </div>
- {{/if}}
</div>
diff --git a/view/tpl/widget_menu.tpl b/view/tpl/widget_menu.tpl
new file mode 100644
index 000000000..86799ff00
--- /dev/null
+++ b/view/tpl/widget_menu.tpl
@@ -0,0 +1,10 @@
+<div class="widget">
+ <h3>{{$title}}</h3>
+ <ul class="nav nav-pills flex-column">
+ {{foreach $menu_items as $menu_item}}
+ <li class="nav-item">
+ <a class="nav-link{{if $menu_item.active}} active{{/if}}" href="{{$menu_item.href}}" title="{{$menu_item.title}}">{{$menu_item.label}}</a>
+ <li>
+ {{/foreach}}
+ </ul>
+</div>