login static method

Future<Result> login(
  1. String remoteId,
  2. String account,
  3. String password
)

Implementation

static Future<Result<dynamic>> login(
    String remoteId,
    String account,
    String password,
    ) async {
  // 设置 NetworkConfig 的 id
  NetworkConfig.setRemoteId(remoteId);
  var result = await post(
    // apiPath: "/api/v1/device-connections",
    // apiPath: "/api/v1/devices/connect",
    apiPath: "/api/user/v1.0/login.cgi",
    bodyParams: {
      // "aomucId": remoteId,
      "username": account,
      "password": password,
    },
  );
  if (result.isSuccess) {
    final data = (result.data as Map<String, dynamic>?)?["data"];
    DeviceRequestManager.saveToken(
      data?["access-token"] ?? "",
      data?["refresh-token"] ?? "",
    );
    DeviceRequestManager.saveP2PToken(data?["p2pToken"] ?? "");
    NasDeviceConfig.setCurrentNasInfo(
      NASDeviceInfo(
        serviceName: data?["name"] ?? "",
        serviceType: "Nas",
        sn: data?["serialNumber"] ?? data?["sn"] ?? "",
        port: data?["port"] ?? 0,
        ipAddress: data?["ipAddress"] ?? "",
        remoteId: data?["aomucId"] ?? "",
        txtRecords: {},
      ),
    );
  }
  return result;
}