# HG changeset patch # User Marseille # Date 1246458076 -7200 # Node ID cb5293558d3c1686b785da8411b33490ee800c6c # Parent 5601d949c5aac9d1c1fb1a6e4257af0932695ad3 MIse en place du JID dans createaccount diff -r 5601d949c5aa -r cb5293558d3c res/values-en/strings.xml --- a/res/values-en/strings.xml Wed Jul 01 14:15:06 2009 +0200 +++ b/res/values-en/strings.xml Wed Jul 01 16:21:16 2009 +0200 @@ -61,15 +61,6 @@ Yes No - - Login: - Email: - Password: - Repeat: - Ok - Log with - Bad form - Account created Beem - Add contact @@ -220,6 +211,7 @@ Change my settings Close has been created successfully + Bad JabberID Passwords do not match. Username Password diff -r 5601d949c5aa -r cb5293558d3c res/values-fr/strings.xml --- a/res/values-fr/strings.xml Wed Jul 01 14:15:06 2009 +0200 +++ b/res/values-fr/strings.xml Wed Jul 01 16:21:16 2009 +0200 @@ -58,16 +58,6 @@ Êtes-vous sûr de vouloir supprimer ce contact ? Oui Non - - - Nom d'utilisateur: - Courriel: - Mot de passe: - Répéter: - Ok - Se connecter avec - Mauvais formulaire - Compte créé Beem - Ajouter un contact @@ -214,6 +204,7 @@ Changer mes paramètres Fermer a été créé avec succès + Mauvais JabberID Les mots de passe ne correspondent pas Nom d\'utilisateur Mot de passe diff -r 5601d949c5aa -r cb5293558d3c src/com/beem/project/beem/ui/CreateAccount.java --- a/src/com/beem/project/beem/ui/CreateAccount.java Wed Jul 01 14:15:06 2009 +0200 +++ b/src/com/beem/project/beem/ui/CreateAccount.java Wed Jul 01 16:21:16 2009 +0200 @@ -1,10 +1,13 @@ package com.beem.project.beem.ui; +import java.util.regex.Pattern; + import org.jivesoftware.smack.AccountManager; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.proxy.ProxyInfo; +import org.jivesoftware.smack.util.StringUtils; import android.app.Activity; import android.app.AlertDialog; @@ -15,29 +18,27 @@ import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; import android.widget.Toast; import com.beem.project.beem.R; /** - * This class represents an activity which allows the user to create an account on the XMPP server - * saved in settings - * + * This class represents an activity which allows the user to create an account on the XMPP server saved in settings * @author dasilvj */ public class CreateAccount extends Activity { private final static boolean DEFAULT_BOOLEAN_VALUE = false; - private final static String DEFAULT_STRING_VALUE = ""; - private final static int DEFAULT_INT_VALUE = 0; + private final static String DEFAULT_STRING_VALUE = ""; + private final static int DEFAULT_INT_VALUE = 0; - private final static String DEFAULT_XMPP_PORT = "5222"; + private final static String DEFAULT_XMPP_PORT = "5222"; - private final static int NOTIFICATION_DURATION = Toast.LENGTH_SHORT; + private final static int NOTIFICATION_DURATION = Toast.LENGTH_SHORT; - private SharedPreferences settings = null; - private Button createAccountButton = null; - + private SharedPreferences settings = null; + private Button createAccountButton = null; /** * {@inheritDoc} @@ -51,21 +52,6 @@ } /** - * Check if the fields password and confirm password match - * - * @return return true if password & confirm password fields match, else false - */ - private boolean checkPasswords() { - final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString(); - final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password)) - .getText().toString(); - - if (passwordFieldValue.equals(passwordConfirmFielddValue)) - return (true); - return (false); - } - - /** * Create an account on the XMPP server specified in settings */ private boolean createAccount(String username, String password) { @@ -73,10 +59,9 @@ ConnectionConfiguration connectionConfiguration = null; if (getRegisteredProxy() != null) { - connectionConfiguration = new ConnectionConfiguration(getRegisteredXMPPServer(), getRegisteredXMPPPort(), - getRegisteredProxy()); + connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), 5222, getRegisteredProxy()); } else { - connectionConfiguration = new ConnectionConfiguration(getRegisteredXMPPServer(), getRegisteredXMPPPort()); + connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), 5222); } if (getRegisteredXMPPTLSUse()) connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required); @@ -100,9 +85,7 @@ /** * Create a dialog containing an error message - * - * @param errMsg - * the error message + * @param errMsg the error message */ private void createErrorDialog(String errMsg) { Log.v(getString(R.string.create_account_tag), errMsg); @@ -121,7 +104,6 @@ /** * Retrive proxy informations from the preferences - * * @return Registered proxy informations */ private ProxyInfo getRegisteredProxy() { @@ -135,7 +117,6 @@ /** * Retrieve proxy password from the preferences - * * @return Registered proxy password */ private String getRegisteredProxyPassword() { @@ -144,7 +125,6 @@ /** * Retrieve proxy port from the preferences - * * @return Registered proxy port */ private int getRegisteredProxyPort() { @@ -153,7 +133,6 @@ /** * Retrieve proxy server from the preferences - * * @return Registered proxy server */ private String getRegisteredProxyServer() { @@ -162,7 +141,6 @@ /** * Retrieve proxy type from the preferences - * * @return Registered proxy type */ private ProxyInfo.ProxyType getRegisteredProxyType() { @@ -181,7 +159,6 @@ /** * Retrieve proxy use from the preferences - * * @return Registered proxy use */ private boolean getRegisteredProxyUse() { @@ -190,7 +167,6 @@ /** * Retrieve proxy username from the preferences - * * @return Registered proxy username */ private String getRegisteredProxyUsername() { @@ -198,26 +174,17 @@ } /** - * Retrieve xmpp port from the preferences - * - * @return Registered xmpp port - */ - private int getRegisteredXMPPPort() { - return (Integer.parseInt(settings.getString(getString(R.string.settings_key_xmpp_port), DEFAULT_XMPP_PORT))); - } - - /** * Retrieve xmpp server from the preferences - * * @return Registered xmpp server */ - private String getRegisteredXMPPServer() { - return (settings.getString(getString(R.string.settings_key_xmpp_server), DEFAULT_STRING_VALUE)); + private String getXMPPServer() { + TextView xmppServerTextView = (TextView) findViewById(R.id.create_account_username); + String xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString()); + return xmppServer; } /** * Retrieve TLS use from the preferences - * * @return Registered TLS use */ private boolean getRegisteredXMPPTLSUse() { @@ -225,6 +192,25 @@ } /** + * Check if the fields password and confirm password match + * @return return true if password & confirm password fields match, else false + */ + private boolean checkPasswords() { + final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString(); + final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password)) + .getText().toString(); + + if (passwordFieldValue.equals(passwordConfirmFielddValue)) + return (true); + return (false); + } + + private boolean checkEmail() { + String email = ((TextView) findViewById(R.id.create_account_username)).getText().toString(); + return (Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", email)); + } + + /** * Initialize the "Create this account" button which allows the user to create an account */ private void initCreateAccountButton() { @@ -232,30 +218,39 @@ createAccountButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText() - .toString(); + .toString(); String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText() - .toString(); + .toString(); + String username = StringUtils.parseName(usernameFieldValue); + if (!checkEmail()) + createErrorDialog(getString(R.string.create_account_err_username)); + else if (!checkPasswords()) + createErrorDialog(getString(R.string.create_account_err_passwords)); + else { + if (createAccount(username, passwordFieldValue)) + finish(); + } - if (!checkPasswords()) - createErrorDialog(getString(R.string.create_account_err_passwords)); - else if (createAccount(usernameFieldValue, passwordFieldValue)) - finish(); } }); Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button); createAccountLoginButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText() - .toString(); + .toString(); + String username = StringUtils.parseName(usernameFieldValue); + String server= StringUtils.parseServer(usernameFieldValue); String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText() - .toString(); - - if (!checkPasswords()) + .toString(); + if (!checkEmail()) + createErrorDialog(getString(R.string.create_account_err_username)); + else if (!checkPasswords()) createErrorDialog(getString(R.string.create_account_err_passwords)); else { - if (createAccount(usernameFieldValue, passwordFieldValue)) { + if (createAccount(username, passwordFieldValue)) { SharedPreferences.Editor settingsEditor = settings.edit(); - settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue); + settingsEditor.putString(getString(R.string.settings_key_account_username), username); + settingsEditor.putString(getString(R.string.settings_account_server), server); settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue); settingsEditor.commit(); finish(); @@ -263,5 +258,5 @@ } } }); - } + } }