<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use Auth;
use Validator;
use Redirect; 

class LoginController extends Controller
{
    
    public function authenticate(Request $request) {
        $post 	=	$request->all();
		$email = $post['email'];
        $password = $post['password'];
        
        if (Auth::attempt(['email' => $email, 'password' => $password])) {
        
           // Authentication passed...
           if (Auth::user()->role == 'admin') {
                // return $next($request);
                return redirect()->intended('admin');
            }
            return redirect('/logout');
            
           
        }else{
            return Redirect::back()->withErrors(array(
                'error'=>'Invalid Email Address or Password'
            ));
        }
    }
}
