mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 15:59:29 +00:00
Can display specific error message on create account form.
This commit is contained in:
parent
c699e13833
commit
b8f732d82b
@ -0,0 +1,26 @@
|
|||||||
|
package org.communiquons.android.comunic.client.data.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create account results
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
public enum CreateAccountResult {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The account was successfully created
|
||||||
|
*/
|
||||||
|
SUCCESS,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trying to login with an existing email address
|
||||||
|
*/
|
||||||
|
ERROR_EXISTING_EMAIL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unspecified error occurred
|
||||||
|
*/
|
||||||
|
ERROR
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package org.communiquons.android.comunic.client.data.helpers;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.CreateAccountResult;
|
||||||
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
||||||
import org.communiquons.android.comunic.client.data.models.APIResponse;
|
import org.communiquons.android.comunic.client.data.models.APIResponse;
|
||||||
import org.communiquons.android.comunic.client.data.models.NewAccount;
|
import org.communiquons.android.comunic.client.data.models.NewAccount;
|
||||||
@ -188,9 +189,10 @@ public class AccountHelper {
|
|||||||
* @param newAccount Information about the new account to create
|
* @param newAccount Information about the new account to create
|
||||||
* @return TRUE for a success / FALSE else
|
* @return TRUE for a success / FALSE else
|
||||||
*/
|
*/
|
||||||
public boolean createAccount(NewAccount newAccount) {
|
public CreateAccountResult createAccount(NewAccount newAccount) {
|
||||||
|
|
||||||
APIRequest request = new APIRequest(mContext, "account/create");
|
APIRequest request = new APIRequest(mContext, "account/create");
|
||||||
|
request.setTryContinueOnError(true);
|
||||||
request.addString("firstName", newAccount.getFirstName());
|
request.addString("firstName", newAccount.getFirstName());
|
||||||
request.addString("lastName", newAccount.getLastName());
|
request.addString("lastName", newAccount.getLastName());
|
||||||
request.addString("emailAddress", newAccount.getEmail());
|
request.addString("emailAddress", newAccount.getEmail());
|
||||||
@ -199,11 +201,22 @@ public class AccountHelper {
|
|||||||
//Perform the request
|
//Perform the request
|
||||||
try {
|
try {
|
||||||
APIResponse response = new APIRequestHelper().exec(request);
|
APIResponse response = new APIRequestHelper().exec(request);
|
||||||
return response.getResponse_code() == 200;
|
|
||||||
|
switch (response.getResponse_code()) {
|
||||||
|
case 200:
|
||||||
|
return CreateAccountResult.SUCCESS;
|
||||||
|
|
||||||
|
case 409:
|
||||||
|
return CreateAccountResult.ERROR_EXISTING_EMAIL;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return CreateAccountResult.ERROR;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return CreateAccountResult.ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,13 @@ import android.widget.Button;
|
|||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.communiquons.android.comunic.client.BuildConfig;
|
import org.communiquons.android.comunic.client.BuildConfig;
|
||||||
import org.communiquons.android.comunic.client.R;
|
import org.communiquons.android.comunic.client.R;
|
||||||
import org.communiquons.android.comunic.client.data.asynctasks.SafeAsyncTask;
|
import org.communiquons.android.comunic.client.data.asynctasks.SafeAsyncTask;
|
||||||
|
import org.communiquons.android.comunic.client.data.enums.CreateAccountResult;
|
||||||
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
|
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
|
||||||
import org.communiquons.android.comunic.client.data.models.NewAccount;
|
import org.communiquons.android.comunic.client.data.models.NewAccount;
|
||||||
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
||||||
@ -29,13 +31,13 @@ import static android.os.AsyncTask.Status.FINISHED;
|
|||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
public class CreateAccountActivity extends AppCompatActivity
|
public class CreateAccountActivity extends AppCompatActivity
|
||||||
implements SafeAsyncTask.OnPostExecuteListener<Boolean> {
|
implements SafeAsyncTask.OnPostExecuteListener<CreateAccountResult> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Input fields
|
* Input fields
|
||||||
*/
|
*/
|
||||||
private ProgressBar mProgress;
|
private ProgressBar mProgress;
|
||||||
private View mForm;
|
private ScrollView mForm;
|
||||||
private TextView mError;
|
private TextView mError;
|
||||||
private EditText mFirstName;
|
private EditText mFirstName;
|
||||||
private EditText mLastName;
|
private EditText mLastName;
|
||||||
@ -238,12 +240,24 @@ public class CreateAccountActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void OnPostExecute(Boolean result) {
|
public void OnPostExecute(CreateAccountResult result) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
//Check for errors
|
//Check for errors
|
||||||
if(!result){
|
if(result != CreateAccountResult.SUCCESS){
|
||||||
setError(getString(R.string.err_while_creating_account));
|
|
||||||
|
//Find the right error to display
|
||||||
|
int message = R.string.err_while_creating_account;
|
||||||
|
switch (result){
|
||||||
|
|
||||||
|
//Existing email address
|
||||||
|
case ERROR_EXISTING_EMAIL:
|
||||||
|
message = R.string.err_create_account_existing_email;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mForm.scrollTo(1, 1);
|
||||||
|
setError(getString(message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,14 +275,14 @@ public class CreateAccountActivity extends AppCompatActivity
|
|||||||
/**
|
/**
|
||||||
* Class used to create an account across activities
|
* Class used to create an account across activities
|
||||||
*/
|
*/
|
||||||
private static class CreateAccountTask extends SafeAsyncTask<NewAccount, Void, Boolean> {
|
private static class CreateAccountTask extends SafeAsyncTask<NewAccount, Void, CreateAccountResult> {
|
||||||
|
|
||||||
CreateAccountTask(Context context) {
|
CreateAccountTask(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(NewAccount... newAccounts) {
|
protected CreateAccountResult doInBackground(NewAccount... newAccounts) {
|
||||||
return new AccountHelper(getContext()).createAccount(newAccounts[0]);
|
return new AccountHelper(getContext()).createAccount(newAccounts[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/activity_login_bg">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/loading_progress"
|
android:id="@+id/loading_progress"
|
||||||
@ -14,8 +15,7 @@
|
|||||||
<ScrollView
|
<ScrollView
|
||||||
android:id="@+id/create_account_form"
|
android:id="@+id/create_account_form"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" >
|
||||||
android:background="@drawable/activity_login_bg">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -44,6 +44,7 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
android:inputType="textPersonName"
|
||||||
android:id="@+id/first_name"
|
android:id="@+id/first_name"
|
||||||
style="@style/CreateAccountInput"
|
style="@style/CreateAccountInput"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -58,6 +59,7 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
android:inputType="textPersonName"
|
||||||
android:id="@+id/last_name"
|
android:id="@+id/last_name"
|
||||||
style="@style/CreateAccountInput"
|
style="@style/CreateAccountInput"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -228,9 +228,10 @@
|
|||||||
<string name="err_invalid_password">Please specify a valid password!</string>
|
<string name="err_invalid_password">Please specify a valid password!</string>
|
||||||
<string name="err_password_confirmation_not_identical">The password and its confirmation are not the same!</string>
|
<string name="err_password_confirmation_not_identical">The password and its confirmation are not the same!</string>
|
||||||
<string name="err_need_accept_terms">Please accept the terms of use of Comunic !</string>
|
<string name="err_need_accept_terms">Please accept the terms of use of Comunic !</string>
|
||||||
<string name="err_while_creating_account">An error occurred while trying to create your account! Maybe an account with the same email address already exists!</string>
|
<string name="err_while_creating_account">An error occurred while trying to create your account!</string>
|
||||||
<string name="account_created_title">Congratulations</string>
|
<string name="account_created_title">Congratulations</string>
|
||||||
<string name="account_created_message">Your account has been created. You can now sign into your new account to use all the features of Comunic.</string>
|
<string name="account_created_message">Your account has been created. You can now sign into your new account to use all the features of Comunic.</string>
|
||||||
<string name="account_created_sign_in">Sign in</string>
|
<string name="account_created_sign_in">Sign in</string>
|
||||||
<string name="activity_login_too_many_request">Too many failed login requests. Please try again later…</string>
|
<string name="activity_login_too_many_request">Too many failed login requests. Please try again later…</string>
|
||||||
|
<string name="err_create_account_existing_email">This email address is already associated with an account!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user