updateAccountPassword method

  1. @override
Future<void> updateAccountPassword(
  1. String newPassword,
  2. String oldPassword
)
override

Implementation

@override
Future<void> updateAccountPassword(String newPassword, String oldPassword) async {
  logger.finest('updateAccountPassword($newPassword)');
  //
  if (newPassword.isEmpty || newPassword.isEmpty || newPassword == oldPassword) {
    // invalid password !!!
    logger.severe('invalid password !!!');
    throw HycopUtils.getHycopException(defaultMessage: 'invalid password !!!');
  }
  //
  String email = AccountManager.currentLoginUser.email;
  final getUserData = await HycopFactory.dataBase!
      .simpleQueryData('hycop_users', name: 'email', value: email, orderBy: 'name')
      .catchError((error, stackTrace) => throw HycopUtils.getHycopException(
          error: error, defaultMessage: 'not exist account(email:$email) !!!'));
  if (getUserData.isEmpty) {
    logger.finest('not exist account(email:$email) !!!');
    throw HycopException(message: 'not exist account(email:$email) !!!');
  }
  String oldPasswordSha1 = HycopUtils.stringToSha1(oldPassword);
  String newPasswordSha1 = HycopUtils.stringToSha1(newPassword);
  for (var result in getUserData) {
    String pwd = result['password'] ?? '';
    if (pwd != oldPasswordSha1) {
      logger.finest('different oldpassword (email:$oldPassword) !!!');
      throw HycopException(message: 'not exist account(email:$email) !!!');
    }
    break;
  }
  //
  Map<String, dynamic> newUserData = {};
  newUserData.addAll(AccountManager.currentLoginUser.getValueMap);
  newUserData['password'] = newPasswordSha1;
  if (AccountManager.currentLoginUser.hasGenPassword) {
    newUserData['userType'] = '';
  }
  String userId = AccountManager.currentLoginUser.userId;
  await HycopFactory.dataBase!.setData('hycop_users', 'user=$userId', newUserData).catchError(
      (error, stackTrace) =>
          throw HycopUtils.getHycopException(error: error, defaultMessage: 'setData Error !!!'));
}