Guest User

Untitled

a guest
Aug 27th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | None | 0 0
  1. namespace AppHttpControllersSuperAuthSuper;
  2.  
  3. use IlluminateHttpRequest;
  4. use AppHttpControllersController;
  5. use IlluminateSupportFacadesAuth;
  6.  
  7. class LoginController extends Controller
  8. {
  9.  
  10.  
  11. /**
  12. * Where to redirect users after login.
  13. *
  14. * @var string
  15. */
  16. //protected $redirectTo = '/home';
  17.  
  18. /**
  19. * Create a new controller instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct()
  24. {
  25. $this->middleware('guest:super')->except('logout');
  26. }
  27.  
  28. public function showIndex(){
  29. return view('caja.sucursal');
  30. }
  31.  
  32. public function login(Request $request)
  33. {
  34. $this->validate($request, [
  35. 'email' => 'required|email',
  36. 'password' => 'required|min:6'
  37. ]);
  38.  
  39. $credential = [
  40. 'email' => $request->email,
  41. 'password' => $request->password
  42. ];
  43.  
  44. // Attempt to log the user in
  45. if (guard()->attempt($credential)){
  46. // If login succesful, then redirect to their intended location
  47. return redirect()->intended(route('caja.home'));
  48. }
  49.  
  50. // If Unsuccessful, then redirect back to the login with the form
  51. data
  52. return redirect()->back()->withInput($request->only('email', 'remember'));
  53. }
  54.  
  55.  
  56. public function logout(){
  57. Auth::guard('super')->logout();
  58. return redirect('/sucursal')->with('flash','Se ha cerrado la Sesión');;
  59. }
  60.  
  61.  
  62.  
  63.  
  64. public function guard()
  65. {
  66. return Auth::guard('super');
  67. }
  68. }
  69.  
  70. 'guards' => [
  71. 'web' => [
  72. 'driver' => 'session',
  73. 'provider' => 'users',
  74. ],
  75.  
  76. 'api' => [
  77. 'driver' => 'token',
  78. 'provider' => 'users',
  79. ],
  80. 'super' => [
  81. 'driver' => 'session',
  82. 'provider' => 'supers',
  83. ],
  84.  
  85. 'api-super' => [
  86. 'driver' => 'token',
  87. 'provider' => 'supers',
  88. ],
  89. ],
  90.  
  91. 'providers' => [
  92. 'users' => [
  93. 'driver' => 'eloquent',
  94. 'model' => AppUser::class,
  95. ],
  96. 'supers' => [
  97. 'driver' => 'eloquent',
  98. 'model' => AppSuperuser::class,
  99. ],
  100.  
  101. // 'users' => [
  102. // 'driver' => 'database',
  103. // 'table' => 'users',
  104. // ],
  105. ],
  106.  
  107. 'passwords' => [
  108. 'users' => [
  109. 'provider' => 'users',
  110. 'table' => 'password_resets',
  111. 'expire' => 60,
  112. ],
  113. 'supers' => [
  114. 'provider' => 'supers',
  115. 'table' => 'password_resets',
  116. 'expire' => 60,
  117. ],
  118. ],
  119.  
  120. public function handle($request, Closure $next, $guard = null)
  121. {
  122. switch ($guard){
  123. case 'super':
  124. if (Auth::guard($guard)->check()) {
  125. return redirect()->route('caja.home');
  126. }
  127. break;
  128.  
  129. default:
  130. if (Auth::guard($guard)->check()) {
  131. return redirect()->route('home');
  132. }
  133. break;
  134. }
  135.  
  136. return $next($request);
  137. }
  138.  
  139. <?php
  140.  
  141. namespace AppExceptions;
  142.  
  143. use Exception;
  144. use IlluminateFoundationExceptionsHandler as ExceptionHandler;
  145. use Request;
  146. use Response;
  147. use IlluminateAuthAuthenticationException;
  148.  
  149. class Handler extends ExceptionHandler
  150. {
  151. /**
  152. * A list of the exception types that are not reported.
  153. *
  154. * @var array
  155. */
  156. protected $dontReport = [
  157. //
  158. ];
  159.  
  160. /**
  161. * A list of the inputs that are never flashed for validation exceptions.
  162. *
  163. * @var array
  164. */
  165. protected $dontFlash = [
  166. 'password',
  167. 'password_confirmation',
  168. ];
  169.  
  170. /**
  171. * Report or log an exception.
  172. *
  173. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  174. *
  175. * @param Exception $exception
  176. * @return void
  177. */
  178. public function report(Exception $exception)
  179. {
  180. parent::report($exception);
  181. }
  182.  
  183. /**
  184. * Render an exception into an HTTP response.
  185. *
  186. * @param IlluminateHttpRequest $request
  187. * @param Exception $exception
  188. * @return IlluminateHttpResponse
  189. */
  190. public function render($request, Exception $exception)
  191. {
  192. // if ($exception instanceof IlluminateAuthAuthenticationException){
  193. // return redirect('/')->with('flash','Por favor Inicia Sesión');
  194. // }
  195. return parent::render($request, $exception);
  196. }
  197.  
  198. protected function unauthenticated($request, AuthenticationException $exception)
  199. {
  200. // return $request->expectsJson()
  201. // ? response()->json(['message' => 'Unauthenticated.'], 401)
  202. // : redirect()->guest(route('login'));
  203.  
  204. if ($request->expectsJson()) {
  205. return response()->json(['error' => 'Unauthenticated.'], 401);
  206. }
  207.  
  208. $guard = array_get($exception->guards(), 0);
  209. switch ($guard) {
  210. case 'super':
  211. $login = 'caja.sucursal';
  212. break;
  213.  
  214. default:
  215. $login = '/';
  216. break;
  217. }
  218. return redirect()->guest(route($login))->with('flash','Por favor Inicia Sesión');
  219. }
  220. }
  221.  
  222. namespace AppHttpControllersSuperAuthSuper;
  223.  
  224. use IlluminateHttpRequest;
  225. use AppHttpControllersController;
  226. use IlluminateFoundationAuthSendsPasswordResetEmails;
  227. use IlluminateSupportFacadesPassword;
  228.  
  229. class ForgotPasswordController extends Controller
  230. {
  231.  
  232.  
  233. use SendsPasswordResetEmails;
  234.  
  235. /**
  236. * Create a new controller instance.
  237. *
  238. * @return void
  239. */
  240. public function __construct()
  241. {
  242. $this->middleware('guest:super');
  243. }
  244.  
  245. public function broker()
  246. {
  247. return Password::broker('supers');
  248. }
  249.  
  250.  
  251. /**
  252. * Display the form to request a password reset link.
  253. *
  254. * @return IlluminateHttpResponse
  255. */
  256. public function showLinkRequestForm()
  257. {
  258. return view('authSuper.passwords.email');
  259. }
  260.  
  261. /**
  262. * Send a reset link to the given user.
  263. *
  264. * @param IlluminateHttpRequest $request
  265. * @return IlluminateHttpRedirectResponse
  266. */
  267. public function sendResetLinkEmail(Request $request)
  268. {
  269. $this->validateEmail($request);
  270.  
  271. // We will send the password reset link to this user. Once we have attempted
  272. // to send the link, we will examine the response then see the message we
  273. // need to show to the user. Finally, we'll send out a proper response.
  274. $response = $this->broker()->sendResetLink(
  275. $request->only('email')
  276. );
  277.  
  278. return $response == Password::RESET_LINK_SENT
  279. ? $this->sendResetLinkResponse($response)
  280. : $this->sendResetLinkFailedResponse($request, $response);
  281. }
  282.  
  283.  
  284. }
  285.  
  286. namespace AppHttpControllersSuperAuthSuper;
  287.  
  288. use IlluminateHttpRequest;
  289. use AppHttpControllersController;
  290. use IlluminateFoundationAuthResetsPasswords;
  291. use IlluminateSupportFacadesPassword;
  292. use IlluminateSupportFacadesAuth;
  293.  
  294. class ResetPasswordController extends Controller
  295. {
  296.  
  297. use ResetsPasswords;
  298.  
  299. /**
  300. * Where to redirect users after resetting their password.
  301. *
  302. * @var string
  303. */
  304. protected $redirectTo = '/sucursal';
  305.  
  306. /**
  307. * Create a new controller instance.
  308. *
  309. * @return void
  310. */
  311. public function __construct()
  312. {
  313. $this->middleware('guest:super');
  314. }
  315.  
  316. public function guard()
  317. {
  318. return Auth::guard('super');
  319. }
  320.  
  321. public function broker()
  322. {
  323. return Password::broker('supers');
  324. }
  325.  
  326. /**
  327. * Display the password reset view for the given token.
  328. *
  329. * If no token is present, display the link request form.
  330. *
  331. * @param IlluminateHttpRequest $request
  332. * @param string|null $token
  333. * @return IlluminateContractsViewFactory|IlluminateViewView
  334. */
  335. public function showResetForm(Request $request, $token = null)
  336. {
  337. return view('authSuper.passwords.reset')->with(
  338. ['token' => $token, 'email' => $request->email]
  339. );
  340. }
  341. }
  342.  
  343. <form role="form" action="{{ route('caja.login')}}" method="POST">
  344. {{ csrf_field() }}
  345. <div class="form-group {{ $errors->has('rut') ? 'has-error':''}}">
  346. <label class="sr-only" for="r-form-1-name">RUT</label>
  347. <input type="text" name="rut" placeholder="Rut..." class="r-form-1-name form-control" id="r-form-1-name" value="{{ old('rut')}}">
  348. {!! $errors->first('rut','<span class="help-block">:message</span>') !!}
  349. </div>
  350. <div class="form-group {{ $errors->has('password') ? 'has-error':''}}">
  351. <label class="sr-only" for="r-form-1-email">CONTRASEÑA</label>
  352. <input type="password" name="password" placeholder="Contraseña..." class="r-form-1-email form-control" id="r-form-1-email">
  353. {!! $errors->first('password','<span class="help-block">:message</span>') !!}
  354. </div>
  355.  
  356. <p class="terms">
  357. * Olvidaste la Contraseña?
  358. <!--<a href="#" class="launch-modal"
  359. data-modal-id="modal-terms">Presiona aquí</a>-->
  360. <a href="{{
  361. route('caja.password.resetter') }}">Presiona aquí</a>
  362. </p>
  363. <center>
  364. <a class="btn" href="
  365. {{route('caja.home')}}">ENTRAR</a>
  366. </center>
  367.  
  368. </form>
  369.  
  370. Route::prefix('sucursal')->group(function(){
  371. Route::get('/', 'SuperAuthSuperLoginController@showIndex')->name('caja.sucursal');
  372. Route::get('/home','SuperCajaController@home')->name('caja.home');
  373. Route::post('/login', 'SuperAuthSuperLoginController@login')->name('caja.login');
  374. Route::post('/logout', 'SuperAuthSuperLoginController@logout')->name('caja.logout');
  375. Route::get('/password/reset', 'SuperAuthSuperForgotPasswordController@showLinkRequestForm')->name('caja.password.resetter');
  376. Route::post('/password/email', 'SuperAuthSuperForgotPasswordController@sendResetLinkEmail')->name('caja.password.email');
  377. Route::get('/password/reset/{token}', 'SuperAuthSuperResetPasswordController@showResetForm')->name('caja.password.reset');
  378. Route::post('/password/request', 'SuperAuthSuperResetPasswordController@reset')->name('caja.password.request');
  379. Route::post('buscar-rut', 'SuperCajaController@buscarRut');
  380. });
Add Comment
Please, Sign In to add comment