mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can sign in user
This commit is contained in:
		
							
								
								
									
										27
									
								
								lib/models/api_request.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								lib/models/api_request.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
import 'package:meta/meta.dart';
 | 
			
		||||
 | 
			
		||||
/// API Request model
 | 
			
		||||
///
 | 
			
		||||
/// Contains all the information associated to an API request
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class APIRequest {
 | 
			
		||||
  final String uri;
 | 
			
		||||
  final bool needLogin;
 | 
			
		||||
  Map<String, String> args;
 | 
			
		||||
 | 
			
		||||
  APIRequest({
 | 
			
		||||
    @required this.uri,
 | 
			
		||||
    this.needLogin = false,
 | 
			
		||||
  })  : assert(uri != null),
 | 
			
		||||
        assert(needLogin != null),
 | 
			
		||||
        args = Map();
 | 
			
		||||
 | 
			
		||||
  void addString(String name, String value) => args[name] = value;
 | 
			
		||||
 | 
			
		||||
  void addInt(String name, int value) => args[name] = value.toString();
 | 
			
		||||
 | 
			
		||||
  void addBool(String name, bool value) =>
 | 
			
		||||
      args[name] = value ? "true" : "false";
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								lib/models/api_response.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								lib/models/api_response.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
import 'dart:convert';
 | 
			
		||||
 | 
			
		||||
/// API response
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class APIResponse {
 | 
			
		||||
  final int code;
 | 
			
		||||
  final String content;
 | 
			
		||||
 | 
			
		||||
  const APIResponse(this.code, this.content) : assert(code != null);
 | 
			
		||||
 | 
			
		||||
  List<dynamic> getArray() => jsonDecode(this.content);
 | 
			
		||||
 | 
			
		||||
  Map<String, dynamic> getObject() => jsonDecode(this.content);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								lib/models/authentication_details.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								lib/models/authentication_details.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
import 'package:meta/meta.dart';
 | 
			
		||||
 | 
			
		||||
/// Authentication details
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class AuthenticationDetails {
 | 
			
		||||
  final String email;
 | 
			
		||||
  final String password;
 | 
			
		||||
 | 
			
		||||
  const AuthenticationDetails({@required this.email, @required this.password})
 | 
			
		||||
      : assert(email != null),
 | 
			
		||||
        assert(password != null);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								lib/models/config.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								lib/models/config.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
import 'package:meta/meta.dart';
 | 
			
		||||
 | 
			
		||||
/// Application configuration model
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
/// Configuration class
 | 
			
		||||
class Config {
 | 
			
		||||
  final String apiServerName;
 | 
			
		||||
  final String apiServerUri;
 | 
			
		||||
  final bool apiServerSecure;
 | 
			
		||||
  final String serviceName;
 | 
			
		||||
  final String serviceToken;
 | 
			
		||||
 | 
			
		||||
  const Config(
 | 
			
		||||
      {@required this.apiServerName,
 | 
			
		||||
      @required this.apiServerUri,
 | 
			
		||||
      @required this.apiServerSecure,
 | 
			
		||||
      @required this.serviceName,
 | 
			
		||||
      @required this.serviceToken})
 | 
			
		||||
      : assert(apiServerName != null),
 | 
			
		||||
        assert(apiServerUri != null),
 | 
			
		||||
        assert(apiServerSecure != null),
 | 
			
		||||
        assert(serviceName != null),
 | 
			
		||||
        assert(serviceToken != null);
 | 
			
		||||
 | 
			
		||||
  /// Get and set static configuration
 | 
			
		||||
  static Config _config;
 | 
			
		||||
 | 
			
		||||
  static Config get() {
 | 
			
		||||
    return _config;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static void set(Config conf) {
 | 
			
		||||
    _config = conf;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get the current configuration of the application
 | 
			
		||||
Config config() {
 | 
			
		||||
  return Config.get();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								lib/models/login_tokens.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								lib/models/login_tokens.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
import 'dart:convert';
 | 
			
		||||
 | 
			
		||||
/// Login tokens model
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class LoginTokens {
 | 
			
		||||
  final String tokenOne;
 | 
			
		||||
  final String tokenTwo;
 | 
			
		||||
 | 
			
		||||
  const LoginTokens(this.tokenOne, this.tokenTwo)
 | 
			
		||||
      : assert(tokenOne != null),
 | 
			
		||||
        assert(tokenTwo != null);
 | 
			
		||||
 | 
			
		||||
  LoginTokens.fromJSON(Map<String, dynamic> json)
 | 
			
		||||
      : tokenOne = json["token_one"],
 | 
			
		||||
        tokenTwo = json["token_two"];
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  String toString() {
 | 
			
		||||
    return jsonEncode({"token_one": tokenOne, "token_two": tokenTwo});
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user