cvs: php4 /pear/PEAR/Command Auth.php
| From: | Stig Bakken | Date: | Tue, 14 May 2002 01:49:56 +0000 |
| Subject: | cvs: php4 /pear/PEAR/Command Auth.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3817@lists.php.net to get a copy of this message | ||
ssb Mon May 13 21:49:56 2002 EDT
Modified files:
/php4/pear/PEAR/Command Auth.php
Log:
* add command definitions, split run() into one method for each command
Index: php4/pear/PEAR/Command/Auth.php
diff -u php4/pear/PEAR/Command/Auth.php:1.5 php4/pear/PEAR/Command/Auth.php:1.6
--- php4/pear/PEAR/Command/Auth.php:1.5 Wed May 8 22:31:36 2002
+++ php4/pear/PEAR/Command/Auth.php Mon May 13 21:49:56 2002
@@ -16,7 +16,7 @@
// | Author: Stig Bakken <ssb@fast.no> |
// +----------------------------------------------------------------------+
//
-// $Id: Auth.php,v 1.5 2002/05/09 02:31:36 ssb Exp $
+// $Id: Auth.php,v 1.6 2002/05/14 01:49:56 ssb Exp $
require_once "PEAR/Command/Common.php";
require_once "PEAR/Remote.php";
@@ -28,7 +28,34 @@
*/
class PEAR_Command_Auth extends PEAR_Command_Common
{
- // {{{ constructor
+ // {{{ command definitions
+
+ var $commands = array(
+ 'login' => array(
+ 'summary' => 'Connects and authenticates to remote server',
+ 'function' => 'doLogin',
+ 'options' => array(),
+ 'doc' => 'To use functions in the installer that require any kind
+of privilege, you need to log in first. The username and password you enter
+here will be stored in your per-user PEAR configuration (~/.pearrc on
+Unix-like systems). After logging in, your username and password will be
+passed along in every subsequent operation on the remote server.
+',
+ ),
+ 'logout' => array(
+ 'summary' => 'Logs out from the remote server',
+ 'function' => 'doLogout',
+ 'options' => array(),
+ 'doc' => 'Logs out from the remote server.
+This command does not actually connect to the remote
+server, it only deletes the stored username and password from your
+user configuration.
+',
+ )
+
+ );
+
+ // }}}
/**
* PEAR_Command_Auth constructor.
@@ -40,94 +67,69 @@
parent::PEAR_Command_Common($ui, $config);
}
- // }}}
-
- // {{{ getCommands()
-
/**
- * Return a list of all the commands defined by this class.
- * @return array list of commands
+ * Execute the 'logout' command.
+ *
+ * @param string $command command name
+ *
+ * @param array $options option_name => value
+ *
+ * @param array $params list of additional parameters
+ *
+ * @return bool TRUE on success, FALSE for unknown commands, or
+ * a PEAR error on failure
+ *
* @access public
*/
- function getCommands()
+ function doLogin($command, $options, $params)
{
- return array('login' => 'Log In',
- 'logout' => 'Log Out');
- }
-
- // }}}
+ $server = $this->config->get('master_server');
+ $remote = new PEAR_Remote($this->config);
+ $username = $this->config->get('username');
+ if (empty($username)) {
+ $username = @$_ENV['USER'];
+ }
+ $this->ui->displayLine("Logging in to $server.");
+ $username = trim($this->ui->userDialog('Username', 'text',
$username));
- function getHelp($command)
- {
- switch ($command) {
- case 'login':
- return array(null, 'Connects to the remote server');
- case 'logout':
- return array(null, 'Disconnects from the remote server');
+ $this->config->set('username', $username);
+ $password = trim($this->ui->userDialog('Password', 'password'));
+ $this->config->set('password', $password);
+ $remote->expectError(401);
+ $ok = $remote->call('logintest');
+ $remote->popExpect();
+ if ($ok === true) {
+ $this->ui->displayLine("Logged in.");
+ $this->config->store();
+ } else {
+ $this->ui->displayLine("Login failed!");
}
+
}
- // {{{ run()
/**
- * Execute the command.
+ * Execute the 'logout' command.
*
- * @param string command name
+ * @param string $command command name
*
- * @param array option_name => value
+ * @param array $options option_name => value
*
- * @param array list of additional parameters
+ * @param array $params list of additional parameters
*
* @return bool TRUE on success, FALSE for unknown commands, or
* a PEAR error on failure
*
* @access public
*/
- function run($command, $options, $params)
+ function doLogout($command, $options, $params)
{
- $failmsg = '';
$server = $this->config->get('master_server');
- switch ($command) {
- case 'login': {
- $remote = new PEAR_Remote($this->config);
- $username = $this->config->get('username');
- if (empty($username)) {
- $username = @$_ENV['USER'];
- }
- $this->ui->displayLine("Logging in to $server.");
- $username = trim($this->ui->userDialog('Username',
'text', $username));
-
- $this->config->set('username', $username);
- $password = trim($this->ui->userDialog('Password',
'password'));
- $this->config->set('password', $password);
- $remote->expectError(401);
- $ok = $remote->call('logintest');
- $remote->popExpect();
- if ($ok === true) {
- $this->ui->displayLine("Logged in.");
- $this->config->store();
- } else {
- $this->ui->displayLine("Login failed!");
- }
- break;
- }
- case 'logout': {
- $this->ui->displayLine("Logging out from $server.");
- $this->config->remove('username');
- $this->config->remove('password');
- $this->config->store();
- break;
- }
- default: {
- return false;
- }
- }
- if ($failmsg) {
- return $this->raiseError($failmsg);
- }
- return true;
+ $this->ui->displayLine("Logging out from $server.");
+ $this->config->remove('username');
+ $this->config->remove('password');
+ $this->config->store();
}
- // }}}
}
?>