/**
  * Run the database seeds.
  */
 public function run()
 {
     $rolesRepository = new RoleRepository();
     $userRepository = new UserRepository();
     $role = $rolesRepository->findByName('administrator');
     $user = User::fromNameAndEmailAndPassword('Administrator', '*****@*****.**', '123456');
     $user->confirm();
     $user->role()->associate($role);
     $userRepository->save($user);
 }
 private function findOrCreateUserFor($article)
 {
     /* @var UserRepository $userRepository */
     $userRepository = app(UserRepository::class);
     /* @var RoleRepository $roleRepository */
     $roleRepository = app(RoleRepository::class);
     $adminRole = $roleRepository->findByName('administrator');
     try {
         $user = $userRepository->findByEmail($article['user']['email']);
     } catch (NotFoundException $e) {
         $user = User::fromNameAndEmailAndPassword($article['user']['first_name'] . ' ' . $article['user']['last_name'], $article['user']['email'], 'secret');
         $user->is_confirmed = true;
         $this->dispatch(new AssignRoleToUserCommand($adminRole, $user));
         $userRepository->save($user);
     }
     return $user;
 }
Beispiel #3
0
 /**
  * Invita un nuovo editor creandone l'utente come editor.
  *
  * @param UserInviteRequest $request
  * @param UserRepository $userRepository
  * @param RoleRepository $roleRepository
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postInvite(UserInviteRequest $request, UserRepository $userRepository, RoleRepository $roleRepository)
 {
     $user = User::fromNameAndEmailAndPassword($request->get('name'), $request->get('email'), '');
     try {
         $userRepository->save($user);
     } catch (NotSavedException $e) {
         return redirect('admin/users')->with('error_message', 'Problemi durante la creazione dell\'utente. Riprovare.');
     }
     try {
         $role = $roleRepository->findByName('editor');
         $this->dispatch(new AssignRoleToUserCommand($role, $user));
     } catch (NotSavedException $e) {
         return redirect('admin/users')->with('error_message', 'Problemi in fase di assegnazione del ruolo. Riprovare.');
     }
     return redirect('admin/users')->with('success_message', 'Editor invitato correttamente.');
 }