/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $email = $this->argument('email');
     $password = $this->argument('password', 'admin123');
     $firstName = $this->argument('first_name', 'Admin');
     $lastName = $this->argument('last_name', 'Tea');
     if (empty($email)) {
         $email = '*****@*****.**';
     }
     if (empty($password)) {
         $password = '******';
     }
     if (empty($firstName)) {
         $firstName = 'Admin';
     }
     if (empty($lastName)) {
         $lastName = 'Tea';
     }
     try {
         // Let's register a user.
         $user = Sentry::createUser(array('email' => $email, 'password' => $password, 'first_name' => $firstName, 'last_name' => $lastName, 'activated' => true));
         // Find the group using the group id
         $group = Sentry::findGroupByName('Administrators');
         // Assign the group to the user
         $user->addGroup($group);
     } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
         $this->error('User with this login already exists');
     } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         $this->error('Group was not found');
     }
 }
Exemplo n.º 2
0
 /**
  * Find the group by name.
  *
  * @param string $name
  * @return \Cartalyst\Sentry\Groups\GroupInterface|false
  */
 public function findByName($name)
 {
     try {
         $group = Sentry::findGroupByName($name);
     } catch (GroupNotFoundException $e) {
         $this->error = 'Group was not found.';
         return false;
     }
     return $group;
 }
Exemplo n.º 3
0
 public function editor($field)
 {
     $admin = Sentry::findGroupByName('admin');
     if (Sentry::check() && Sentry::getUser()->inGroup($admin)) {
         $pageEditor = $this;
         $fieldEdit = "editor_init_" . get_class($pageEditor) . "_" . $field . "_" . $pageEditor->id;
         return View::make('builder::partials.editor_init', compact("pageEditor", "field", "fieldEdit"));
     } else {
         return $this->{$field};
     }
 }
Exemplo n.º 4
0
 /**
  * Updates a group info.
  *
  * @param  array  $id
  */
 public function update(array $input, $id)
 {
     try {
         $group = Sentry::findGroupByName($id);
         $group->name = $input['name'];
         $group->permissions = array('superuser' => $input['superuser'], 'titles.edit' => $input['titles_edit'], 'titles.create' => $input['titles_create'], 'titles.delete' => $input['titles_delete'], 'people.create' => $input['people_create'], 'people.edit' => $input['people_edit'], 'people.delete' => $input['people_delete'], 'users.create' => $input['users_create'], 'users.edit' => $input['users_edit'], 'users.delete' => $input['users_delete'], 'slides.create' => $input['slides_create'], 'slides.edit' => $input['slides_edit'], 'slides.delete' => $input['slides_delete'], 'actions.manage' => $input['actions_manage'], 'settings.manage' => $input['settings_manage'], 'ads.manage' => $input['ads_manage'], 'reviews.delete' => $input['reviews_delete'], 'links.approve' => $input['links_approve'], 'links.delete' => $input['links_delete'], 'groups.create' => $input['groups_create'], 'groups.edit' => $input['groups_edit'], 'groups.delete' => $input['groups_delete'], 'production_companies.create' => $input['production_companies_create'], 'production_companies.edit' => $input['production_companies_edit'], 'production_companies.delete' => $input['production_companies_delete'], 'tv_networks.create' => $input['tv_networks_create'], 'tv_networks.edit' => $input['tv_networks_edit'], 'tv_networks.delete' => $input['tv_networks_delete']);
         if ($group->save()) {
             \Cache::flush();
             return 'success';
         } else {
             return 'Please check your input';
         }
     } catch (NameRequiredException $e) {
         return 'Name field is required';
     } catch (GroupExistsException $e) {
         return 'Group already exists.';
     } catch (GroupNotFoundException $e) {
         return 'Group was not found.';
     }
 }
 public function index()
 {
     if (Sentry::inGroup(Sentry::findGroupByName('Admins'))) {
         $data['openTickets'] = $this->ticket->getOpenTickets();
         $data['inProgressTickets'] = $this->ticket->getInProgressTickets();
         $data['openProjects'] = $this->project->getOpenProjects();
         $data['inProgressProjects'] = $this->project->getInProgressProjects();
         $data['openInvoices'] = $this->invoice->getOpenInvoices();
         $data['openInvoicesAmount'] = $this->invoice->getOpenInvoicesTotalAmount();
         $data['overdueInvoices'] = $this->invoice->getOverdueInvoices();
         $data['overdueInvoicesAmount'] = $this->invoice->getOverdueInvoicesTotalAmount();
         return View::make('dashboard.admin')->with('data', $data);
     } else {
         $data['openTickets'] = $this->ticket->getOpenTicketsByUser();
         $data['inProgressTickets'] = $this->ticket->getInProgressTicketsByUser();
         $data['openProjects'] = $this->project->getOpenProjectsByUser();
         $data['inProgressProjects'] = $this->project->getInProgressProjectsByUser();
         $data['openInvoices'] = $this->invoice->getOpenInvoicesByUser();
         $data['openInvoicesAmount'] = $this->invoice->getOpenInvoicesTotalAmountByUser();
         $data['overdueInvoices'] = $this->invoice->getOverdueInvoicesByUser();
         $data['overdueInvoicesAmount'] = $this->invoice->getOverdueInvoicesTotalAmountByUser();
         return View::make('dashboard.user')->with('data', $data);
     }
 }
Exemplo n.º 6
0
 public function postUsers(Request $request)
 {
     $outputMessage = array();
     if ($request->has('action')) {
         switch ($request->get('action')) {
             case 'new':
                 $email = $request->get('email');
                 $password = $request->get('password');
                 $firstname = $request->get('firstname');
                 $lastname = $request->get('lastname');
                 //$groupName = $request->get('group');
                 $groupID = $request->get('group');
                 try {
                     $user = Sentry::register(array('email' => $email, 'first_name' => $firstname, 'last_name' => $lastname, 'password' => $password, 'activated' => true));
                     if ($user) {
                         $outputMessage[] = array("type" => "success", "msg" => "User created successfuly.");
                         if ($groupID == 1) {
                             $group = Sentry::findGroupByName('user');
                             $user->addGroup($group);
                             $outputMessage[] = array("type" => "alert", "msg" => "The God is unique.User is added to User group ;)");
                         } else {
                             $group = Sentry::findGroupById($groupID);
                             if ($group) {
                                 $user->addGroup($group);
                                 $outputMessage[] = array("type" => "success", "msg" => "User added to " . $group->name . " successfuly");
                             } else {
                                 $group = Sentry::findGroupByName('user');
                                 $user->addGroup($group);
                                 $outputMessage[] = array("type" => "alert", "msg" => "Group " . $group->name . " not found.User is added to User group ;)");
                             }
                         }
                     }
                 } catch (\Cartalyst\Sentry\Users\LoginRequiredException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "Login field is required.");
                 } catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "Login field is required.");
                 } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "User with this login already exists.");
                 } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "Group was not found.");
                 }
                 break;
         }
     }
     $groups = Sentry::findAllGroups();
     $users = User::select(array('id', 'first_name', 'last_name', 'email'))->paginate(20);
     return view('admin.users')->with('users', $users)->with('groups', $groups)->with('messages', $outputMessage);
 }
Exemplo n.º 7
0
 /**
  * Checks if a user belongs to the given Role Name
  * @param  string $name
  * @return bool
  */
 public function hasRoleName($name)
 {
     $role = Sentry::findGroupByName($name);
     return $this->inGroup($role);
 }
Exemplo n.º 8
0
 /**
  * Handle update a user.
  *
  * @param  integer $userId
  * @return Response
  */
 public function update($userId)
 {
     try {
         $user = Sentry::findUserById($userId);
     } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
         // Return 404 if user not found
         return API::resourceJson(array('message' => 'Requested user could not be found.'), 404);
     }
     $validationRules = array('email' => 'required|email', 'first_name' => 'required');
     $input = Input::all();
     // Do validation
     $validator = Validator::make($input, $validationRules);
     if (!$validator->fails()) {
         if (isset($input['group'])) {
             try {
                 // Find the group using the group id
                 $group = Sentry::findGroupByName($input['group']);
                 // Assign the group to the user
                 $user->addGroup($group);
             } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
                 return API::resourceJson(array('message' => 'Requested group could not be found.'), 400);
             }
         }
         $user->setAttribute('email', $input['email']);
         if (isset($input['password'])) {
             $user->setAttribute('password', $input['password']);
         }
         if (isset($input['activated'])) {
             $user->setAttribute('activated', $input['activated']);
         }
         if (isset($input['first_name'])) {
             $user->setAttribute('first_name', $input['first_name']);
         }
         if (isset($input['last_name'])) {
             $user->setAttribute('last_name', $input['last_name']);
         }
         // Save the user
         $user->save();
     } else {
         return API::resourceJson(array('message' => 'Provided information is not valid.', 'errors' => $validator->errors()->toArray()), 422);
     }
     return API::resourceJson(new UserTemplate($user));
 }
Exemplo n.º 9
0
 /**
  * Adds the array of groups to the specified user.
  *
  * @param \Cartalyst\Sentry\Users\Eloquent\User $user
  * @param array                                 $groups
  *
  * @return bool
  */
 private function addGroupsToUser($user, array $groups = [])
 {
     if (count($groups) > 0) {
         foreach ($groups as $group) {
             try {
                 $group = Sentry::findGroupByName($group);
                 $user->addGroup($group);
             } catch (GroupNotFoundException $e) {
             }
         }
         return true;
     }
     return false;
 }
Exemplo n.º 10
0
 /**
  * Find a role by its name
  * @param  string $name
  * @return mixed
  */
 public function findByName($name)
 {
     return Sentry::findGroupByName($name);
 }