kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add login Credentials data class
rodzic
b61b840e13
commit
ff1961555a
|
@ -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<Credentials, ExecError> 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}';
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue