In this recipe, we will learn how to build and run a custom shell, which will ask for a username and a password, and add the given account to a list of user accounts. Based on the system created in the recipe Setting up a basic authentication system from Chapter 1, Authentication, this shell is a great help when looking to create test accounts.
To go through this recipe we need an authentication system. Follow the entire recipe Setting up a basic authentication system from Authentication chapter.
Create a file named user.php
and place it in your app/vendors/shells
folder, with the following contents:
<?php App::import('Core', 'Security'); class UserShell extends Shell { public $uses = array('User'); public function main() { $user = $this->in('Enter the username (ENTER to abort):'); if (empty($user)) { $this->_stop(); } $defaultPassword = $this->_randomPassword();; $password = $this->in('Enter the password (ENTER to use...