cartalyst / sentinel

A framework agnostic authentication & authorization system.
BSD 3-Clause "New" or "Revised" License
1.51k stars 238 forks source link

Is there a way to add users via the cli with their rolls etc ? #552

Closed adam-jones-net closed 3 years ago

adam-jones-net commented 3 years ago

I don't think this functionality exists built in but I just wanted to be sure. When I say this I mean without dying sql queries in the CLI ;)

Mxrck commented 3 years ago

we used to create an artisan command (laravel) that ask the user data and create the user with the Sentinel facade.

...
public function handle()
    {
        $username = $this->ask(_i('Correo electrónico del usuario:'));
        $password = $this->secret(_i('Contraseña:'));
        $repeatPassword = $this->secret('Repita la contraseña');

        $credentials = [
            'login' => $username,
            'password' => $password,
        ];
        if ($password === $repeatPassword) {
            $response = \Sentinel::registerAndActivate($credentials);
            $names = $this->ask('Ingrese sus nombres');
            $lastNames = $this->ask('Ingrese sus apellidos');

            $user = \Sentinel::findById($response->id);
            $user->superuser = 1;
            $user->save();
            Profile::create([
                'first_name' => $names,
                'last_name' => $lastNames,
                'user_id' => $user->id
            ]);

            $this->info('Se ha creado su usuario correctamente');
        }
        else {
            $this->error('Las contraseñas no coinciden');
        }
    }
...

imagen

adam-jones-net commented 3 years ago

Thanks @Mxrck that was really useful! :)