confirmUser method

Future<void> confirmUser(
  1. String userName,
  2. String verifCode
)

Confirms a new user.

The username must be the email used to create the user. The verification code is sent to the email following the creation of the user. Throws BadVerificationException on a bad code.

Implementation

Future<void> confirmUser(String userName, String verifCode) async {
  assert(userName.isNotEmpty);
  assert(verifCode.isNotEmpty);

  final uri = _urlBase.getPath(_baseUserEndpoint);

  final body = await JsonIsolate().encodeJson({
    'user_name': userName,
    'verification_code': verifCode,
  });

  final resp = await post(uri, body: body);
  final Map<String, dynamic> bodyResp =
      await JsonIsolate().decodeJson(resp.body);
  if (resp.statusCode != 201) {
    if (bodyResp['error_code'] == 101002) {
      throw InvalidEmailException();
    }
    if (bodyResp['error_code'] == 101012) {
      throw BadVerificationException();
    }
    throw bodyResp['description'];
  }
}