<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Auth;
class AccessController extends Controller
{
    public function adminLogin(Request $request)
    { 
          try{
            $data = $request->all();
            if(Auth::attempt(['email'=> $data['email'], 'password'=>$data['password']])){
                
                $notification=array(
                         'messege'=>'Successfully Logged In',
                         'alert-type'=>'success'
                        );
                    return redirect('/dashboard')->with($notification);

            }else{
                $notification=array(
                         'messege'=>'Email Or Password Invalid',
                         'alert-type'=>'error'
                        );
                    return redirect()->back()->with($notification);
            }
          }catch(Exception $e){
                  
                $message = $e->getMessage();
      
                $code = $e->getCode();       
      
                $string = $e->__toString();       
                return response()->json(['message'=>$message, 'execption_code'=>$code, 'execption_string'=>$string]);
                exit;
            } 
    }

    public function logout()
    {  
       try{
            Auth::logout();
            $notification=array(
                         'messege'=>'Successfully Logged out',
                         'alert-type'=>'success'
                        );
            return redirect('/')->with($notification);
       }catch(Exception $e){
                  
                $message = $e->getMessage();
      
                $code = $e->getCode();       
      
                $string = $e->__toString();       
                return response()->json(['message'=>$message, 'execption_code'=>$code, 'execption_string'=>$string]);
                exit;
        }
        
    }
}
