src/Charcoal/Admin/Script/User/CreateScript.php
private function createUser()
    {
        $this->climate()->underline()->out(
            $this->translator()->translate('Create a new Charcoal Administrator User')
        );

        $user       = $this->modelFactory()->create(User::class);
        $prompts    = $this->userPrompts();
        $properties = $user->properties(array_keys($prompts));

        $vals = [];
        foreach ($properties as $prop) {
            if (!in_array($prop->ident(), array_keys($prompts))) {
                continue;
            }

            $prompt = $prompts[$prop->ident()];

            if ($prompt['property']) {
                $v = $prompt['property'];
            } else {
                $v = $this->promptProperty($prop, $prompt['label']);
            }
            if (isset($prompt['validation'])) {
                call_user_func($prompt['validation'], $v);
            }

            $prop->setVal($v);
            $vals[$prop->ident()] = $v;
        }

        // Trigger reset password
        $user->resetPassword($vals['password']);
        unset($vals['password']);

        $user->setFlatData($vals);
        $ret = $user->save();

        if ($ret) {
            $this->climate()->green()->out("\n".sprintf('Success! User "%s" created.', $user->email()));
        } else {
            $this->climate()->red()->out("\nError. User could not be created.");
        }
    }
private function createUser()
    {
        $this->climate()->underline()->out(
            $this->translator()->translate('Create a new Charcoal Administrator User')
        );

        $user       = $this->modelFactory()->create(User::class);
        $prompts    = $this->userPrompts();
        $properties = $user->properties(array_keys($prompts));

        $vals = [];
        foreach ($properties as $prop) {
            if (!in_array($prop->ident(), array_keys($prompts))) {
                continue;
            }

            $prompt = $prompts[$prop->ident()];

            if ($prompt['property']) {
                $v = $prompt['property'];
            } else {
                $v = $this->promptProperty($prop, $prompt['label']);
            }
            if (isset($prompt['validation'])) {
                call_user_func($prompt['validation'], $v);
            }

            $prop->setVal($v);
            $vals[$prop->ident()] = $v;
        }

        // Trigger reset password
        $user->resetPassword($vals['password']);
        unset($vals['password']);

        $user->setFlatData($vals);
        $ret = $user->save();

        if ($ret) {
            $this->climate()->green()->out("\n".sprintf('Success! User "%s" created.', $user->email()));
        } else {
            $this->climate()->red()->out("\nError. User could not be created.");
        }
    }
private function createUser ( ) { $ this -> climate ( ) -> underline ( ) -> out ( $ this -> translator ( ) -> translate ( 'Create a new Charcoal Administrator User' ) ) ; $ user = $ this -> modelFactory ( ) -> create ( User :: class ) ; $ prompts = $ this -> userPrompts ( ) ; $ properties = $ user -> properties ( array_keys ( $ prompts ) ) ; $ vals = [ ] ; foreach ( $ properties as $ prop ) { if ( ! in_array ( $ prop -> ident ( ) , array_keys ( $ prompts ) ) ) { continue ; } $ prompt = $ prompts [ $ prop -> ident ( ) ] ; if ( $ prompt [ 'property' ] ) { $ v = $ prompt [ 'property' ] ; } else { $ v = $ this -> promptProperty ( $ prop , $ prompt [ 'label' ] ) ; } if ( isset ( $ prompt [ 'validation' ] ) ) { call_user_func ( $ prompt [ 'validation' ] , $ v ) ; } $ prop -> setVal ( $ v ) ; $ vals [ $ prop -> ident ( ) ] = $ v ; } // Trigger reset password $ user -> resetPassword ( $ vals [ 'password' ] ) ; unset ( $ vals [ 'password' ] ) ; $ user -> setFlatData ( $ vals ) ; $ ret = $ user -> save ( ) ; if ( $ ret ) { $ this -> climate ( ) -> green ( ) -> out ( "\n" . sprintf ( 'Success! User "%s" created.' , $ user -> email ( ) ) ) ; } else { $ this -> climate ( ) -> red ( ) -> out ( "\nError. User could not be created." ) ; } }
Create a new user in the database
@return void
Create a new user in the database