Rework assistant account creation

This commit is contained in:
Margaux Clerc 2016-02-29 14:30:32 +01:00
parent 321eba7153
commit 375b7aadda
6 changed files with 69 additions and 68 deletions

View file

@ -74,7 +74,7 @@
<string name="wizard_username_unavailable">Tämä käyttäjätunnus on jo käytössä.</string> <string name="wizard_username_unavailable">Tämä käyttäjätunnus on jo käytössä.</string>
<string name="wizard_username_incorrect">Sinun käyttäjätunnus ei ole kelvollinen.</string> <string name="wizard_username_incorrect">Sinun käyttäjätunnus ei ole kelvollinen.</string>
<string name="wizard_email_incorrect">Sähkpostisi ei ole kelvollinen.</string> <string name="wizard_email_incorrect">Sähkpostisi ei ole kelvollinen.</string>
<string name="wizard_password_incorrect">Salasanasi ei ole kelvollinen (6 merkkiä vähintään).</string> <string name="wizard_password_incorrect">Salasanasi ei ole kelvollinen.</string>
<string name="wizard_passwords_unmatched">Antamasi salasanat ovat erillaiset.</string> <string name="wizard_passwords_unmatched">Antamasi salasanat ovat erillaiset.</string>
<string name="setup_confirm_username">Sinun käyttäjätunnus tulee olemaan %s.\r\n\r\nIt voiden muuttua, jotta vaatiukset täyttyisivät .\r\nHyväksytkö?</string> <string name="setup_confirm_username">Sinun käyttäjätunnus tulee olemaan %s.\r\n\r\nIt voiden muuttua, jotta vaatiukset täyttyisivät .\r\nHyväksytkö?</string>
<string name="first_launch_no_login_password">Anna käyttäjätunnus ja salasana</string> <string name="first_launch_no_login_password">Anna käyttäjätunnus ja salasana</string>

View file

@ -75,7 +75,7 @@ Lorsque cela est fait, cliquez sur le bouton pour continuer.</string>
<string name="wizard_username_unavailable">Ce nom d\'utilisateur est déjà pris.</string> <string name="wizard_username_unavailable">Ce nom d\'utilisateur est déjà pris.</string>
<string name="wizard_username_incorrect">Votre nom d\'utilisateur est invalide.</string> <string name="wizard_username_incorrect">Votre nom d\'utilisateur est invalide.</string>
<string name="wizard_email_incorrect">Votre email est invalide.</string> <string name="wizard_email_incorrect">Votre email est invalide.</string>
<string name="wizard_password_incorrect">Votre mot de passe est invalide (6 caractères minimum).</string> <string name="wizard_password_incorrect">Votre mot de passe est invalide.</string>
<string name="wizard_passwords_unmatched">Les mots de passes ne correspondent pas.</string> <string name="wizard_passwords_unmatched">Les mots de passes ne correspondent pas.</string>
<string name="setup_confirm_username">Votre nom d\'utilisateur sera %s.\r\n\r\nIl peut différer de votre saisie.\r\nContinuer ?</string> <string name="setup_confirm_username">Votre nom d\'utilisateur sera %s.\r\n\r\nIl peut différer de votre saisie.\r\nContinuer ?</string>
<string name="first_launch_no_login_password">Entrez votre nom d\'utilisateur et votre mot de passe</string> <string name="first_launch_no_login_password">Entrez votre nom d\'utilisateur et votre mot de passe</string>

View file

@ -85,7 +85,7 @@
<string name="wizard_username_unavailable">This username is already in use.</string> <string name="wizard_username_unavailable">This username is already in use.</string>
<string name="wizard_username_incorrect">Your username is invalid.</string> <string name="wizard_username_incorrect">Your username is invalid.</string>
<string name="wizard_email_incorrect">Your email is invalid.</string> <string name="wizard_email_incorrect">Your email is invalid.</string>
<string name="wizard_password_incorrect">Your password is invalid (6 characters min).</string> <string name="wizard_password_incorrect">Your password is invalid</string>
<string name="wizard_passwords_unmatched">Passwords do not match.</string> <string name="wizard_passwords_unmatched">Passwords do not match.</string>
<string name="setup_confirm_username">Your username will be %s.\r\n\r\nIt may differ from your input to match requirements.\r\nDo you accept?</string> <string name="setup_confirm_username">Your username will be %s.\r\n\r\nIt may differ from your input to match requirements.\r\nDo you accept?</string>
<string name="first_launch_no_login_password">Please enter your login and password</string> <string name="first_launch_no_login_password">Please enter your login and password</string>

View file

@ -395,7 +395,9 @@ public class AssistantActivity extends Activity implements OnClickListener {
try { try {
builder.saveNewAccount(); builder.saveNewAccount();
displayRegistrationInProgressDialog(); if(!newAccount) {
displayRegistrationInProgressDialog();
}
accountCreated = true; accountCreated = true;
} catch (LinphoneCoreException e) { } catch (LinphoneCoreException e) {
e.printStackTrace(); e.printStackTrace();
@ -414,12 +416,12 @@ public class AssistantActivity extends Activity implements OnClickListener {
} }
} }
public void displayAssistantConfirm(String username) { public void displayAssistantConfirm(String username, String password) {
CreateAccountActivationFragment fragment = new CreateAccountActivationFragment(); CreateAccountActivationFragment fragment = new CreateAccountActivationFragment();
progress.dismiss();
newAccount = true; newAccount = true;
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString("Username", username); extras.putString("Username", username);
extras.putString("Password", password);
fragment.setArguments(extras); fragment.setArguments(extras);
changeFragment(fragment); changeFragment(fragment);

View file

@ -38,7 +38,7 @@ import de.timroes.axmlrpc.XMLRPCServerException;
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class CreateAccountActivationFragment extends Fragment { public class CreateAccountActivationFragment extends Fragment {
private String username; private String username, password, domain;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
@Override @Override
@ -47,6 +47,7 @@ public class CreateAccountActivationFragment extends Fragment {
View view = inflater.inflate(R.layout.assistant_account_creation_activation, container, false); View view = inflater.inflate(R.layout.assistant_account_creation_activation, container, false);
username = getArguments().getString("Username"); username = getArguments().getString("Username");
password = getArguments().getString("Password");
Button checkAccount = (Button) view.findViewById(R.id.assistant_check); Button checkAccount = (Button) view.findViewById(R.id.assistant_check);
checkAccount.setOnClickListener(new OnClickListener() { checkAccount.setOnClickListener(new OnClickListener() {
@ -78,6 +79,7 @@ public class CreateAccountActivationFragment extends Fragment {
Runnable runOk = new Runnable() { Runnable runOk = new Runnable() {
public void run() { public void run() {
AssistantActivity.instance().saveCreatedAccount(username,password,null, getString(R.string.default_domain),null);
AssistantActivity.instance().isAccountVerified(username); AssistantActivity.instance().isAccountVerified(username);
} }
}; };

View file

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
import java.net.URL; import java.net.URL;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
@ -35,8 +36,7 @@ import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Editable; import android.text.Editable;
import android.text.InputFilter; import android.text.InputType;
import android.text.Spanned;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Patterns; import android.util.Patterns;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -64,6 +64,7 @@ public class CreateAccountFragment extends Fragment {
private boolean emailOk = false; private boolean emailOk = false;
private boolean confirmPasswordOk = false; private boolean confirmPasswordOk = false;
private Button createAccount; private Button createAccount;
private final Pattern UPPER_CASE_REGEX = Pattern.compile("[A-Z]");
private char[] acceptedChars = new char[]{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', private char[] acceptedChars = new char[]{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-' }; '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '_', '-' };
@ -100,21 +101,8 @@ public class CreateAccountFragment extends Fragment {
inputFilterCharacters = new String(acceptedChars); inputFilterCharacters = new String(acceptedChars);
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) { if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
inputFilterCharacters = new String(acceptedCharsForPhoneNumbers); inputFilterCharacters = new String(acceptedCharsForPhoneNumbers);
usernameEdit.setInputType(InputType.TYPE_CLASS_NUMBER);
} }
InputFilter filter = new InputFilter(){
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (end > start) {
for (int index = start; index < end; index++) {
if (!inputFilterCharacters.contains(String.valueOf(source.charAt(index)))) {
return "";
}
}
}
return null;
}
};
usernameEdit.setFilters(new InputFilter[] { filter });
addXMLRPCPasswordHandler(passwordEdit, null); addXMLRPCPasswordHandler(passwordEdit, null);
addXMLRPCConfirmPasswordHandler(passwordEdit, passwordConfirmEdit, null); addXMLRPCConfirmPasswordHandler(passwordEdit, passwordConfirmEdit, null);
@ -124,19 +112,7 @@ public class CreateAccountFragment extends Fragment {
createAccount.setEnabled(false); createAccount.setEnabled(false);
createAccount.setOnClickListener(new OnClickListener() { createAccount.setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); createAccount(getUsername(), passwordEdit.getText().toString(), emailEdit.getText().toString(), false);
builder.setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
createAccount(getUsername(), passwordEdit.getText().toString(), emailEdit.getText().toString(), false);
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setMessage(getString(R.string.setup_confirm_username).replace("%s", getUsername()));
AlertDialog dialog = builder.create();
dialog.show();
} }
}); });
@ -147,6 +123,7 @@ public class CreateAccountFragment extends Fragment {
if (isEmailCorrect(account.name)) { if (isEmailCorrect(account.name)) {
String possibleEmail = account.name; String possibleEmail = account.name;
emailEdit.setText(possibleEmail); emailEdit.setText(possibleEmail);
emailOk = true;
break; break;
} }
} }
@ -172,7 +149,7 @@ public class CreateAccountFragment extends Fragment {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig(); LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
return lpc.isPhoneNumber(username); return lpc.isPhoneNumber(username);
} else { } else {
return username.matches("^[a-zA-Z]+[a-zA-Z0-9.\\-_]{2,}$"); return username.matches("^[a-z]+[a-z0-9.\\-_]{2,}$");
} }
} }
@ -237,7 +214,7 @@ public class CreateAccountFragment extends Fragment {
} }
private boolean isPasswordCorrect(String password) { private boolean isPasswordCorrect(String password) {
return password.length() >= 6; return password.length() >= 1;
} }
private void createAccount(final String username, final String password, String email, boolean suscribe) { private void createAccount(final String username, final String password, String email, boolean suscribe) {
@ -261,8 +238,7 @@ public class CreateAccountFragment extends Fragment {
Runnable runOk = new Runnable() { Runnable runOk = new Runnable() {
public void run() { public void run() {
AssistantActivity.instance().saveCreatedAccount(username, password, null, context.getString(R.string.default_domain), null); AssistantActivity.instance().displayAssistantConfirm(username, password);
AssistantActivity.instance().displayAssistantConfirm(username);
} }
}; };
@ -294,7 +270,11 @@ public class CreateAccountFragment extends Fragment {
private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) { private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() { field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
Matcher matcher = UPPER_CASE_REGEX.matcher(s);
while (matcher.find()) {
CharSequence upperCaseRegion = s.subSequence(matcher.start(), matcher.end());
s.replace(matcher.start(), matcher.end(), upperCaseRegion.toString().toLowerCase());
}
} }
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -302,17 +282,26 @@ public class CreateAccountFragment extends Fragment {
} }
public void onTextChanged(CharSequence s, int start, int count, int after) { public void onTextChanged(CharSequence s, int start, int count, int after) {
usernameOk = false; field.setOnFocusChangeListener(new View.OnFocusChangeListener() {
String username = field.getText().toString().toLowerCase(Locale.getDefault()); @Override
if (isUsernameCorrect(username)) { public void onFocusChange(View v, boolean hasFocus) {
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) { if(!hasFocus){
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig(); usernameOk = false;
username = lpc.normalizePhoneNumber(username); String username = field.getText().toString();
if (isUsernameCorrect(username)) {
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
}
isUsernameRegistred(username, icon);
} else {
displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_username_incorrect));
}
} else {
displayError(true, usernameError, usernameEdit, "");
}
} }
isUsernameRegistred(username, icon); });
} else {
displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_username_incorrect));
}
} }
}); });
} }
@ -381,21 +370,29 @@ public class CreateAccountFragment extends Fragment {
public void onTextChanged(CharSequence s, int start, int count, int after) public void onTextChanged(CharSequence s, int start, int count, int after)
{ {
confirmPasswordOk = false; field2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
if (field1.getText().toString().equals(field2.getText().toString())) { @Override
confirmPasswordOk = true; public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
confirmPasswordOk = false;
if (field1.getText().toString().equals(field2.getText().toString())) {
confirmPasswordOk = true;
if (!isPasswordCorrect(field1.getText().toString())) { if (!isPasswordCorrect(field1.getText().toString())) {
displayError(passwordOk, passwordError, passwordEdit, getString(R.string.wizard_password_incorrect)); displayError(passwordOk, passwordError, passwordEdit, getString(R.string.wizard_password_incorrect));
} else {
displayError(confirmPasswordOk, passwordConfirmError, passwordConfirmEdit, "");
}
} else {
displayError(confirmPasswordOk, passwordConfirmError, passwordConfirmEdit, getString(R.string.wizard_passwords_unmatched));
}
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} else {
displayError(true, passwordConfirmError, passwordConfirmEdit, "");
}
} }
else { });
displayError(confirmPasswordOk, passwordConfirmError, passwordConfirmEdit, "");
}
}
else {
displayError(confirmPasswordOk, passwordConfirmError, passwordConfirmEdit, getString(R.string.wizard_passwords_unmatched));
}
createAccount.setEnabled(usernameOk && passwordOk && confirmPasswordOk && emailOk);
} }
}; };