Exemple #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     $currentRouteAction = \Route::currentRouteAction();
     $c_a = explode('@', $currentRouteAction);
     if (count($c_a) < 2) {
         return $next($request);
     }
     list($controller, $action) = explode('@', $currentRouteAction);
     $cname = substr($controller, strlen('App\\Http\\Controllers\\'));
     $user = Auth::User();
     if (!$user) {
         $user_count = User::count();
         if ($user_count == 0) {
             if ($cname == 'Auth\\AuthController' && ($action == 'showRegistrationForm' || $action == 'register')) {
                 return $next($request);
             } else {
                 return redirect()->action('Auth\\AuthController@showRegistrationForm')->with('message', 'You must create the 1st user(which would be super admin) before any tasks!')->with('message_type', 'warning');
             }
         } else {
             if ($cname == 'Auth\\AuthController') {
                 if ($action == 'showRegistrationForm' || $action == 'register') {
                     return redirect()->action('Auth\\AuthController@showLoginForm')->with('message', 'Only super admin can create more users!')->with('message_type', 'warning');
                 } else {
                     if ($action == 'showLoginForm' || $action == 'login') {
                         return $next($request);
                     }
                 }
             } else {
                 if ($cname == 'Auth\\PasswordController') {
                     return $next($request);
                 }
             }
         }
         return redirect(action('Auth\\AuthController@showLoginForm') . '?continue=' . \Request::url())->with('message', 'You must login to visit this page!')->with('message_type', 'warning');
     } else {
         if ($user->type === 0) {
             return $next($request);
         }
         //Super Admin!
         if ($cname == 'PageController' || $cname == 'Auth\\AuthController' && $action == 'logout' || $cname == 'HomeController' && ($action == 'getIndex' || $action == 'getHome')) {
             return $next($request);
         }
     }
     return redirect('/');
 }
Exemple #2
0
 public function postEdit($id)
 {
     $iuser = Input::get('user');
     $user = User::find($id);
     if (@$iuser['user_groups']) {
         $new_set = [];
         foreach ($iuser['user_groups'] as $key => $value) {
             $new_set[$key] = ref(UserGroup::find($key));
         }
         if ($user->type === 0) {
             $new_set[1] = ref(UserGroup::find(1));
         }
         $iuser['user_groups'] = $new_set;
     }
     foreach ($iuser as $key => $value) {
         $user->{$key} = $value;
     }
     $user->export();
     return \Redirect::back()->with('message_type', 'success')->with('message', 'Success!');
 }
 /**
  * Retrieve a user by their unique identifier.
  *
  * @param  mixed  $identifier
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  */
 public function retrieveById($identifier)
 {
     return User::import_by_id($identifier);
 }
Exemple #4
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }