]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/showapplication.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / actions / showapplication.php
index 049206375d260ff09e49f1baacaf3d439b1e5154..10aaff538f3451e93d04600ef631ff911d6fd6cf 100644 (file)
@@ -149,7 +149,6 @@ class ShowApplicationAction extends OwnerDesignAction
 
     function showContent()
     {
-
         $cur = common_current_user();
 
         $consumer = $this->application->getConsumer();
@@ -201,7 +200,7 @@ class ShowApplicationAction extends OwnerDesignAction
         $userCnt = $appUsers->count();
 
         $this->raw(sprintf(
-            _('created by %1$s - %2$s access by default - %3$d users'),
+            _('Created by %1$s - %2$s access by default - %3$d users'),
               $profile->getBestName(),
               $defaultAccess,
               $userCnt
@@ -222,18 +221,39 @@ class ShowApplicationAction extends OwnerDesignAction
 
         $this->elementStart('li', 'entity_reset_keysecret');
         $this->elementStart('form', array(
-            'id' => 'forma_reset_key',
+            'id' => 'form_reset_key',
             'class' => 'form_reset_key',
             'method' => 'POST',
             'action' => common_local_url('showapplication',
                                          array('id' => $this->application->id))));
+        $this->elementStart('fieldset');
+        $this->hidden('token', common_session_token());
+
+        $this->element('input', array('type' => 'submit',
+                                      'id' => 'reset',
+                                      'name' => 'reset',
+                                      'class' => 'submit',
+                                      'value' => _('Reset key & secret'),
+                                      'onClick' => 'return confirmReset()'));
+        $this->elementEnd('fieldset');
+        $this->elementEnd('form');
+        $this->elementEnd('li');
+
+        $this->elementStart('li', 'entity_delete');
+        $this->elementStart('form', array(
+                                          'id' => 'form_delete_application',
+                                          'class' => 'form_delete_application',
+                                          'method' => 'POST',
+                                          'action' => common_local_url('deleteapplication',
+                                                                       array('id' => $this->application->id))));
 
         $this->elementStart('fieldset');
         $this->hidden('token', common_session_token());
-        $this->submit('reset', _('Reset key & secret'));
+        $this->submit('delete', _('Delete'));
         $this->elementEnd('fieldset');
         $this->elementEnd('form');
         $this->elementEnd('li');
+
         $this->elementEnd('ul');
         $this->elementEnd('div');
 
@@ -251,21 +271,21 @@ class ShowApplicationAction extends OwnerDesignAction
 
         $this->elementStart('dl', 'entity_request_token_url');
         $this->element('dt', null, _('Request token URL'));
-        $this->element('dd', null, common_local_url('apioauthrequesttoken'));
+        $this->element('dd', null, common_local_url('ApiOauthRequestToken'));
         $this->elementEnd('dl');
 
         $this->elementStart('dl', 'entity_access_token_url');
         $this->element('dt', null, _('Access token URL'));
-        $this->element('dd', null, common_local_url('apioauthaccesstoken'));
+        $this->element('dd', null, common_local_url('ApiOauthAccessToken'));
         $this->elementEnd('dl');
 
         $this->elementStart('dl', 'entity_authorize_url');
         $this->element('dt', null, _('Authorize URL'));
-        $this->element('dd', null, common_local_url('apioauthauthorize'));
+        $this->element('dd', null, common_local_url('ApiOauthAuthorize'));
         $this->elementEnd('dl');
 
         $this->element('p', 'note',
-            _('Note: We support hmac-sha1 signatures. We do not support the plaintext signature method.'));
+            _('Note: We support HMAC-SHA1 signatures. We do not support the plaintext signature method.'));
         $this->elementEnd('div');
 
         $this->elementStart('p', array('id' => 'application_action'));
@@ -276,14 +296,53 @@ class ShowApplicationAction extends OwnerDesignAction
         $this->elementEnd('p');
     }
 
+    /**
+     * Add a confirm script for Consumer key/secret reset
+     *
+     * @return void
+     */
+
+    function showScripts()
+    {
+        parent::showScripts();
+
+        $msg = _('Are you sure you want to reset your consumer key and secret?');
+
+        $js  = 'function confirmReset() { ';
+        $js .= '    var agree = confirm("' . $msg . '"); ';
+        $js .= '    return agree;';
+        $js .= '}';
+
+        $this->inlineScript($js);
+    }
+
+    /**
+     * Reset an application's Consumer key and secret
+     *
+     * XXX: Should this be moved to its own page with a confirm?
+     *
+     */
+
     function resetKey()
     {
         $this->application->query('BEGIN');
 
+        $oauser = new Oauth_application_user();
+        $oauser->application_id = $this->application->id;
+        $result = $oauser->delete();
+
+        if ($result === false) {
+            common_log_db_error($oauser, 'DELETE', __FILE__);
+            $this->success = false;
+            $this->msg = ('Unable to reset consumer key and secret.');
+            $this->showPage();
+            return;
+        }
+
         $consumer = $this->application->getConsumer();
         $result = $consumer->delete();
 
-        if (!$result) {
+        if ($result === false) {
             common_log_db_error($consumer, 'DELETE', __FILE__);
             $this->success = false;
             $this->msg = ('Unable to reset consumer key and secret.');
@@ -295,7 +354,7 @@ class ShowApplicationAction extends OwnerDesignAction
 
         $result = $consumer->insert();
 
-        if (!$result) {
+        if (empty($result)) {
             common_log_db_error($consumer, 'INSERT', __FILE__);
             $this->application->query('ROLLBACK');
             $this->success = false;
@@ -308,7 +367,7 @@ class ShowApplicationAction extends OwnerDesignAction
         $this->application->consumer_key = $consumer->consumer_key;
         $result = $this->application->update($orig);
 
-        if (!$result) {
+        if ($result === false) {
             common_log_db_error($application, 'UPDATE', __FILE__);
             $this->application->query('ROLLBACK');
             $this->success = false;
@@ -325,4 +384,3 @@ class ShowApplicationAction extends OwnerDesignAction
     }
 
 }
-