1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-20 00:35:17 +00:00

Create account form is working

This commit is contained in:
2019-11-02 18:54:30 +01:00
parent 32a32224ca
commit a603d5bd3a
5 changed files with 149 additions and 9 deletions

View File

@ -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(