diff options
author | redmatrix <git@macgirvin.com> | 2016-07-14 22:41:53 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-07-14 22:41:53 -0700 |
commit | 7ee7f00bf34b11d0427f03df9494088cf56ef9ee (patch) | |
tree | eea7b4b07c143848e83bca6c1ef6e5ee5d483031 | |
parent | 397a23499dc64e2abdd2c27ccdf7e059a23dcfff (diff) | |
download | volse-hubzilla-7ee7f00bf34b11d0427f03df9494088cf56ef9ee.tar.gz volse-hubzilla-7ee7f00bf34b11d0427f03df9494088cf56ef9ee.tar.bz2 volse-hubzilla-7ee7f00bf34b11d0427f03df9494088cf56ef9ee.zip |
Here's the basic UI for the Zot Access Tokens, requires some minor cleanup
-rw-r--r-- | Zotlabs/Module/Settings.php | 78 | ||||
-rw-r--r-- | include/widgets.php | 9 | ||||
-rw-r--r-- | view/tpl/settings_tokens.tpl | 28 |
3 files changed, 114 insertions, 1 deletions
diff --git a/Zotlabs/Module/Settings.php b/Zotlabs/Module/Settings.php index af246a4dc..60c9be519 100644 --- a/Zotlabs/Module/Settings.php +++ b/Zotlabs/Module/Settings.php @@ -28,7 +28,7 @@ class Settings extends \Zotlabs\Web\Controller { } - function post() { + function post() { if(! local_channel()) return; @@ -117,6 +117,43 @@ class Settings extends \Zotlabs\Web\Controller { build_sync_packet(); return; } + + + if((argc() > 1) && (argv(1) == 'tokens')) { + check_form_security_token_redirectOnErr('/settings/tokens', 'settings_tokens'); + + $atoken_id = (($_POST['atoken_id']) ? intval($_POST['atoken_id']) : 0); + $name = trim(escape_tags($_POST['name'])); + $token = trim($_POST['token']); + if(trim($_POST['expires'])) + $expires = datetime_convert(date_default_timezone_get(),'UTC',$_POST['expires']); + else + $expires = NULL_DATE; + + if($atoken_id) { + $r = q("update atoken set atoken_name = '%s', atoken_token = '%s' atoken_expire = '%s' + where atoken_id = %d and atoken_uid = %d", + dbesc($name), + dbesc($token), + dbesc($expires), + intval($atoken_id), + intval($channel['channel_id']) + ); + } + else { + $r = q("insert into atoken ( atoken_aid, atoken_uid, atoken_name, atoken_token, atoken_expire ) + values ( %d, %d, '%s', '%s', '%s' ) ", + intval($channel['channel_account_id']), + intval($channel['channel_id']), + dbesc($name), + dbesc($token), + dbesc($expires) + ); + } + + info( t('Token saved.') . EOL); + return; + } @@ -706,6 +743,45 @@ class Settings extends \Zotlabs\Web\Controller { )); return $o; } + + if((argc() > 1) && (argv(1) === 'tokens')) { + $atoken = null; + if(argc() > 2) { + $id = argv(2); + + $atoken = q("select * from atoken where atoken_id = %d and atoken_uid = %d", + intval($id), + intval(local_channel()) + ); + + if($atoken) + $atoken = $atoken[0]; + + if($atoken && argc() > 3 && argv(3) === 'drop') { + $r = q("delete from atoken where atoken_id = %d", + intval($id) + ); + } + } + $t = q("select * from atoken where atoken_uid = %d", + intval(local_channel()) + ); + + $tpl = get_markup_template("settings_tokens.tpl"); + $o .= replace_macros($tpl, array( + '$form_security_token' => get_form_security_token("settings_tokens"), + '$title' => t('Guest Access Tokens'), + '$tokens' => $t, + '$atoken' => $atoken, + '$name' => array('name', t('Login Name'), (($atoken) ? $atoken['atoken_name'] : ''),''), + '$token'=> array('token', t('Login Password'),(($atoken) ? $atoken['atoken_token'] : autoname(8)), ''), + '$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') + )); + return $o; + } + + diff --git a/include/widgets.php b/include/widgets.php index 2d4d5b799..da73657f5 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -609,6 +609,15 @@ function widget_settings_menu($arr) { 'selected' => ((argv(1) === 'oauth') ? 'active' : ''), ); + if(! UNO) { + $tabs[] = array( + 'label' => t('Guest Access Tokens'), + 'url' => z_root() . '/settings/tokens', + 'selected' => ((argv(1) === 'tokens') ? 'active' : ''), + ); + } + + if($role === false || $role === 'custom') { $tabs[] = array( 'label' => t('Connection Default Permissions'), diff --git a/view/tpl/settings_tokens.tpl b/view/tpl/settings_tokens.tpl new file mode 100644 index 000000000..8763a681c --- /dev/null +++ b/view/tpl/settings_tokens.tpl @@ -0,0 +1,28 @@ +<div class="generic-content-wrapper"> + <div class="section-title-wrapper"> + <h2>{{$title}}</h2> + <div class="clear"></div> + </div> + <form action="settings/tokens" id="settings-account-form" method="post" autocomplete="off" > + <input type='hidden' name='form_security_token' value='{{$form_security_token}}'> + {{if $atoken}}<input type="hidden" name="atoken_id" value="{{$atoken.atoken_id}}" />{{/if}} + <div class="section-content-tools-wrapper"> + {{include file="field_input.tpl" field=$name}} + {{include file="field_input.tpl" field=$token}} + {{include file="field_input.tpl" field=$expires}} + <div class="settings-submit-wrapper" > + <button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button> + </div> + </div> + </form> + {{if $tokens}} + <div> + <ul> + {{foreach $tokens as $t}} + <li><a href="settings/tokens/{{$t.atoken_id}}">{{$t.atoken_name}}</a> <a href="settings/tokens/{{$t.atoken_id}}/drop"><i class="fa fa-remove btn btn-xs btn-default pull-right"></i></a></li> + {{/foreach}} + </ul> + </div> + {{/if}} + +</div> |