<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Request;
use Session;
use DB;

class LoginController extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
	function CheckLogin(){
		Request::validate([
			"user" => "required","pwd" => "required"
		]);
		$u = Request::get("user");
		$p = Request::get("pwd");
		 
		
		$data = DB::table("user")
		->where("username",$u)
		->where("password",$p)
		->count();
				
		if ($data > 0){
			Session::put("username", $u);
			$data = DB::table("user")
			->where("username",$u)
			->where("password",$p)
			->first();
			Session::put("userlevel", $data->userlevel);
			return redirect("/about");
		}
		else{
			Session::forget("username");
			return redirect("/pagelogin");
		}
	}
	
}
