loginByPhone method

Future<EasyPacket<void>> loginByPhone({
  1. required String phone,
  2. required String code,
  3. String? no,
  4. String? pwd,
})

使用phone和验证码code进行登录。分为三种场景:

  • 新账号注册:当no非null且pwd非null时,服务端会对phoneno的重复注册情况进行验证,然后注册新账号并登录。
  • 忘记了密码:当no为null但pwd非null时,服务端会对phone对应的账号的进行密码重置,然后登录。
  • 手机号登录:不满足上面两种情况时,直接使用phone对应的账号的进行登录,如果不存在phone对应的账号则创建一个新账号之后再登录。

Implementation

Future<EasyPacket<void>> loginByPhone({required String phone, required String code, String? no, String? pwd}) async {
  final response = await _guestClient.httpRequest('$host/loginByPhone', data: {'bsid': bsid, 'phone': phone, 'code': code, 'no': no, 'pwd': pwd});
  if (response.ok) {
    user.updateByJson(response.data!['user']);
    _resetAliveClient(response.data!['url'], response.data!['pwd']);
    onCredentials(ComTools.formatUserNick(user), encryptCredentials(user, secret));
  } else if (response.code == 401) {
    onCredentials(ComTools.formatUserNick(user), null);
  }
  return response;
}