<?php

namespace App\Http\Controllers\Manage\Manage;

use App\Http\Controllers\Controller;
use App\Modules\Manage\Services\ManageService;
use Illuminate\Http\Request;
use Cache;

class AuthController extends Controller
{
    /**
     * @apiDefine Manage 管理
     */


     /**
     * @apiVersion 1.0.0
     * @apiDescription 管理后台登陆
     * @api {POST} auth/login 管理后台登陆
     * @apiGroup Manage
     * @apiName login
     * @apiParam {String}  accout 账号.
     * @apiParam {String}  password 密码.
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *         "code": 0,
     *         "msg": "",
     *         "data": {}
     *     }
     */
    function login(Request $request)
    {
        $account = $request->has('account') ? trim($request->input('account')) : '';
        $password = $request->has('password') ? trim($request->input('password')) : '';
//         var_dump('$password:'.$password.' $account:'.$account);die();

        if(!$account || !$password) return response()->error('PARAM_ERROR');

        $manage = ManageService::getByAccount($account);
//         var_dump($manage);

        if($manage && $manage->password == md5($password."^-^zhuishuyun^_^"))
        {
            if($manage->is_enabled == 0) return response()->error('MANAGE_NOT_ENABLED');
            $request->session()->put('manage_auth', $manage->id);
            $request->session()->put('manage_user', serialize($manage));
            
            $options = [];
            $options =[
            	'role'=>$manage->role
            ];

//             $options = json_encode($options);
            
            return response()->success(compact('options'));
        }

        return response()->error('LOGIN_VERIFY_ERROR');
    }


}