<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Controllers\TaskController;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

use Illuminate\Support\Facades\Auth;


class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Create a new controller instance.
     *
     * @return void
     */

    public function __construct()
    {

        $this->middleware('guest', ['except' => 'logout']);

        

    }

    /**
     * Where to redirect users after login
     * @var string
     **/
//    protected $redirectTo = '/home/1';

    /**
     * si el usuario no es teamleader redirect a tareas creada,
     * de lo contrario redirect a panel de tareas
     * @return string
     */
    protected function redirectTo()
    {
        $user = Auth::user();

        if(!$user->isApplicant()){
            return '/tasks/uninitiated';
        }
        else{
            return '/home/1';
        }

    }



    /**
     * Log the user out of the application.
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {


        $this->guard()->logout();

        $request->session()->flush();

        $request->session()->regenerate();

        return redirect('/login');
    }


//
//    public function userAutenticate()
//    {
//
//        $this->validate($request, [
//            'email' => 'required',
//            'password' => 'required',
//        ]);
//
//
//    }






}

