示例#1
0
 /**
  * Log in as a user
  *
  *  ## OPTIONS
  * [<email>]
  * : Email address to log in as.
  *
  * [--password=<value>]
  * : Log in non-interactively with this password. Useful for automation.
  * [--debug]
  * : dump call information when logging in.
  */
 public function login($args, $assoc_args)
 {
     if (empty($args)) {
         $email = Terminus::prompt("Your email address?", NULL);
     } else {
         $email = $args[0];
     }
     if (\Terminus\Utils\is_valid_email($email)) {
         if (!isset($assoc_args['password'])) {
             exec("stty -echo");
             $password = Terminus::prompt("Your dashboard password (input will not be shown)");
             exec("stty echo");
             Terminus::line();
         } else {
             $password = $assoc_args['password'];
         }
         Terminus::line("Logging in as {$email}");
         $data = $this->doLogin($email, $password);
         if ($data != FALSE) {
             if (array_key_exists("debug", $assoc_args)) {
                 $this->_debug(get_defined_vars());
             }
             Terminus::launch_self("art", array("fist"));
         } else {
             Terminus::error("Login Failed!");
         }
     } else {
         Terminus::error("Error: invalid email address");
     }
 }
示例#2
0
文件: auth.php 项目: blueprintmrk/cli
 /**
  * Log in as a user
  *
  *  ## OPTIONS
  * [<email>]
  * : Email address to log in as.
  *
  * [--password=<value>]
  * : Log in non-interactively with this password. Useful for automation.
  *
  * [--machine-token=<value>]
  * : Authenticate using an Auth0 token
  *
  * [--debug]
  * : dump call information when logging in.
  */
 public function login($args, $assoc_args)
 {
     // Try to login using a machine token, if provided.
     if (isset($assoc_args['machine-token']) || empty($args) && isset($_SERVER['TERMINUS_MACHINE_TOKEN'])) {
         $token = $_SERVER['TERMINUS_MACHINE_TOKEN'];
         if (isset($assoc_args['machine-token'])) {
             $token = $assoc_args['machine-token'];
         }
         $this->auth->logInViaMachineToken($token);
     } else {
         // Otherwise, do a normal email/password-based login.
         if (empty($args)) {
             if (isset($_SERVER['TERMINUS_USER'])) {
                 $email = $_SERVER['TERMINUS_USER'];
             } else {
                 $email = Terminus::prompt('Your email address?', null);
             }
         } else {
             $email = $args[0];
         }
         if (isset($assoc_args['password'])) {
             $password = $assoc_args['password'];
         } else {
             $password = Terminus::promptSecret('Your dashboard password (input will not be shown)');
         }
         $this->auth->logInViaUsernameAndPassword($email, $password);
     }
     $this->log()->debug(get_defined_vars());
     Terminus::launchSelf('art', array('fist'));
 }
示例#3
0
文件: auth.php 项目: newtoid/cli
 /**
  * Log in as a user
  *
  *  ## OPTIONS
  * [<email>]
  * : Email address to log in as.
  *
  * [--password=<value>]
  * : Log in non-interactively with this password. Useful for automation.
  * [--session=<value>]
  * : Authenticate using an existing session token
  * [--debug]
  * : dump call information when logging in.
  */
 public function login($args, $assoc_args)
 {
     # First try to login using a session token if provided
     if (isset($assoc_args['session'])) {
         Terminus::line("Validating session token");
         $data = $this->doLoginFromSessionToken($assoc_args['session']);
         if ($data != FALSE) {
             if (array_key_exists("debug", $assoc_args)) {
                 $this->_debug(get_defined_vars());
             }
             Terminus::line("Logged in as " . $data['email']);
             Terminus::launch_self("art", array("fist"));
         } else {
             Terminus::error("Login Failed!");
         }
         return;
     }
     # Otherwise do a normal email/password-based login
     if (empty($args)) {
         if (isset($_SERVER['TERMINUS_USER'])) {
             $email = $_SERVER['TERMINUS_USER'];
         } else {
             $email = Terminus::prompt("Your email address?", NULL);
         }
     } else {
         $email = $args[0];
     }
     if (\Terminus\Utils\is_valid_email($email)) {
         if (!isset($assoc_args['password'])) {
             exec("stty -echo");
             $password = Terminus::prompt("Your dashboard password (input will not be shown)");
             exec("stty echo");
             Terminus::line();
         } else {
             $password = $assoc_args['password'];
         }
         Terminus::line("Logging in as {$email}");
         $data = $this->doLogin($email, $password);
         if ($data != FALSE) {
             if (array_key_exists("debug", $assoc_args)) {
                 $this->_debug(get_defined_vars());
             }
             Terminus::launch_self("art", array("fist"));
         } else {
             Terminus::error("Login Failed!");
         }
     } else {
         Terminus::error("Error: invalid email address");
     }
 }
示例#4
0
文件: auth.php 项目: andrefy/cli
 /**
  * Log in as a user
  *
  *  ## OPTIONS
  * [<email>]
  * : Email address to log in as.
  *
  * [--password=<value>]
  * : Log in non-interactively with this password. Useful for automation.
  * [--session=<value>]
  * : Authenticate using an existing session token
  * [--debug]
  * : dump call information when logging in.
  */
 public function login($args, $assoc_args)
 {
     # First try to login using a session token if provided
     if (isset($assoc_args['session'])) {
         $this->log()->info("Validating session token");
         $data = $this->doLoginFromSessionToken($assoc_args['session']);
         if ($data != FALSE) {
             if (array_key_exists("debug", $assoc_args)) {
                 $this->_debug(get_defined_vars());
             }
             $this->log()->info("Logged in as " . $data['email']);
             Terminus::launchSelf("art", array("fist"));
         } else {
             $this->failure('Login failed!');
         }
         return;
     }
     # Otherwise do a normal email/password-based login
     if (empty($args)) {
         if (isset($_SERVER['TERMINUS_USER'])) {
             $email = $_SERVER['TERMINUS_USER'];
         } else {
             $email = Terminus::prompt("Your email address?", NULL);
         }
     } else {
         $email = $args[0];
     }
     if (Utils\isValidEmail($email)) {
         if (!isset($assoc_args['password'])) {
             $password = Terminus::promptSecret('Your dashboard password (input will not be shown)');
         } else {
             $password = $assoc_args['password'];
         }
         $this->log()->info("Logging in as {$email}");
         $data = $this->doLogin($email, $password);
         if ($data != FALSE) {
             if (array_key_exists("debug", $assoc_args)) {
                 $this->_debug(get_defined_vars());
             }
             Terminus::launchSelf("art", array("fist"));
         } else {
             $this->failure('Login Failed!');
         }
     } else {
         $this->failure('Invalid email address');
     }
 }
示例#5
0
文件: Input.php 项目: newtoid/cli
 /**
  * Returns $args[key] if exists, then STDIN, then $default
  *
  * @param [array]  $args    Args already input
  * @param [string] $key     Key for searched-for argument
  * @param [string] $label   Promp printed to STDOUT
  * @param [mixed]  $default Returns if no other choice
  *
  * @return [string] Either $args[$key]. $default, or string from prompt
  */
 public static function string($args, $key, $label = "Enter", $default = null)
 {
     if (isset($args[$key])) {
         return $args[$key];
     }
     $string = \Terminus::prompt($label);
     if ($string == '' && isset($default)) {
         return $default;
     }
     return $string;
 }
示例#6
0
 /**
  * Lock an environment to prevent changes
  *
  * ## OPTIONS
  *
  * <info|add|remove>
  * : action to execute ( i.e. info, add, remove )
  *
  * [--site=<site>]
  * : site name
  *
  * [--env=<env>]
  * : site environment
  *
  * [--username=<username>]
  * : your username
  *
  * [--password=<password>]
  * : your password
  *
  **/
 function lock($args, $assoc_args)
 {
     $action = array_shift($args);
     $site = SiteFactory::instance(Input::site($assoc_args));
     $env = Input::env($assoc_args, 'env');
     switch ($action) {
         case 'info':
             $data = $locks = $site->environment($env)->lockinfo();
             if (!Terminus::get_config('json')) {
                 $data = array($data);
             }
             $this->handleDisplay($data);
             break;
         case 'add':
             Terminus::line("Creating new lock on %s -> %s", array($site->getName(), $env));
             if (!isset($assoc_args['username'])) {
                 $email = Terminus::prompt("Username for the lock");
             } else {
                 $email = $assoc_args['username'];
             }
             if (!isset($assoc_args['password'])) {
                 exec("stty -echo");
                 $password = Terminus::prompt("Password for the lock");
                 exec("stty echo");
                 Terminus::line();
             } else {
                 $password = $assoc_args['password'];
             }
             $data = $site->environment($env)->lock($email, $password);
             if ($data and property_exists($data, 'id')) {
                 $this->waitOnWorkflow('sites', $data->site_id, $data->id);
             }
             Terminus::success('Success');
             break;
         case 'remove':
             Terminus::line("Removing lock from %s -> %s", array($site->getName(), $env));
             $data = $site->environment($env)->unlock();
             if (property_exists($data, 'id')) {
                 $this->waitOnWorkflow('sites', $data->site_id, $data->id);
             }
             Terminus::success('Success');
     }
 }
示例#7
0
文件: site.php 项目: RobLoach/cli
 /**
   * Lock an environment to prevent changes
   *
   * ## OPTIONS
   *
   * <info|add|remove>
   * : action to execute ( i.e. info, add, remove )
   *
   * [--site=<site>]
   * : site name
   *
   * [--env=<env>]
   * : site environment
   *
   * [--username=<username>]
   * : your username
   *
   * [--password=<password>]
   * : your password
   *
 **/
 function lock($args, $assoc_args)
 {
     $action = array_shift($args);
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env($assoc_args, 'env'));
     switch ($action) {
         case 'info':
             $info = $env->lockinfo();
             $this->output()->outputRecord($info);
             break;
         case 'add':
             $this->log()->info('Creating new lock on {site}-{env}', array('site' => $site->get('name'), 'env' => $env->get('id')));
             if (!isset($assoc_args['username'])) {
                 $username = Terminus::prompt('Username for the lock');
             } else {
                 $username = $assoc_args['username'];
             }
             if (!isset($assoc_args['password'])) {
                 $password = Terminus::promptSecret('Password for the lock');
             } else {
                 $password = $assoc_args['password'];
             }
             $workflow = $env->lock(array('username' => $username, 'password' => $password));
             $workflow->wait();
             break;
         case 'remove':
             $this->log()->info('Removing lock from {site}-{env}', array('site' => $site->get('name'), 'env' => $env->get('id')));
             $workflow = $env->unlock();
             $workflow->wait();
             break;
     }
     if (isset($workflow)) {
         $this->workflowOutput($workflow);
     }
 }
示例#8
0
文件: site.php 项目: skyywalk3rr/cli
 /**
  * Lock an environment to prevent changes
  *
  * ## OPTIONS
  *
  * <info|add|remove>
  * : action to execute ( i.e. info, add, remove )
  *
  * [--site=<site>]
  * : site name
  *
  * [--env=<env>]
  * : site environment
  *
  * [--username=<username>]
  * : your username
  *
  * [--password=<password>]
  * : your password
  *
  **/
 function lock($args, $assoc_args)
 {
     $action = array_shift($args);
     $site = SiteFactory::instance(Input::sitename($assoc_args));
     $env = Input::env($assoc_args, 'env');
     switch ($action) {
         case 'info':
             $info = $site->environment($env)->lockinfo();
             return $this->handleDisplay($info);
         case 'add':
             Terminus::line("Creating new lock on %s -> %s", array($site->getName(), $env));
             if (!isset($assoc_args['username'])) {
                 $username = Terminus::prompt("Username for the lock");
             } else {
                 $username = $assoc_args['username'];
             }
             if (!isset($assoc_args['password'])) {
                 exec("stty -echo");
                 $password = Terminus::prompt("Password for the lock");
                 exec("stty echo");
                 Terminus::line();
             } else {
                 $password = $assoc_args['password'];
             }
             $workflow = $site->environment($env)->lock(array('username' => $username, 'password' => $password));
             $workflow->wait();
             return Terminus::success('Success');
         case 'remove':
             Terminus::line("Removing lock from %s -> %s", array($site->getName(), $env));
             $workflow = $site->environment($env)->unlock();
             $workflow->wait();
             return Terminus::success('Success');
     }
 }
示例#9
0
 /**
  * Prompt the user for input
  *
  * @param string $message
  */
 static function promptSecret($message = '', $params = array(), $default = null)
 {
     exec("stty -echo");
     $response = Terminus::prompt($message, $params);
     exec("stty echo");
     Terminus::line();
     return $response;
 }
示例#10
0
 static function string($args, $key, $label = "Enter", $default = null)
 {
     if (isset($args[$key])) {
         return $args[$key];
     }
     $string = \Terminus::prompt($label);
     if ('' == $string and null !== $default) {
         return $default;
     }
     return $string;
 }