login method

  1. @Deprecated('Use [loginWithToken or loginWithPassword] instead')
Future<void> login(
  1. String userId,
  2. String pwdOrToken, [
  3. bool isPassword = true
])

~english Logs in to the chat server with a password or token.

Param userId The user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^a-zA-Z0-9_-+$.

Param pwdOrToken The password or token.

Param isPassword Whether to log in with a password or a token. (Default) true: A password is used. false: A token is used.

Throws A description of the exception. See EMError. ~end

~chinese 使用密码或 Token 登录服务器。

Param userId 用户 ID,长度不超过 64 个字符。请确保你对该参数设值。 支持的字符包括英文字母(a-z),数字(0-9),下划线(_),英文横线(-),英文句号(.)。 该参数不区分大小写,大写字母会被自动转为小写字母。如果使用正则表达式设置该参数,则可以将表达式写为:^a-zA-Z0-9_-+$。

Param pwdOrToken 登录密码或 Token。

Param isPassword 是否用密码登录。

  • (默认)true:是。
  • false:否。

Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError。 ~end

Implementation

@Deprecated('Use [loginWithToken or loginWithPassword] instead')

/// ~english
/// Logs in to the chat server with a password or token.
///
/// Param [userId] The user ID. The maximum length is 64 characters. Ensure that you set this parameter.
/// Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.).
/// This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones.
/// If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
///
/// Param [pwdOrToken] The password or token.
///
/// Param [isPassword] Whether to log in with a password or a token.
/// (Default) `true`: A password is used.
/// `false`: A token is used.
///
/// **Throws** A description of the exception. See [EMError].
/// ~end
///
/// ~chinese
/// 使用密码或 Token 登录服务器。
///
/// Param [userId] 用户 ID,长度不超过 64 个字符。请确保你对该参数设值。
/// 支持的字符包括英文字母(a-z),数字(0-9),下划线(_),英文横线(-),英文句号(.)。
/// 该参数不区分大小写,大写字母会被自动转为小写字母。如果使用正则表达式设置该参数,则可以将表达式写为:^[a-zA-Z0-9_-]+$。
///
/// Param [pwdOrToken] 登录密码或 Token。
///
/// Param [isPassword] 是否用密码登录。
/// - (默认)`true`:是。
/// - `false`:否。
///
/// **Throws**  如果有异常会在这里抛出,包含错误码和错误描述,详见 [EMError]。
/// ~end
Future<void> login(
  String userId,
  String pwdOrToken, [
  bool isPassword = true,
]) async {
  EMLog.v('login: $userId : $pwdOrToken, isPassword: $isPassword');
  Map req = {
    'username': userId,
    'pwdOrToken': pwdOrToken,
    'isPassword': isPassword
  };
  Map result = await ClientChannel.invokeMethod(ChatMethodKeys.login, req);
  try {
    EMError.hasErrorFromResult(result);
    _currentUserId = userId;
  } on EMError catch (e) {
    throw e;
  }
}