Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php  
  2. class CreateUserShell extends Shell {
  3.     var $uses = array('User');
  4.  
  5.     function main() {
  6.         App::import('Component','Auth');
  7.         $this->Auth = new AuthComponent(null);
  8.        
  9.         $this->out('Create Admin User:');
  10.         $this->hr();
  11.          
  12.         while (empty($username)) {
  13.           $username = $this->in('Username:');
  14.           if (empty($username)) $this->out('Username must not be empty!');
  15.         }
  16.          
  17.         while (empty($pwd1)) {
  18.           $pwd1 = $this->in('Password:');
  19.           if (empty($pwd1)) $this->out('Password must not be empty!');
  20.         }
  21.          
  22.         while (empty($pwd2)) {
  23.           $pwd2 = $this->in('Password Confirmation:');
  24.           if ($pwd1 !== $pwd2) {
  25.             $this->out('Passwort and confirmation do not match!');
  26.             $pwd2 = NULL;
  27.           }
  28.         }
  29.          
  30.         // we got all the data, let's create the user        
  31.         $this->User->create();
  32.               if ($this->User->save(array('username' => $username, 'password' => $this->Auth->password($pwd1)))) {
  33.                   $this->out('Admin User created successfully!');
  34.               } else {
  35.                   $this->out('ERROR while creating the Admin User!!!');
  36.               }
  37.     }
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement