]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/openidsettings.php
Fix for bug #00019 (Linkified all @ addresses in a message)
[quix0rs-gnu-social.git] / actions / openidsettings.php
index 0355534d79631167cc1240f932536656bf0df465..a915542a6fcc0956699c52b6089395ee098a420c 100644 (file)
@@ -23,19 +23,28 @@ require_once(INSTALLDIR.'/lib/settingsaction.php');
 require_once(INSTALLDIR.'/lib/openid.php');
 
 class OpenidsettingsAction extends SettingsAction {
-
-       function show_form($msg=NULL, $success=false) {
+       
+       function show_top($arr) {
+               $msg = $arr[0];
+               $success = $arr[1];
                
-               $user = common_current_user();
-               
-               common_show_header(_t('OpenID settings'), NULL, NULL, array($this, 'settings_menu'));
-
                if ($msg) {
                        $this->message($msg, $success);
                } else {
                        common_element('div', 'instructions',
                                                   _t('Manage your associated OpenIDs from here.'));
                }
+               
+               $this->settings_menu();
+       }
+       
+       function show_form($msg=NULL, $success=false) {
+               
+               $user = common_current_user();
+               
+               common_show_header(_t('OpenID settings'), NULL, array($msg, $success),
+                                                  array($this, 'show_top'));
+               
                common_element_start('form', array('method' => 'POST',
                                                                                   'id' => 'openidadd',
                                                                                   'action' =>
@@ -53,46 +62,67 @@ class OpenidsettingsAction extends SettingsAction {
                common_element('input', array('type' => 'submit',
                                                                          'id' => 'add',
                                                                          'name' => 'add',
+                                                                         'class' => 'submit',
                                                                          'value' => _t('Add')));
                common_element_end('p');
                common_element_end('form');
-
+               
                $oid = new User_openid();
                $oid->user_id = $user->id;
                
-               if ($oid->find()) {
+               $cnt = $oid->find();
+               
+               if ($cnt > 0) {
                        
-                       common_element('h2', NULL, _t('OpenID'));
-                       common_element('p', NULL,
-                                                  _t('You can remove an OpenID from your account ',
-                                                         'by clicking the button marked "Delete" next to it.'));
-                       $idx = 0;
+                       common_element('h2', NULL, _t('Remove OpenID'));
                        
-                       while ($oid->fetch()) {
-                               common_element_start('form', array('method' => 'POST',
-                                                                                                  'id' => 'openiddelete' . $idx,
-                                                                                                  'action' =>
-                                                                                                  common_local_url('openidsettings')));
-                               common_element_start('p');
-                               common_element('a', array('href' => $oid->canonical),
-                                                          $oid->display);
-                               common_element('input', array('type' => 'hidden',
-                                                                                         'id' => 'openid_url'.$idx,
-                                                                                         'name' => 'openid_url',
-                                                                                         'value' => $oid->canonical));
-                               common_element('input', array('type' => 'submit',
-                                                                                         'id' => 'remove'.$idx,
-                                                                                         'name' => 'remove',
-                                                                                         'value' => _t('Add')));
-                               common_element_end('p');
-                               common_element_end('form');
-                               $idx++;
+                       if ($cnt == 1 && !$user->password) {
+                               
+                               common_element('p', NULL,
+                                                          _t('Removing your only OpenID would make it impossible to log in! ' .
+                                                                 'If you need to remove it, add another OpenID first.'));
+                               
+                               if ($oid->fetch()) {
+                                       common_element_start('p');
+                                       common_element('a', array('href' => $oid->canonical),
+                                                                  $oid->display);
+                                       common_element_end('p');
+                               }
+                               
+                       } else {
+                               
+                               common_element('p', NULL,
+                                                          _t('You can remove an OpenID from your account '.
+                                                                 'by clicking the button marked "Remove".'));
+                               $idx = 0;
+                               
+                               while ($oid->fetch()) {
+                                       common_element_start('form', array('method' => 'POST',
+                                                                                                          'id' => 'openiddelete' . $idx,
+                                                                                                          'action' =>
+                                                                                                          common_local_url('openidsettings')));
+                                       common_element_start('p');
+                                       common_element('a', array('href' => $oid->canonical),
+                                                                  $oid->display);
+                                       common_element('input', array('type' => 'hidden',
+                                                                                                 'id' => 'openid_url'.$idx,
+                                                                                                 'name' => 'openid_url',
+                                                                                                 'value' => $oid->canonical));
+                                       common_element('input', array('type' => 'submit',
+                                                                                                 'id' => 'remove'.$idx,
+                                                                                                 'name' => 'remove',
+                                                                                                 'class' => 'submit',
+                                                                                                 'value' => _t('Remove')));
+                                       common_element_end('p');
+                                       common_element_end('form');
+                                       $idx++;
+                               }
                        }
                }
                
                common_show_footer();
        }
-
+       
        function handle_post() {
                if ($this->arg('add')) {
                        $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
@@ -105,7 +135,7 @@ class OpenidsettingsAction extends SettingsAction {
                        $this->show_form(_t('Something weird happened.'));
                }
        }
-
+       
        function remove_openid() {
                
                $openid_url = $this->trimmed('openid_url');
@@ -120,7 +150,7 @@ class OpenidsettingsAction extends SettingsAction {
                        return;
                }
                $oid->delete();
-               $this->show_form(_t('OpenID removed.', true));
+               $this->show_form(_t('OpenID removed.'), true);
                return;
        }
 }
\ No newline at end of file