/** * Handle an incoming request. * * @param Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) { //get the admin check closure that should be supplied in the config /** @var CmfConfig $configs */ $configs = CmfConfig::getInstance(); //if this is a simple false value, send the user to the login redirect $response = \Auth::guard()->check() && $configs->isAuthorised($request); if (!$response) { $loginUrl = route($configs->login_route()); $redirectUri = $request->url(); if ($request->ajax()) { \Session::set(CmfConfig::getInstance()->session_redirect_key(), $redirectUri); return response()->json(['redirect_with_reload' => $loginUrl], HttpCode::UNAUTHORISED); } else { return redirect()->guest($loginUrl)->with(CmfConfig::getInstance()->session_redirect_key(), $redirectUri); } } else { if (is_a($response, 'Illuminate\\Http\\JsonResponse') || is_a($response, 'Illuminate\\Http\\Response')) { return $response; } else { if (is_a($response, 'Illuminate\\Http\\RedirectResponse')) { $redirectUri = $request->url(); /** @var RedirectResponse $response */ return $response->with(CmfConfig::getInstance()->session_redirect_key(), $redirectUri); } } } return $next($request); }
/** * Bootstrap the application services. * * @return void */ public function boot() { view()->composer('layout.admin', function ($view) { $usuario = Manager::with('company')->where('id', '=', \Auth::guard('web_managers')->user()->id)->firstOrFail(); $json = json_decode($usuario->company->configuracoes); if ($json) { $corPainel = $json->config->cores->cor; $dados['corPainel'] = $corPainel; Cookie::queue(Cookie::make('corPainel', $json->config->cores, 2628000)); } $dados['usuario'] = $usuario; $view->with($dados); }); view()->composer('errors.404', function ($view) { $dados = []; $cookie = Cookie::get('corPainel'); if ($cookie) { $cookie = Crypt::decrypt($cookie); $dados['corPainel'] = $cookie->cor; } $view->with($dados); }); view()->composer('layout.login', function ($view) { $cookie = Cookie::get('corPainel'); if ($cookie) { $cores = ['bgm-white' => '#ffffff', 'bgm-black' => '#000000', 'bgm-brown' => '#795548', 'bgm-pink' => '#e91e63', 'bgm-red' => '#f44336', 'bgm-blue' => '#2196f3', 'bgm-purple' => '#9c27b0', 'bgm-deeppurple' => '#673ab7', 'bgm-lightblue' => '#03a9f4', 'bgm-cyan' => '#00bcd4', 'bgm-teal' => '#009688', 'bgm-green' => '#4caf50', 'bgm-lightgreen' => '#8bc34a', 'bgm-lime' => '#cddc39', 'bgm-yellow' => '#ffeb3b', 'bgm-amber' => '#ffc107', 'bgm-orange' => '#ff9800', 'bgm-deeporange' => '#ff5722', 'bgm-gray' => '#9e9e9e', 'bgm-bluegray' => '#607d8b', 'bgm-indigo' => '#3f51b5']; $corHex = $cores[$cookie->cor]; $dados['corHex'] = $corHex; } $dados['corPainel'] = $cookie; $view->with($dados); }); }
/** * Get the comment's user_id attribute. * * @return bool */ public function getLikedAttribute() { if (!\Auth::guard()->check()) { return false; } return $this->likes()->where('user_id', \Auth::guard()->user()->getAuthIdentifier())->exists(); }
public function handle($request, \Closure $next, $guard = null) { if (\Auth::guard($guard)->check()) { return redirect()->route('admin'); } return $next($request); }
public static function create() { self::$urls = \Config::get('panel.panelControllers'); $config = \Serverfireteam\Panel\Link::allCached(); $dashboard = array(); $appHelper = new AppHelper(); // Make Dashboard Items foreach ($config as $value) { $modelName = $value['url']; if (in_array($modelName, self::$urls)) { $model = "Serverfireteam\\Panel\\" . $modelName; } else { $model = $appHelper->getNameSpace() . $modelName; } //if (class_exists($value)) { if ($value['show_menu']) { $user = \Auth::guard('panel')->user(); if (!$user->hasRole('super')) { if (!\Auth::guard('panel')->user()->hasPermission($modelName . 'all')) { continue; } } $dashboard[] = array('modelName' => $modelName, 'title' => $value['display'], 'count' => $model::count(), 'showListUrl' => 'panel/' . $modelName . '/all', 'addUrl' => 'panel/' . $modelName . '/edit'); } } return $dashboard; }
/** * 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) { if (Auth::guard($guard)->check()) { return redirect(addon()->config('addon.routes.landing', '/')); } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (is_null(\Auth::guard('panel')->user())) { $message = session('message', Lang::get('panel::fields.enterEmail')); return redirect('/panel/login')->with('message', $message)->with('mesType', 'message'); } return $next($request); }
function __construct() { if (\Auth::guard('web')->check()) { $this->user_grade = \Auth::user()->grade; } else { $this->user_grade = 0; } }
public function verify($username, $password) { $credentials = ['email' => $username, 'password' => $password]; if (\Auth::guard($this->guard)->once($credentials)) { return \Auth::guard($this->guard)->user()->id; } return false; }
public function create($id) { $cliente = Client::with('info')->where('id', '=', $id)->first(); $company = Company::with('managers')->where('id', '=', \Auth::guard('web_managers')->user()->company_id)->firstOrFail(); $config = json_decode($company->configuracoes); $tiposEvento = ArrayObjToArray($config->config->tipoEvento); return view('admin.orcamento.create', compact('cliente', 'config', 'tiposEvento', 'company')); }
public function checkLoggedIn() { $temp = \Config::get('auth.model'); \Config::set('auth.model', 'Serverfireteam\\Panel\\Admin'); $access = !\Auth::guard('panel')->guest(); \Config::set('auth.model', $temp); return $access; }
public function alteraConfigs(Request $request) { $company = Company::find(\Auth::guard('web_managers')->user()->company_id); $company->configuracoes = $request->config; $configs = json_decode($company->configuracoes); Cookie::queue(Cookie::make('corPainel', $configs->config->cores, 2628000)); $company->save(); return 'true'; }
/** @test */ public function it_keeps_track_of_the_token() { Auth::guard('jwt')->attempt($this->getCorrectCredentials()); $token = Auth::guard('jwt')->token(); $this->assertInstanceOf('\\Vercoutere\\LaravelJwt\\Token', $token); Auth::guard('jwt')->logout(); $this->assertFalse(Auth::guard('jwt')->token()); Auth::guard('jwt')->authenticateWithToken($token); $this->assertInstanceOf('\\Vercoutere\\LaravelJwt\\Token', Auth::guard('jwt')->token()); }
/** * 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) { if (Auth::guard($guard)->guest()) { if ($request->ajax() || $request->wantsJson()) { return response('Unauthorized.', 401); } else { return redirect()->guest(addon()->config('addon.routes.login', '/login')); } } return $next($request); }
/** * 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) { if (\Auth::guard($guard)->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } return $next($request); }
/** * Update the users password. * * @param PasswordUpdateRequest $request * @param BlogUserInterface $user * * @return $this|\Illuminate\Http\RedirectResponse */ public function updatePassword(PasswordUpdateRequest $request, BlogUserInterface $user) { $this->validate($request, ['password' => 'required', 'new_password' => 'required|confirmed|min:6']); $guard = \Auth::guard(); if (!$guard->validate($request->only('password'))) { return back()->withErrors(trans('auth.failed')); } $user->password = bcrypt($request->input('new_password')); $user->save(); Session::set('_passwordUpdate', trans('easel::messages.update_success', ['entity' => 'Password'])); return redirect()->route('admin.profile.edit.password', $user->id); }
public function postEdit() { $demo = false; if (\Config::get('panel.demo') == true) { $demo = true; } $admin = Admin::find(\Auth::guard('panel')->user()->id); $inputs = Input::all(); $admin->update($inputs); $admin->save(); return \View('panelViews::editProfile')->with(array('admin' => $admin, 'message' => \Lang::get('panel::fields.successfullEditProfile'), 'demo_status' => $demo)); }
/** * Verify the incoming request's user belongs to team. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return \Illuminate\Http\Response */ public function handle($request, $next) { if (!backend_auth()->check()) { if ($user = \Auth::guard('api')->user()) { backend_auth()->setUser($user); $response = $next($request); $response->withCookie($this->repository->createCookie($user->token())); return $response; } } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param int|string $permission * * @throws \Litepie\User\Exceptions\PermissionDeniedException * * @return mixed */ public function handle($request, Closure $next, $permission, $guard = null) { if (Auth::guard($guard)->check() && Auth::guard($guard)->user()->can($permission)) { return $next($request); } if (user()->new && config('user.verify_email')) { return redirect('verify'); } if (!user()->active) { throw new InvalidAccountException('Account is not active.'); } throw new PermissionDeniedException($permission); }
public function handle(Request $request, \Closure $next, $guard = null) { if (\Gate::denies('admin.access')) { if ($request->ajax()) { return response('Unauthorized.', 401, ['X-Redirect-Url' => route('admin.login')]); } elseif (\Auth::guard($guard)->check()) { return view('admin::auth.denied'); } else { return redirect()->guest(route('admin.login')); } } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param int|string $permission * * @throws \Litepie\User\Exceptions\PermissionDeniedException * @return mixed */ public function handle($request, Closure $next, $guard) { if (Auth::guard($guard)->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } if (user()->new && config('user.verify_email')) { return redirect('verify'); } if (!user()->active) { throw new InvalidAccountException('Account is not active.'); } return $next($request); }
/** * Execute an action on the controller. * * @param string $method * @param array $parameters * * @return \Symfony\Component\HttpFoundation\Response */ public function callAction($method, $parameters) { /** * @var HasAccessEntity|PermissionsTrait|null $user * @var Permissions $annotation */ try { $user = \Auth::guard(property_exists($this, 'guard') ? $this->guard : null)->user(); $reader = new AnnotationReader(); $class = new \ReflectionClass($this); $annotation = $reader->getClassAnnotation($class, Permissions::class); if ($annotation instanceof Permissions) { if ($user instanceof HasAccessEntity) { if (!$user->hasAccess($annotation->permissions, $annotation->all)) { throw new AccessDeniedHttpException(); } } else { throw new \RuntimeException('User must implements HasAccessEntity'); } } $method = $class->getMethod($method); $annotation = $reader->getMethodAnnotation($method, Permissions::class); if ($annotation instanceof Permissions) { if ($user instanceof HasAccessEntity) { if (!$user->hasAccess($annotation->permissions, $annotation->all)) { throw new AccessDeniedHttpException(); } } else { throw new \RuntimeException('User must implements HasAccessEntity'); } } } catch (AccessDeniedHttpException $e) { if (\Request::ajax()) { return \Response::json(['error' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()], 403, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } else { return view(property_exists($this, 'denyView') ? $this->denyView : 'deny'); } } return $method->invokeArgs($this, $parameters); }
/** * 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) { if (Auth::guard('web_managers')->check()) { $tenantColumn = 'company_id'; $tenantId = \Auth::guard('web_managers')->user()->company_id; TenantScope::addTenant($tenantColumn, $tenantId); } if (Auth::guard($guard)->guest()) { if ($request->ajax()) { return response('Unauthorized.', 401); } else { switch ($guard) { case 'web_managers': $path = 'admin/login'; break; default: $path = 'cliente/login'; break; } return redirect()->guest($path); } } return $next($request); }
/** * Register the service provider. * * @return void */ public function register() { //Registering my services on laravel's container $this->app->singleton('AvalonAdmin.ParameterService', ParameterService::class); $this->app->singleton('AvalonAdmin.CategoryService', CategoryService::class); //Registering my Facades. (I'll not make user register manually so usefull facades.) $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Avalon\\Parameter', \Andersonef\AvalonAdmin\Facades\Parameter::class); $loader->alias('Avalon\\Category', \Andersonef\AvalonAdmin\Facades\Category::class); //Setting a new authentication driver: if (!config('auth.providers.avalon-admin')) { config(['auth.providers.avalon-admin' => ['driver' => 'eloquent', 'model' => User::class]]); config(['auth.guards.avalon-admin' => ['driver' => 'session', 'provider' => 'avalon-admin']]); } $this->commands([UpCommand::class, DownCommand::class]); //Injecting dependencies: $this->app->when(UserService::class)->needs(Guard::class)->give(function () { return \Auth::guard('avalon-admin'); }); //Injecting dependencies on services: $this->app->when(ParameterService::class)->needs(Model::class)->give(Parameter::class); $this->app->when(CategoryService::class)->needs(Model::class)->give(Category::class); $this->app->when(\Andersonef\AvalonAdmin\Services\UserService::class)->needs(Model::class)->give(User::class); }
$pros = App\Product::all(); $intersect = $pros; return dd($intersect); }); Route::post('test', function () { }); // Admin Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function () { Route::group(['middleware' => 'web'], function () { Route::group(['namespace' => 'Auth'], function () { Route::get('login', 'AuthController@getLogin'); Route::post('login', 'AuthController@postLogin'); Route::get('logout', 'AuthController@getLogout'); }); Route::resource('product', 'ProductController'); Route::post('product/{product}/ajax/destroy', 'ProductController@ajaxDestroy'); Route::post('product/destroy', 'ProductController@destroy'); Route::resource('category', 'CategoryController'); Route::get('category/{id}/destroy', 'CategoryController@destroy'); Route::resource('/', 'DashBoardController'); Route::get('/test', function () { //Auth::guard('admin')->attempt(array('user_id'=>'Nosh','password'=>123123)) ; //Auth::guard('admin')->logout(); return Auth::guard('admin')->user(); }); Route::get('invoice', 'InvoiceController@index'); Route::get('cart', 'CartController@index'); Route::get('checkpayment', 'CheckPayment@index'); Route::post('checkpayment', 'CheckPayment@post'); }); });
<?php Route::get('home', ['middleware' => 'auth:web_managers', 'as' => 'home', function () { dd(\Auth::guard('web_managers')->user()->toArray()); }]); Route::group(['middleware' => 'auth:web_managers', 'as' => 'cliente.', 'prefix' => 'cliente'], function () { Route::get('', ['as' => 'index', 'uses' => 'ClienteController@index']); Route::get('adiciona', ['as' => 'create', 'uses' => 'ClienteController@create']); Route::post('create', ['as' => 'store', 'uses' => 'ClienteController@store']); Route::get('{id}/editar', ['as' => 'edit', 'uses' => 'ClienteController@edit']); Route::get('{id}/detalhes/{pagina}', ['as' => 'show', 'uses' => 'ClienteController@show']); Route::post('update/{id}', ['as' => 'update', 'uses' => 'ClienteController@update']); Route::put('updateFoto/{id}', ['as' => 'updateFoto', 'uses' => 'ClienteController@updateFoto']); Route::post('{id}/deletar', ['as' => 'destroy', 'uses' => 'ClienteController@destroy']); }); Route::group(['middleware' => 'auth:web_managers', 'as' => 'orcamento.', 'prefix' => 'orcamento'], function () { Route::get('', ['as' => 'index', 'uses' => 'OrcamentoController@index']); Route::get('{id}/detalhes/', ['as' => 'index', 'uses' => 'OrcamentoController@show']); Route::get('{id}/adiciona', ['as' => 'create', 'uses' => 'OrcamentoController@create']); Route::post('store', ['as' => 'store', 'uses' => 'OrcamentoController@store']); Route::get('pendentes', ['as' => 'pendentes', 'uses' => 'OrcamentoController@pendentes']); Route::get('{id}/detalhes', ['as' => 'show', 'uses' => 'OrcamentoController@show']); Route::post('apiLista', ['as' => 'apiLista', 'uses' => 'OrcamentoController@apiLista']); Route::post('apiMensagens', ['as' => 'apiMensagens', 'uses' => 'OrcamentoController@apiMensagens']); }); Route::group(['middleware' => 'auth:web_managers', 'as' => 'config.', 'prefix' => 'configuracoes'], function () { Route::get('index', ['as' => 'index', 'uses' => 'ConfigController@index']); Route::post('alteraConfigs', ['as' => 'alteraConfigs', 'uses' => 'ConfigController@alteraConfigs']); }); Route::group(['as' => 'login.', 'prefix' => 'login'], function () { Route::get('', ['as' => 'index', 'uses' => 'AuthController@index']);
/** * @return Admin */ public static function getAdmin() { return \Auth::guard()->user(); }
public function postChangePassword() { $user = Admin::find(\Auth::guard('panel')->user()->id); $password = Input::only('current_password'); $new_password = Input::only('password'); $retype_password = Input::only('password_confirmation'); $user_password = \Auth::guard('panel')->user()->password; //Check to see if user enters current password correctly if (\Hash::check($password['current_password'], $user_password)) { if ($new_password['password'] == $retype_password['password_confirmation']) { $user->password = \Hash::make($new_password['password']); $user->save(); return \Redirect::to('/panel/changePassword')->with('message', 'Successfully Changed Your Password!!'); } else { return \Redirect::to('/panel/changePassword')->with('message', 'Passwords not matched!!')->with('mesType', 'error'); } } else { return \Redirect::to('/panel/changePassword')->with('message', 'Password is not correct!!')->with('mesType', 'error'); } }
/** log the user out of the application **/ public function logout() { \Auth::guard($this->getGuard())->logout(); \Session::flash('message', 'You have been logged out.'); return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/'); }
function teacher() { return Auth::guard('teacher')->user(); }