feat: change password
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@@ -47,4 +48,36 @@ class UserRemoteDataProvider {
|
||||
return DC.error(UserFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<UserFailure, Unit>> changePassword({
|
||||
required String newPassword,
|
||||
required String currentPassword,
|
||||
required String userId,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'${ApiPath.user}/$userId/password',
|
||||
data: {
|
||||
'new_password': newPassword,
|
||||
'current_password': currentPassword,
|
||||
},
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.statusCode == 400) {
|
||||
return DC.error(UserFailure.unexpectedError());
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return DC.error(
|
||||
UserFailure.dynamicErrorMessage(response.data['error']),
|
||||
);
|
||||
}
|
||||
|
||||
return DC.data(unit);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('changePassword', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(UserFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user