diff --git a/lib/models/credentials.dart b/lib/models/credentials.dart new file mode 100644 index 0000000..6d847ce --- /dev/null +++ b/lib/models/credentials.dart @@ -0,0 +1,42 @@ +import 'package:flutter_portal/models/exec_error.dart'; +import 'package:result_monad/result_monad.dart'; + +class Credentials { + final String username; + final String password; + final String serverName; + + Credentials( + {required this.username, + required this.password, + required this.serverName}); + + Credentials copy({String? username, String? password, String? serverName}) { + return Credentials( + username: username ?? this.username, + password: password ?? this.password, + serverName: serverName ?? this.serverName); + } + + static Result buildFromHandle( + String handle, String password) { + final elements = handle.split('@'); + if (elements.length != 2) { + return Result.error(ExecError( + type: ErrorType.authentication, + message: 'Handle has invalid format: $handle')); + } + final result = Credentials( + username: elements[0], + password: password, + serverName: elements[1], + ); + print(result); + return Result.ok(result); + } + + @override + String toString() { + return 'Credentials{username: $username, password?: ${password.isNotEmpty}, serverName: $serverName}'; + } +}