Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace AppHttpControllersSuperAuthSuper;
- use IlluminateHttpRequest;
- use AppHttpControllersController;
- use IlluminateSupportFacadesAuth;
- class LoginController extends Controller
- {
- /**
- * Where to redirect users after login.
- *
- * @var string
- */
- //protected $redirectTo = '/home';
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('guest:super')->except('logout');
- }
- public function showIndex(){
- return view('caja.sucursal');
- }
- public function login(Request $request)
- {
- $this->validate($request, [
- 'email' => 'required|email',
- 'password' => 'required|min:6'
- ]);
- $credential = [
- 'email' => $request->email,
- 'password' => $request->password
- ];
- // Attempt to log the user in
- if (guard()->attempt($credential)){
- // If login succesful, then redirect to their intended location
- return redirect()->intended(route('caja.home'));
- }
- // If Unsuccessful, then redirect back to the login with the form
- data
- return redirect()->back()->withInput($request->only('email', 'remember'));
- }
- public function logout(){
- Auth::guard('super')->logout();
- return redirect('/sucursal')->with('flash','Se ha cerrado la Sesión');;
- }
- public function guard()
- {
- return Auth::guard('super');
- }
- }
- 'guards' => [
- 'web' => [
- 'driver' => 'session',
- 'provider' => 'users',
- ],
- 'api' => [
- 'driver' => 'token',
- 'provider' => 'users',
- ],
- 'super' => [
- 'driver' => 'session',
- 'provider' => 'supers',
- ],
- 'api-super' => [
- 'driver' => 'token',
- 'provider' => 'supers',
- ],
- ],
- 'providers' => [
- 'users' => [
- 'driver' => 'eloquent',
- 'model' => AppUser::class,
- ],
- 'supers' => [
- 'driver' => 'eloquent',
- 'model' => AppSuperuser::class,
- ],
- // 'users' => [
- // 'driver' => 'database',
- // 'table' => 'users',
- // ],
- ],
- 'passwords' => [
- 'users' => [
- 'provider' => 'users',
- 'table' => 'password_resets',
- 'expire' => 60,
- ],
- 'supers' => [
- 'provider' => 'supers',
- 'table' => 'password_resets',
- 'expire' => 60,
- ],
- ],
- public function handle($request, Closure $next, $guard = null)
- {
- switch ($guard){
- case 'super':
- if (Auth::guard($guard)->check()) {
- return redirect()->route('caja.home');
- }
- break;
- default:
- if (Auth::guard($guard)->check()) {
- return redirect()->route('home');
- }
- break;
- }
- return $next($request);
- }
- <?php
- namespace AppExceptions;
- use Exception;
- use IlluminateFoundationExceptionsHandler as ExceptionHandler;
- use Request;
- use Response;
- use IlluminateAuthAuthenticationException;
- class Handler extends ExceptionHandler
- {
- /**
- * A list of the exception types that are not reported.
- *
- * @var array
- */
- protected $dontReport = [
- //
- ];
- /**
- * A list of the inputs that are never flashed for validation exceptions.
- *
- * @var array
- */
- protected $dontFlash = [
- 'password',
- 'password_confirmation',
- ];
- /**
- * Report or log an exception.
- *
- * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
- *
- * @param Exception $exception
- * @return void
- */
- public function report(Exception $exception)
- {
- parent::report($exception);
- }
- /**
- * Render an exception into an HTTP response.
- *
- * @param IlluminateHttpRequest $request
- * @param Exception $exception
- * @return IlluminateHttpResponse
- */
- public function render($request, Exception $exception)
- {
- // if ($exception instanceof IlluminateAuthAuthenticationException){
- // return redirect('/')->with('flash','Por favor Inicia Sesión');
- // }
- return parent::render($request, $exception);
- }
- protected function unauthenticated($request, AuthenticationException $exception)
- {
- // return $request->expectsJson()
- // ? response()->json(['message' => 'Unauthenticated.'], 401)
- // : redirect()->guest(route('login'));
- if ($request->expectsJson()) {
- return response()->json(['error' => 'Unauthenticated.'], 401);
- }
- $guard = array_get($exception->guards(), 0);
- switch ($guard) {
- case 'super':
- $login = 'caja.sucursal';
- break;
- default:
- $login = '/';
- break;
- }
- return redirect()->guest(route($login))->with('flash','Por favor Inicia Sesión');
- }
- }
- namespace AppHttpControllersSuperAuthSuper;
- use IlluminateHttpRequest;
- use AppHttpControllersController;
- use IlluminateFoundationAuthSendsPasswordResetEmails;
- use IlluminateSupportFacadesPassword;
- class ForgotPasswordController extends Controller
- {
- use SendsPasswordResetEmails;
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('guest:super');
- }
- public function broker()
- {
- return Password::broker('supers');
- }
- /**
- * Display the form to request a password reset link.
- *
- * @return IlluminateHttpResponse
- */
- public function showLinkRequestForm()
- {
- return view('authSuper.passwords.email');
- }
- /**
- * Send a reset link to the given user.
- *
- * @param IlluminateHttpRequest $request
- * @return IlluminateHttpRedirectResponse
- */
- public function sendResetLinkEmail(Request $request)
- {
- $this->validateEmail($request);
- // We will send the password reset link to this user. Once we have attempted
- // to send the link, we will examine the response then see the message we
- // need to show to the user. Finally, we'll send out a proper response.
- $response = $this->broker()->sendResetLink(
- $request->only('email')
- );
- return $response == Password::RESET_LINK_SENT
- ? $this->sendResetLinkResponse($response)
- : $this->sendResetLinkFailedResponse($request, $response);
- }
- }
- namespace AppHttpControllersSuperAuthSuper;
- use IlluminateHttpRequest;
- use AppHttpControllersController;
- use IlluminateFoundationAuthResetsPasswords;
- use IlluminateSupportFacadesPassword;
- use IlluminateSupportFacadesAuth;
- class ResetPasswordController extends Controller
- {
- use ResetsPasswords;
- /**
- * Where to redirect users after resetting their password.
- *
- * @var string
- */
- protected $redirectTo = '/sucursal';
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('guest:super');
- }
- public function guard()
- {
- return Auth::guard('super');
- }
- public function broker()
- {
- return Password::broker('supers');
- }
- /**
- * Display the password reset view for the given token.
- *
- * If no token is present, display the link request form.
- *
- * @param IlluminateHttpRequest $request
- * @param string|null $token
- * @return IlluminateContractsViewFactory|IlluminateViewView
- */
- public function showResetForm(Request $request, $token = null)
- {
- return view('authSuper.passwords.reset')->with(
- ['token' => $token, 'email' => $request->email]
- );
- }
- }
- <form role="form" action="{{ route('caja.login')}}" method="POST">
- {{ csrf_field() }}
- <div class="form-group {{ $errors->has('rut') ? 'has-error':''}}">
- <label class="sr-only" for="r-form-1-name">RUT</label>
- <input type="text" name="rut" placeholder="Rut..." class="r-form-1-name form-control" id="r-form-1-name" value="{{ old('rut')}}">
- {!! $errors->first('rut','<span class="help-block">:message</span>') !!}
- </div>
- <div class="form-group {{ $errors->has('password') ? 'has-error':''}}">
- <label class="sr-only" for="r-form-1-email">CONTRASEÑA</label>
- <input type="password" name="password" placeholder="Contraseña..." class="r-form-1-email form-control" id="r-form-1-email">
- {!! $errors->first('password','<span class="help-block">:message</span>') !!}
- </div>
- <p class="terms">
- * Olvidaste la Contraseña?
- <!--<a href="#" class="launch-modal"
- data-modal-id="modal-terms">Presiona aquí</a>-->
- <a href="{{
- route('caja.password.resetter') }}">Presiona aquí</a>
- </p>
- <center>
- <a class="btn" href="
- {{route('caja.home')}}">ENTRAR</a>
- </center>
- </form>
- Route::prefix('sucursal')->group(function(){
- Route::get('/', 'SuperAuthSuperLoginController@showIndex')->name('caja.sucursal');
- Route::get('/home','SuperCajaController@home')->name('caja.home');
- Route::post('/login', 'SuperAuthSuperLoginController@login')->name('caja.login');
- Route::post('/logout', 'SuperAuthSuperLoginController@logout')->name('caja.logout');
- Route::get('/password/reset', 'SuperAuthSuperForgotPasswordController@showLinkRequestForm')->name('caja.password.resetter');
- Route::post('/password/email', 'SuperAuthSuperForgotPasswordController@sendResetLinkEmail')->name('caja.password.email');
- Route::get('/password/reset/{token}', 'SuperAuthSuperResetPasswordController@showResetForm')->name('caja.password.reset');
- Route::post('/password/request', 'SuperAuthSuperResetPasswordController@reset')->name('caja.password.request');
- Route::post('buscar-rut', 'SuperCajaController@buscarRut');
- });
Add Comment
Please, Sign In to add comment