public function handleLogin(array $request = [])
    {
        $validator = new \Valitron\Validator($request);
        $validator->rule('required', ['username', 'password']);
        $validator->rule(function ($field, $value, array $params, array $fields) {
            return is_string($value);
        }, ['username', 'password'])->message("Invalid username or password");
        $validator->rule('lengthBetween', 'username', 6, 200);
        $validator->rule('lengthBetween', 'password', 8, 80);
        if ($validator->validate() === false) {
            if (headers_sent() === false) {
                header('X-PHP-Response-Code: 422', true, 422);
            }
            return $this->templates->render("Auth::Login", [
                "messages" => [
                    'error' => 'Incorrect username and/or password',
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "username" => $request['username']
            ]);
        }

        $response = $this->core->api('User/login/' . $request['username'], 'POST')->run($request);
        if (headers_sent() === false) {
            foreach ($response["headers"] as $header) {
                header($header[0], $header[1], $header[2]);
            }
        }
        if ($response["headers"][0][2] === 422) {
            return $this->templates->render("Auth::Login", [
                "messages" => [
                    'error' => 'Incorrect username and/or password',
                    'info' => '',
                    'success' => '',
                    'warning' => ''
                ],
                "username" => $request['username']
            ]);
        } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
            $this->core->auth()->validate($response["response"]);
            $_SERVER['REQUEST_URI'] = 'GET';
            $this->router->map('GET', '/', "User@showProfile", 'home-page');
            return $this->redirect();
        } else {
            return $this->templates->render("500", [
                "error" => $response['response'],
                "result" => ''
            ]);
        }
    }