<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

/**
 *
 */
class LoginController extends Controller {

    function _init(){

    }

    function aa() {
        $zqRuleModel = new \App\Lib\Settlement\SettlementOrder;
        $zqRuleModel -> ChuanOrder('20190507134301713489765');
    }

	function index(Request $req) {
		if ($req->isMethod('post')) {
			$user = new \App\Models\System_user;
			$str = $user->adminLogin($_POST['account'], $_POST['password']);
			if($str>0){
                $token=refreshToken($str['admin_id']);
                $str['token']=$token;
				$req->session()->put('adminInfo',$str);
				$str=1;
			}
			$log = array(
            	session('adminInfo.admin_name'),
            	$_POST['account']
	        );
	        OperationLog(session('adminInfo.admin_id'), 'login', $log);
			return responseToJson($str);
		}

		return view('admin.login/index');
	}

	function logout(Request $req){
		$log = array(
	    	session('adminInfo.admin_name'),
	    );
	    OperationLog(session('adminInfo.admin_id'), 'logout', $log);
		$req->session()->flush();
        $req->session()->regenerate();
		// header('location:/admin/login/index');
		 return view('admin.login/index');
	}

	function Errors(){
        return view('admin.login/error');
    }

}