/**
  * @param $id
  * @param $group_list
  * @return bool
  * @throws Cartalyst\Sentry\Users\UserNotFoundException
  */
 private static function _check_system_groups($id, $group_list)
 {
     try {
         $user = \Sentry::findUserByID((int) $id);
         $groups = $user->getGroups();
         foreach ($groups as $group) {
             if (!in_array($group['name'], $group_list)) {
                 continue;
             }
             return true;
         }
         return false;
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         throw new Cartalyst\Sentry\Users\UserNotFoundException($e->getMessage());
     }
 }
 public function post_register_mod_user()
 {
     $input = Input::all();
     $rules = array('first_name' => array('required'), 'last_name' => array('required'), 'birth_date' => array('required'), 'gender' => array('required'), 'email' => array('required', 'email', 'unique:users,email'), 'password' => array('required', 'min:6'), 'password_again' => array('required', 'min:6', 'same:password'));
     $messages = array('first_name.required' => 'Nome richiesto', 'last_name.required' => 'Cognome richiesto', 'birth_date.required' => 'Cognome richiesto', 'gender.required' => 'specificare sesso', 'email.required' => 'indirizzo e-mail richiesto', 'email.email' => 'inserisci un indirizzo e-mail valido', 'email.unique' => 'indirizzo e-mail già presente', 'password.required' => 'password necessaria', 'password_again.required' => 'È necessario ripetere la password', 'password_again.same' => 'Passoword non coincidenti');
     $validator = Validator::make($input, $rules, $messages);
     if ($validator->passes()) {
         try {
             $user = Sentry::findUserByID($input['user']['user_id']);
             $user->first_name = $input['user']['first_name'];
             $user->last_name = $input['user']['last_name'];
             $user->email = $input['user']['email'];
             $user->save();
             $users_data = Users_data::where('user_id', $input['user']['user_id'])->update($input['user_data']);
             return $this->make_response($input, false, array('Utente modificato correttamente'));
         } catch (\Exception $e) {
             return $this->make_response($input, true, array("errore non previsto: " . $e->getMessage() . "<br> File " . $e->getFile() . "<br> Line " . $e->getLine()));
         }
     }
     $errors = $validator->messages();
     return $this->make_response($input, true, $errors);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id = FALSE)
 {
     // Assign $id if FALSE
     if ($id === FALSE) {
         $id = $this->user->id;
     }
     // Check if self or admin
     if ($this->user['id'] == $id || $this->user->hasAccess('user.all')) {
         // Validate the create form
         $validator = Validator::make(Input::all(), array('first_name' => 'required', 'last_name' => 'required', 'company_name' => 'required', 'work_phone' => 'required', 'mobile_phone' => 'required', 'address' => 'required', 'city' => 'required', 'state' => 'required', 'zip' => 'required'));
         if ($validator->fails()) {
             return Redirect::back()->withInput()->withErrors($validator);
         } else {
             // Update UserDetail with Post Values
             try {
                 // Get the user
                 $user = Sentry::findUserByID($id);
                 // Update UserDetail
                 $user_detail = UserDetail::find($user->id);
                 $user_detail->first_name = Input::get('first_name');
                 $user_detail->last_name = Input::get('last_name');
                 $user_detail->company_name = Input::get('company_name');
                 $user_detail->address = Input::get('address');
                 $user_detail->address2 = Input::get('address2');
                 $user_detail->city = Input::get('city');
                 $user_detail->state = Input::get('state');
                 $user_detail->zip = Input::get('zip');
                 $user_detail->country = Input::get('country');
                 $user_detail->work_phone = Input::get('work_phone');
                 $user_detail->mobile_phone = Input::get('mobile_phone');
                 $user_detail->save();
                 // Only Admin users can update a user's groups
                 if ($this->user->hasAccess('user.all')) {
                     // Get groups
                     $group_client = Sentry::findGroupByName('client');
                     $group_staff = Sentry::findGroupByName('staff');
                     $group_admin = Sentry::findGroupByName('admin');
                     // Client group
                     if (Input::has($group_client->name)) {
                         if (!$user->inGroup($group_client)) {
                             $user->addGroup($group_client);
                         }
                     } else {
                         if ($user->inGroup($group_client)) {
                             $user->removeGroup($group_client);
                         }
                     }
                     // Staff group
                     if (Input::has($group_staff->name)) {
                         if (!$user->inGroup($group_staff)) {
                             $user->addGroup($group_staff);
                         }
                     } else {
                         if ($user->inGroup($group_staff)) {
                             $user->removeGroup($group_staff);
                         }
                     }
                     // Admin group
                     if (Input::has($group_admin->name)) {
                         if (!$user->inGroup($group_admin)) {
                             $user->addGroup($group_admin);
                         }
                     } else {
                         if ($user->inGroup($group_admin)) {
                             $user->removeGroup($group_admin);
                         }
                     }
                 }
                 Session::flash('alert_success', 'User Details Updated Successfully.');
                 return Redirect::to('/user/' . $user->id);
             } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) {
                 Session::flash('alert_danger', 'User Details Update Failed.');
                 return Redirect::to('/dashboard');
             } catch (Cartalyst\Sentry\Users\UserExistsException $e) {
                 Session::flash('alert_danger', 'User Details Update Failed.');
                 return Redirect::to('/dashboard');
             } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
                 Session::flash('alert_danger', 'User not found.');
                 return Redirect::to('/dashboard');
             } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
                 Session::flash('alert_danger', 'One of the User Groups was not found.');
                 return Redirect::to('/dashboard');
             }
         }
     } else {
         Session::flash('alert_danger', 'Access denied.');
         return Redirect::to('dashboard');
     }
 }
Exemple #4
0
 public function banUser($id)
 {
     $user = Sentry::findUserByID($id);
     if (!$user->hasAccess('admin')) {
         try {
             // Find the user using the user id
             $throttle = Sentry::findThrottlerByUserId($id);
             // Ban the user
             $throttle->ban();
             return Redirect::to('/neverland')->with('global_success', 'User banned successfully banned.');
         } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
             return Redirect::to('/neverland')->with('global_error', 'There is no such user.');
         }
     } else {
         return Redirect::to('/neverland')->with('global_error', 'You can\'t ban Admin');
     }
 }
Exemple #5
0
<?php

Route::get('test', function () {
    // Find the user using the user id
    $user = Sentry::findUserByID(11);
    // Get the user permissions
    $permissions = $user->hasAccess('super');
    return json_decode($permissions);
});
Route::post('title-data/{type}/{provider}/{id}', 'TitleController@getData');
//search
Route::get(Str::slug(trans('main.search')), 'SearchController@byQuery');
Route::get('typeahead/{query}', array('uses' => 'SearchController@typeAhead', 'as' => 'typeahead'));
Route::post('populate-slider/{query}', 'SearchController@populateSlider');
Route::post('typeahead-actor/{query}', array('uses' => 'SearchController@castTypeAhead', 'as' => 'typeahead-cast'));
//homepage and footer
Route::get('/', array('uses' => 'HomeController@index', 'as' => 'home'));
Route::get(Str::slug(trans('main.contactUrl')), array('uses' => 'HomeController@contact', 'as' => 'contact'));
Route::post(Str::slug(trans('main.contactUrl')), array('uses' => 'HomeController@submitContact', 'as' => 'submit.contact'));
//news
Route::get('news/paginate', 'NewsController@paginate');
Route::resource(Str::slug(trans('main.news')), 'NewsController', array('names' => array('show' => 'news.show', 'index' => 'news.index', 'store' => 'news.store', 'edit' => 'news.edit', 'update' => 'news.update', 'destroy' => 'news.destroy', 'create' => 'news.create')));
Route::post('news/external', array('uses' => 'NewsController@updateFromExternal', 'as' => 'news.ext'));
//movies/series
Route::get('titles/paginate', 'TitleController@paginate');
Route::get('titles/relatedTo/{type}', 'TitleController@getRelatedToList');
Route::resource(Str::slug(trans('main.series')), 'SeriesController', array('names' => array('show' => 'series.show', 'index' => 'series.index', 'store' => 'series.store', 'edit' => 'series.edit', 'destroy' => 'series.destroy', 'create' => 'series.create'), 'except' => array('update')));
Route::resource(Str::slug(trans('main.movies')), 'MoviesController', array('names' => array('show' => 'movies.show', 'index' => 'movies.index', 'store' => 'movies.store', 'edit' => 'movies.edit', 'destroy' => 'movies.destroy', 'create' => 'movies.create'), 'except' => array('update')));
Route::post('detach-people', 'TitleController@detachPeople');
//seasons/episodes
Route::resource(Str::slug(trans('main.series')) . '.seasons', 'SeriesSeasonsController', array('except' => array('index', 'edit')));