mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Create account form is working
This commit is contained in:
		@@ -3,6 +3,7 @@ import 'package:comunic/helpers/preferences_helper.dart';
 | 
			
		||||
import 'package:comunic/models/api_request.dart';
 | 
			
		||||
import 'package:comunic/models/authentication_details.dart';
 | 
			
		||||
import 'package:comunic/models/login_tokens.dart';
 | 
			
		||||
import 'package:comunic/models/new_account.dart';
 | 
			
		||||
import 'package:shared_preferences/shared_preferences.dart';
 | 
			
		||||
 | 
			
		||||
/// Account helper
 | 
			
		||||
@@ -16,6 +17,13 @@ enum AuthResult {
 | 
			
		||||
  INVALID_CREDENTIALS
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum CreateAccountResult {
 | 
			
		||||
  SUCCESS,
 | 
			
		||||
  ERROR_TOO_MANY_REQUESTS,
 | 
			
		||||
  ERROR_EXISTING_EMAIL,
 | 
			
		||||
  ERROR
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class AccountHelper {
 | 
			
		||||
  static const _USER_ID_PREFERENCE_NAME = "user_id";
 | 
			
		||||
 | 
			
		||||
@@ -76,6 +84,34 @@ class AccountHelper {
 | 
			
		||||
    _currentUserID = 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Create a new user account
 | 
			
		||||
  Future<CreateAccountResult> createAccount(NewAccount info) async {
 | 
			
		||||
    final response = await APIRequest(
 | 
			
		||||
      uri: "account/create",
 | 
			
		||||
      needLogin: false,
 | 
			
		||||
      args: {
 | 
			
		||||
        "firstName": info.firstName,
 | 
			
		||||
        "lastName": info.lastName,
 | 
			
		||||
        "emailAddress": info.email,
 | 
			
		||||
        "password": info.password,
 | 
			
		||||
      },
 | 
			
		||||
    ).exec();
 | 
			
		||||
 | 
			
		||||
    switch (response.code) {
 | 
			
		||||
      case 200:
 | 
			
		||||
        return CreateAccountResult.SUCCESS;
 | 
			
		||||
 | 
			
		||||
      case 409:
 | 
			
		||||
        return CreateAccountResult.ERROR_EXISTING_EMAIL;
 | 
			
		||||
 | 
			
		||||
      case 429:
 | 
			
		||||
        return CreateAccountResult.ERROR_TOO_MANY_REQUESTS;
 | 
			
		||||
 | 
			
		||||
      default:
 | 
			
		||||
        return CreateAccountResult.ERROR;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Get current user ID from the server
 | 
			
		||||
  Future<int> _downloadCurrentUserID() async {
 | 
			
		||||
    final response = await APIRequest(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user