<?php
/**
 * 登录和退出登录入口
 * User: Titan 名字就是密码
 * Date: 2019/6/4
 * Time: 17:11
 */

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;

class Base extends Controller
{
    public function index()
    {
        echo "test";
    }
    public function login()
    {

            $data = input();
            $username = $data['username'];               //获取到的 用户名
            $password = md5($data['password']);          //获取到的 加密后的密码
            $ip = $_SERVER['REMOTE_ADDR'];
            $userModel = model('User');
            $data = $userModel->login($username,$password,$ip);
            if(!$data){
                return resultArray(['error'=>$userModel->getError()]);
            }else{
                return resultArray(['data'=>$data]);
            }

    }

    public function logout(Request $request)
    {

        $header = Request::instance()->header();
        $data = input(); //获取信息(登录状态为0,ip置为空)
        $data['ip'] = '';
        $data['error_num'] = 0;
        $authKey = $header['authkey'];
        $result = Db::name('admin')->where(['id'=>1])->update($data);
        cache('Auth_'.$authKey, null);
        return json(['code'=>'00','msg'=>'更新数据成功']);
    }
}