<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\adminapi\controller\auth;

use app\adminapi\controller\BaseAdminController;
use app\service\admin\auth\AuthService;
use think\Request;


/**
 * 后台认证控制器
 * 管理员登录、登出、个人资料、修改密码
 * @package app\adminapi\controller\auth
 */
class Auth extends BaseAdminController
{
    /**
     * 管理员登录
     * @param Request $request
     * @return \think\response\Json
     */
    public function login(Request $request)
    {
        return json($this->app->make(AuthService::class)->login($request));
    }

    /**
     * 管理员登出
     * @param Request $request
     * @return \think\response\Json
     */
    public function logout(Request $request)
    {
        return json($this->app->make(AuthService::class)->logout($request));
    }

    /**
     * 管理员个人资料
     * @param Request $request
     * @return \think\response\Json
     */
    public function profile(Request $request)
    {
        $result = $this->app->make(AuthService::class)->profile($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }

    /**
     * 管理员修改密码
     * @param Request $request
     * @return \think\response\Json
     */
    public function changePassword(Request $request)
    {
        $result = $this->app->make(AuthService::class)->changePassword($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }
}
