Guest User

Untitled

a guest
Dec 29th, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.59 KB | None | 0 0
  1. public function redirectPath()
  2. {
  3. //$user = Auth::user()->with('rol')->get();
  4. if (Auth::user()->rol =='admin') {
  5. dd(Auth::user());
  6. }
  7. return '/vacation/request';
  8. }
  9.  
  10. <?php session_start(); ?>
  11. <?php if ($_SESSION[Auth::user] == "USUARIO_ADMIN") { ?>
  12.  
  13. <li><a href="dashboard-crm.html" data-i18n="nav.dash.crm" class="menu-item">Vacaciones</a>
  14. <ul class="menu-content">
  15. <li><a href="{{url('/vacation/request')}}" data-i18n="nav.menu_levels.solic" class="menu-item">Ver solicitudes</a>
  16. </li>
  17. <li><a href="{{url('/vacation/calendar')}}" data-i18n="nav.menu_levels.solic" class="menu-item">Ver calendario</a>
  18. </li>
  19. </ul>
  20. </li>
  21. <?php } ?>
  22. <li><a href="{{ url('/vacation/create/'.Crypt::encrypt(Auth::user()->id).'/'.Crypt::encrypt(Auth::user()->name)) }}" data-i18n="nav.dash.crm" class="menu-item">Solicitar Vacaciones</a></li>
  23.  
  24. class MDusuarioadmin
  25. {
  26. /**
  27. * Handle an incoming request.
  28. *
  29. * @param IlluminateHttpRequest $request
  30. * @param Closure $next
  31. * @return mixed
  32. */
  33. public function handle($request, Closure $next)
  34. {
  35.  
  36. $usuario_actual=Auth::user();
  37. if($usuario_actual->tipoUsuario!=1){
  38. return view("mensajes.msj_rechazado")->with("msj","No tiene suficientes Privilegios para acceder a esta seccion");
  39. }
  40. return $next($request);
  41.  
  42. }
  43. }
  44.  
  45. class MDusuariostandard
  46. {
  47. /**
  48. * Handle an incoming request.
  49. *
  50. * @param IlluminateHttpRequest $request
  51. * @param Closure $next
  52. * @return mixed
  53. */
  54. public function handle($request, Closure $next)
  55. {
  56.  
  57. $usuario_actual=Auth::user();
  58. if($usuario_actual->tipoUsuario!=2){
  59. return view("mensajes.msj_rechazado")->with("msj","Esta seccion es solo visible para el usuario estandard <br/> usted aun no ha sido asignado como usuario standard , consulte al administrador del sistema");
  60. }
  61. return $next($request);
  62.  
  63. }
  64. }
  65.  
  66. //rutas accessibles slo si el usuario no se ha logueado
  67. Route::group(['middleware' => 'guest'], function () {
  68.  
  69. Route::get('login', 'AuthAuthController@getLogin');
  70. Route::post('login', ['as' =>'login', 'uses' => 'AuthAuthController@postLogin']);
  71. // Registration routes...
  72. Route::get('register', 'AuthAuthController@getRegister');
  73. Route::post('register', ['as' => 'auth/register', 'uses' => 'AuthAuthController@postRegister']);
  74.  
  75.  
  76. });
  77.  
  78. //rutas accessibles solo si el usuario esta autenticado y ha ingresado al sistema
  79. Route::group(['middleware' => 'auth'], function () {
  80.  
  81. //Route::get('/', 'HomeController@index');
  82. //Route::get('home', 'HomeController@index');
  83. Route::get('logout', ['as' => 'logout', 'uses' => 'AuthAuthController@getLogout']);
  84. //Route::get('listado_usuarios/{page?}', 'UsuariosController@listado_usuarios');
  85.  
  86. });
  87.  
  88. //rutas accessibles solo para el usuario administrador
  89. Route::group(['middleware' => 'usuarioAdmin'], function () {
  90.  
  91. Route::get('/worker/create', 'WorkerController@create');
  92. Route::post('/worker/store', 'WorkerController@store');
  93. Route::post('/worker/upload', ['as' => 'worker.upload', 'uses' => 'WorkerController@upload']);
  94. Route::get('/worker/show/{id_worker}', 'WorkerController@show');
  95. Route::get('/worker/edit/{id_worker}', 'WorkerController@edit');
  96. Route::post('/worker/update', 'WorkerController@update');
  97. Route::get('/worker/retirados', 'WorkerController@retirados');
  98. Route::post('/worker/remove', 'WorkerController@remove');
  99. Route::get('/worker/showall', 'WorkerController@showall');
  100.  
  101. Route::get('/area', 'AreaController@index');
  102. Route::get('/area/create', 'AreaController@create');
  103. Route::post('/area/store', 'AreaController@store');
  104.  
  105. Route::get('/vacation/create/{id_worker}/{name_worker}', 'VacationController@create');
  106. Route::post('/vacation/store', 'VacationController@store');
  107. Route::get('/vacation/calendar', 'VacationController@index');
  108. Route::get('/vacation/create', 'VacationController@index');
  109. Route::get('/vacation/request', 'VacationController@solicitudes');
  110. Route::get('/vacation/update', 'VacationController@update');
  111. });
  112. //rutas accessibles solo para el usuario standard
  113. Route::group(['middleware' => 'usuarioStandard'], function () {
  114.  
  115. Route::get('/vacation/create/{id_worker}/{name_worker}', 'VacationController@create');
  116. Route::post('/vacation/store', 'VacationController@store');
  117. Route::get('/vacation/calendar', 'VacationController@index');
  118. Route::get('/vacation/create', 'VacationController@index');
  119.  
  120. });
  121.  
  122. <?php
  123.  
  124. namespace AppHttpControllersAuth;
  125. use AppUser;
  126. use Validator;
  127. use AppHttpControllersController;
  128. use IlluminateFoundationAuthThrottlesLogins;
  129. use IlluminateFoundationAuthAuthenticatesAndRegistersUsers;
  130.  
  131. use IlluminateContractsAuthGuard;
  132. use IlluminateHttpRequest;
  133. use Session;
  134.  
  135. class AuthController extends Controller
  136. {
  137.  
  138.  
  139. use AuthenticatesAndRegistersUsers, ThrottlesLogins;
  140.  
  141. /*
  142. |--------------------------------------------------------------------------
  143. | Registration & Login Controller
  144. |--------------------------------------------------------------------------
  145. |
  146. | This controller handles the registration of new users, as well as the
  147. | authentication of existing users. By default, this controller uses
  148. | a simple trait to add these behaviors. Why don't you explore it?
  149. |
  150. */
  151.  
  152. protected $redirctTo ='/';
  153.  
  154. /**
  155. * Create a new authentication controller instance.
  156. *
  157. * @return void
  158. */
  159. public function __construct(Guard $auth)
  160. {
  161. $this->auth = $auth;
  162. $this->middleware('guest', ['except' => 'getLogout']);
  163. }
  164.  
  165. /**
  166. * Get a validator for an incoming registration request.
  167. *
  168. * @param array $data
  169. * @return IlluminateContractsValidationValidator
  170. */
  171.  
  172. //login
  173. protected function getLogin()
  174. {
  175. return view("login");
  176. }
  177.  
  178. public function postLogin(Request $request)
  179. {
  180. $this->validate($request, [
  181. 'email' => 'required',
  182. 'password' => 'required',
  183. ]);
  184. Session::put('tipoUsuario', 'admin');
  185. $credentials = $request->only('email', 'password');
  186.  
  187. if ($this->auth->attempt($credentials, $request->has('remember')))
  188. {
  189. $usuarioactual=Auth::user();
  190. return view('home')->with("usuario", $usuarioactual);
  191. }
  192.  
  193. return "credenciales incorrectas";
  194. }
  195.  
  196. //registro
  197. protected function getRegister()
  198. {
  199. return view("registro");
  200. }
  201.  
  202. protected function postRegister(Request $request)
  203. {
  204. $this->validate($request, [
  205. 'name' => 'required',
  206. 'email' => 'required',
  207. 'password' => 'required',
  208. ]);
  209.  
  210. $data = $request;
  211.  
  212. $user=new User;
  213. $user->name=$data['name'];
  214. $user->email=$data['email'];
  215. $user->password=bcrypt($data['password']);
  216.  
  217. if($user->save())
  218. {
  219. return "se ha registrado correctamente el usuario";
  220. }
  221. }
  222.  
  223. //registro
  224. protected function getLogout()
  225. {
  226. $this->auth->logout();
  227.  
  228. Session::flush();
  229.  
  230. return redirect('login');
  231. }
  232.  
  233.  
  234.  
  235. }
  236.  
  237. Route::get('/', function () {
  238. if( Auth::user() ) //se valida si esta logueado
  239. if( Auth::user()->rol =='admin' ) //se valida el tipo de usuario
  240. return redirect('/admin');
  241. else
  242. return redirect('/normal');
  243. else
  244. return redirect('/login');
  245. });
  246.  
  247. Route::get('admin','LoginController@admin');
  248. Route::get('normal','LoginController@normal');
  249.  
  250. @if( Session::get('tipoUsuario') == 'admin' )
  251. <h1>admin</h1>
  252. @else
  253. <h1>normal</h1>
  254. @endif
  255.  
  256. class MDusuarioadmin
  257. {
  258. /**
  259. * Handle an incoming request.
  260. *
  261. * @param IlluminateHttpRequest $request
  262. * @param Closure $next
  263. * @return mixed
  264. */
  265. public function handle($request, Closure $next)
  266. {
  267.  
  268. $usuario_actual=Auth::user();
  269. if($usuario_actual->tipoUsuario!=1){
  270. return view("mensajes.msj_rechazado")->with("msj","No tiene suficientes Privilegios para acceder a esta seccion");
  271. }
  272. return $next($request);
  273.  
  274. }
  275. }
  276.  
  277. class MDusuariostandard
  278. {
  279. /**
  280. * Handle an incoming request.
  281. *
  282. * @param IlluminateHttpRequest $request
  283. * @param Closure $next
  284. * @return mixed
  285. */
  286. public function handle($request, Closure $next)
  287. {
  288.  
  289. $usuario_actual=Auth::user();
  290. if($usuario_actual->tipoUsuario!=2){
  291. return view("mensajes.msj_rechazado")->with("msj","Esta seccion es solo visible para el usuario estandard <br/> usted aun no ha sido asignado como usuario standard , consulte al administrador del sistema");
  292. }
  293. return $next($request);
  294.  
  295. }
  296. }
  297.  
  298. //rutas accessibles slo si el usuario no se ha logueado
  299. Route::group(['middleware' => 'guest'], function () {
  300.  
  301. Route::get('login', 'AuthAuthController@getLogin');
  302. Route::post('login', ['as' =>'login', 'uses' => 'AuthAuthController@postLogin']);
  303. // Registration routes...
  304. Route::get('register', 'AuthAuthController@getRegister');
  305. Route::post('register', ['as' => 'auth/register', 'uses' => 'AuthAuthController@postRegister']);
  306.  
  307.  
  308. });
  309.  
  310. //rutas accessibles solo si el usuario esta autenticado y ha ingresado al sistema
  311. Route::group(['middleware' => 'auth'], function () {
  312.  
  313. //Route::get('/', 'HomeController@index');
  314. //Route::get('home', 'HomeController@index');
  315. Route::get('logout', ['as' => 'logout', 'uses' => 'AuthAuthController@getLogout']);
  316. //Route::get('listado_usuarios/{page?}', 'UsuariosController@listado_usuarios');
  317.  
  318. });
  319.  
  320. //rutas accessibles solo para el usuario administrador
  321. Route::group(['middleware' => 'usuarioAdmin'], function () {
  322.  
  323. Route::get('/worker/create', 'WorkerController@create');
  324. Route::post('/worker/store', 'WorkerController@store');
  325. Route::post('/worker/upload', ['as' => 'worker.upload', 'uses' => 'WorkerController@upload']);
  326. Route::get('/worker/show/{id_worker}', 'WorkerController@show');
  327. Route::get('/worker/edit/{id_worker}', 'WorkerController@edit');
  328. Route::post('/worker/update', 'WorkerController@update');
  329. Route::get('/worker/retirados', 'WorkerController@retirados');
  330. Route::post('/worker/remove', 'WorkerController@remove');
  331. Route::get('/worker/showall', 'WorkerController@showall');
  332.  
  333. Route::get('/area', 'AreaController@index');
  334. Route::get('/area/create', 'AreaController@create');
  335. Route::post('/area/store', 'AreaController@store');
  336.  
  337. Route::get('/vacation/create/{id_worker}/{name_worker}', 'VacationController@create');
  338. Route::post('/vacation/store', 'VacationController@store');
  339. Route::get('/vacation/calendar', 'VacationController@index');
  340. Route::get('/vacation/create', 'VacationController@index');
  341. Route::get('/vacation/request', 'VacationController@solicitudes');
  342. Route::get('/vacation/update', 'VacationController@update');
  343. });
  344. //rutas accessibles solo para el usuario standard
  345. Route::group(['middleware' => 'usuarioStandard'], function () {
  346.  
  347. Route::get('/vacation/create/{id_worker}/{name_worker}', 'VacationController@create');
  348. Route::post('/vacation/store', 'VacationController@store');
  349. Route::get('/vacation/calendar', 'VacationController@index');
  350. Route::get('/vacation/create', 'VacationController@index');
  351.  
  352. });
  353.  
  354. <?php
  355.  
  356. namespace AppHttpControllersAuth;
  357. use AppUser;
  358. use Validator;
  359. use AppHttpControllersController;
  360. use IlluminateFoundationAuthThrottlesLogins;
  361. use IlluminateFoundationAuthAuthenticatesAndRegistersUsers;
  362.  
  363. use IlluminateContractsAuthGuard;
  364. use IlluminateHttpRequest;
  365. use Session;
  366.  
  367. class AuthController extends Controller
  368. {
  369.  
  370.  
  371. use AuthenticatesAndRegistersUsers, ThrottlesLogins;
  372.  
  373. /*
  374. |--------------------------------------------------------------------------
  375. | Registration & Login Controller
  376. |--------------------------------------------------------------------------
  377. |
  378. | This controller handles the registration of new users, as well as the
  379. | authentication of existing users. By default, this controller uses
  380. | a simple trait to add these behaviors. Why don't you explore it?
  381. |
  382. */
  383.  
  384. protected $redirctTo ='/';
  385.  
  386. /**
  387. * Create a new authentication controller instance.
  388. *
  389. * @return void
  390. */
  391. public function __construct(Guard $auth)
  392. {
  393. $this->auth = $auth;
  394. $this->middleware('guest', ['except' => 'getLogout']);
  395. }
  396.  
  397. /**
  398. * Get a validator for an incoming registration request.
  399. *
  400. * @param array $data
  401. * @return IlluminateContractsValidationValidator
  402. */
  403.  
  404. //login
  405. protected function getLogin()
  406. {
  407. return view("login");
  408. }
  409.  
  410. public function postLogin(Request $request)
  411. {
  412. $this->validate($request, [
  413. 'email' => 'required',
  414. 'password' => 'required',
  415. ]);
  416. Session::put('tipoUsuario', 'admin');
  417. $credentials = $request->only('email', 'password');
  418.  
  419. if ($this->auth->attempt($credentials, $request->has('remember')))
  420. {
  421. $usuarioactual=Auth::user();
  422. return view('home')->with("usuario", $usuarioactual);
  423. }
  424.  
  425. return "credenciales incorrectas";
  426. }
  427.  
  428. //registro
  429. protected function getRegister()
  430. {
  431. return view("registro");
  432. }
  433.  
  434. protected function postRegister(Request $request)
  435. {
  436. $this->validate($request, [
  437. 'name' => 'required',
  438. 'email' => 'required',
  439. 'password' => 'required',
  440. ]);
  441.  
  442. $data = $request;
  443.  
  444. $user=new User;
  445. $user->name=$data['name'];
  446. $user->email=$data['email'];
  447. $user->password=bcrypt($data['password']);
  448.  
  449. if($user->save())
  450. {
  451. return "se ha registrado correctamente el usuario";
  452. }
  453. }
  454.  
  455. //registro
  456. protected function getLogout()
  457. {
  458. $this->auth->logout();
  459.  
  460. Session::flush();
  461.  
  462. return redirect('login');
  463. }
  464.  
  465.  
  466.  
  467. }
  468.  
  469. <?php
  470.  
  471. namespace AppHttpControllersAuth;
  472.  
  473. use AppHttpControllersController;
  474. use IlluminateFoundationAuthAuthenticatesUsers;
  475.  
  476. class LoginController extends Controller
  477. {
  478. use AuthenticatesUsers;
  479.  
  480. /* Ruta de redireccion por defecto */
  481. protected $redirectTo = '/home';
  482.  
  483. public function __construct()
  484. {
  485. $this->middleware('guest')->except('logout');
  486. }
  487.  
  488. /**
  489. *-----------------------------------------------------------------------
  490. * Creamos el método redirectTo()
  491. *-----------------------------------------------------------------------
  492. *
  493. * Esta función nos permite redirigir al iniciar sesión
  494. * en función de la lógica de nustra aplicación.
  495. *
  496. * La ruta retornada en retornada en este método redirectTo(),
  497. * prevalece sobre la propiedad $redirectTo declarada al principio.
  498. *
  499. * @return string
  500. *
  501. */
  502.  
  503. public function redirectTo()
  504. {
  505. if(Auth::user()->rol == 'admin')
  506. {
  507. return '/admin';
  508. } else {
  509. return '/home';
  510. }
  511. }
  512. }
  513.  
  514. public function redirectPath()
  515. {
  516. if(Auth::user()->rol == 'admin')
  517. {
  518. return '/admin';
  519. } else {
  520. return '/home';
  521. }
  522. }
Add Comment
Please, Sign In to add comment