89 lines
2.1 KiB
Dart
89 lines
2.1 KiB
Dart
import 'package:grpc/grpc_web.dart';
|
|
import 'package:softplayer_dart_proto/main.dart';
|
|
|
|
class AccountLocalData {
|
|
AccountLocalData({
|
|
required this.uuid,
|
|
required this.token,
|
|
});
|
|
String uuid;
|
|
String token;
|
|
}
|
|
|
|
class AccountsGrpc {
|
|
final GrpcWebClientChannel channel;
|
|
late AccountsClient accountsStub;
|
|
AccountsGrpc({
|
|
required this.channel,
|
|
});
|
|
|
|
void init() {
|
|
accountsStub = AccountsClient(channel);
|
|
}
|
|
|
|
Future<AccountLocalData> signIn(
|
|
String username, String email, String password) async {
|
|
final request = AccountWithPassword(
|
|
data: AccountData(
|
|
name: username,
|
|
email: email,
|
|
),
|
|
password: AccountPassword(
|
|
password: password,
|
|
));
|
|
try {
|
|
final response = await accountsStub.signIn(request);
|
|
return AccountLocalData(uuid: response.id.id, token: response.token);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<AccountLocalData> signUp(
|
|
String username, String email, String password) async {
|
|
final request = AccountWithPassword(
|
|
data: AccountData(
|
|
name: username,
|
|
email: email,
|
|
),
|
|
password: AccountPassword(
|
|
password: password,
|
|
));
|
|
try {
|
|
final response = await accountsStub.signUp(request);
|
|
return AccountLocalData(uuid: response.id.id, token: response.token);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<Empty> resetPassword(String username, String email) async {
|
|
final request = AccountData(
|
|
name: username,
|
|
email: email,
|
|
);
|
|
try {
|
|
final response = await accountsStub.resetPassword(request);
|
|
return response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<Empty> newPassword(
|
|
String username, String code, String newPassword) async {
|
|
final request = AccountWithPasswordAndCode(
|
|
data: AccountData(
|
|
name: username,
|
|
),
|
|
code: code,
|
|
password: AccountPassword(password: newPassword));
|
|
try {
|
|
final response = await accountsStub.newPassword(request);
|
|
return response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|