Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // email
     $email = $this->argument('email');
     // génération automatique de l'email
     $password = $this->option('pass');
     if (empty($password)) {
         $password = \Models\Business\User::generateRandomPassword();
         $password = $this->ask('Mot de passe', $password);
     }
     // nom complet
     $name = $this->option('name');
     if (empty($name)) {
         $name = $this->ask('Nom complet');
     }
     // interface
     $interface = $this->option('interface');
     if (empty($interface)) {
         $interface = $this->ask('Interface', Acl::INTERFACE_DEFAULT);
     }
     // generation de l'utilisateur
     \Models\Business\User::init($email, $password, $interface, $name, $this->option('admin'));
     // affichage du mot de passe
     $this->info(sprintf('Le mot de passe de l\'utilisateur "%s" [%s] est : %s', $name, $email, $password));
 }
Example #2
0
 /**
  *
  *
  * @param $id
  * @return mixed
  */
 public function postUser($id = null)
 {
     \ruler()->check($this->permission, ['id' => 'exists:user,user_id'], ['id' => $uuid = f($id, 'uuid')]);
     // Recuperation du model
     $user = User::findOrNew($uuid);
     $form = \form()->enableRemote();
     $form->setLegend('Utilisateur : ' . $user->name);
     $form->addText('name', 'Nom');
     $form->addEmail('email', 'Email');
     if (!$user->exists) {
         $form->addText('password', 'Mot de passe');
     }
     $interface = UserInterface::orderBY('name')->pluck('name', 'user_interface_id');
     $form->addSelect('user_interface_id', 'Interface', $interface);
     $form->addSubmit('Enregistrer');
     // enregistrement
     if (\request()->has('Enregistrer')) {
         $form->valid(\request()->all());
         if ($form->isValid()) {
             $data = $form->getFilteredAliasValues();
             try {
                 if ($user->exists) {
                     $user->email = $data['email'];
                     $user->user_interface_id = $data['user_interface_id'];
                     $user->name = $data['name'];
                     $user->save();
                 } else {
                     \Models\Business\User::init($data['email'], $data['password'], $data['user_interface_id'], $data['name']);
                 }
                 \js()->success()->closeRemoteModal()->reloadDataTable();
             } catch (\Exception $e) {
                 \js()->error($e->getMessage());
             }
         }
     } elseif ($user->exists) {
         $form->populate($user->toArray());
     } else {
         $form->populate(['password' => \FrenchFrogs\Models\Business\User::generateRandomPassword()]);
     }
     return response()->modal($form);
 }