make registration uris work with fixed usernames
This commit is contained in:
parent
e57bd477a9
commit
6025e5de28
|
@ -8,9 +8,6 @@ import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
@ -26,9 +23,11 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
|
|
||||||
public static final String EXTRA_DOMAIN = "domain";
|
public static final String EXTRA_DOMAIN = "domain";
|
||||||
public static final String EXTRA_PRE_AUTH = "pre_auth";
|
public static final String EXTRA_PRE_AUTH = "pre_auth";
|
||||||
|
public static final String EXTRA_USERNAME = "username";
|
||||||
|
|
||||||
private MagicCreateBinding binding;
|
private MagicCreateBinding binding;
|
||||||
private String domain;
|
private String domain;
|
||||||
|
private String username;
|
||||||
private String preAuth;
|
private String preAuth;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,6 +54,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
final Intent data = getIntent();
|
final Intent data = getIntent();
|
||||||
this.domain = data == null ? null : data.getStringExtra(EXTRA_DOMAIN);
|
this.domain = data == null ? null : data.getStringExtra(EXTRA_DOMAIN);
|
||||||
this.preAuth = data == null ? null : data.getStringExtra(EXTRA_PRE_AUTH);
|
this.preAuth = data == null ? null : data.getStringExtra(EXTRA_PRE_AUTH);
|
||||||
|
this.username = data == null ? null : data.getStringExtra(EXTRA_USERNAME);
|
||||||
if (getResources().getBoolean(R.bool.portrait_only)) {
|
if (getResources().getBoolean(R.bool.portrait_only)) {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,14 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
this.binding = DataBindingUtil.setContentView(this, R.layout.magic_create);
|
this.binding = DataBindingUtil.setContentView(this, R.layout.magic_create);
|
||||||
setSupportActionBar((Toolbar) this.binding.toolbar);
|
setSupportActionBar((Toolbar) this.binding.toolbar);
|
||||||
configureActionBar(getSupportActionBar(), this.domain == null);
|
configureActionBar(getSupportActionBar(), this.domain == null);
|
||||||
if (domain != null) {
|
if (username != null && domain != null) {
|
||||||
|
binding.title.setText(R.string.your_server_invitation);
|
||||||
|
binding.instructions.setText(getString(R.string.magic_create_text_fixed, domain));
|
||||||
|
binding.finePrint.setVisibility(View.INVISIBLE);
|
||||||
|
binding.username.setEnabled(false);
|
||||||
|
binding.username.setText(this.username);
|
||||||
|
updateFullJidInformation(this.username);
|
||||||
|
} else if (domain != null) {
|
||||||
binding.instructions.setText(getString(R.string.magic_create_text_on_x, domain));
|
binding.instructions.setText(getString(R.string.magic_create_text_on_x, domain));
|
||||||
binding.finePrint.setVisibility(View.INVISIBLE);
|
binding.finePrint.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
@ -70,12 +77,18 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
try {
|
try {
|
||||||
final String username = binding.username.getText().toString();
|
final String username = binding.username.getText().toString();
|
||||||
final Jid jid;
|
final Jid jid;
|
||||||
if (this.domain == null) {
|
final boolean fixedUsername;
|
||||||
jid = Jid.ofLocalAndDomain(username, Config.MAGIC_CREATE_DOMAIN);
|
if (this.domain != null && this.username != null) {
|
||||||
} else {
|
fixedUsername = true;
|
||||||
|
jid = Jid.ofLocalAndDomain(this.username, this.domain);
|
||||||
|
} else if (this.domain != null) {
|
||||||
|
fixedUsername = false;
|
||||||
jid = Jid.ofLocalAndDomain(username, this.domain);
|
jid = Jid.ofLocalAndDomain(username, this.domain);
|
||||||
|
} else {
|
||||||
|
fixedUsername = false;
|
||||||
|
jid = Jid.ofLocalAndDomain(username, Config.MAGIC_CREATE_DOMAIN);
|
||||||
}
|
}
|
||||||
if (!jid.getEscapedLocal().equals(jid.getLocal()) || username.length() < 3) {
|
if (!jid.getEscapedLocal().equals(jid.getLocal()) || (this.username == null && username.length() < 3)) {
|
||||||
binding.username.setError(getString(R.string.invalid_username));
|
binding.username.setError(getString(R.string.invalid_username));
|
||||||
binding.username.requestFocus();
|
binding.username.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,6 +99,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
account.setOption(Account.OPTION_REGISTER, true);
|
account.setOption(Account.OPTION_REGISTER, true);
|
||||||
account.setOption(Account.OPTION_DISABLED, true);
|
account.setOption(Account.OPTION_DISABLED, true);
|
||||||
account.setOption(Account.OPTION_MAGIC_CREATE, true);
|
account.setOption(Account.OPTION_MAGIC_CREATE, true);
|
||||||
|
account.setOption(Account.OPTION_FIXED_USERNAME, fixedUsername);
|
||||||
if (this.preAuth != null) {
|
if (this.preAuth != null) {
|
||||||
account.setKey(Account.PRE_AUTH_REGISTRATION_TOKEN, this.preAuth);
|
account.setKey(Account.PRE_AUTH_REGISTRATION_TOKEN, this.preAuth);
|
||||||
}
|
}
|
||||||
|
@ -118,23 +132,26 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(final Editable s) {
|
||||||
if (s.toString().trim().length() > 0) {
|
updateFullJidInformation(s.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFullJidInformation(final String username) {
|
||||||
|
if (username.trim().isEmpty()) {
|
||||||
|
binding.fullJid.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
binding.fullJid.setVisibility(View.VISIBLE);
|
binding.fullJid.setVisibility(View.VISIBLE);
|
||||||
final Jid jid;
|
final Jid jid;
|
||||||
if (this.domain == null) {
|
if (this.domain == null) {
|
||||||
jid = Jid.ofLocalAndDomain(s.toString(), Config.MAGIC_CREATE_DOMAIN);
|
jid = Jid.ofLocalAndDomain(username, Config.MAGIC_CREATE_DOMAIN);
|
||||||
} else {
|
} else {
|
||||||
jid = Jid.ofLocalAndDomain(s.toString(), this.domain);
|
jid = Jid.ofLocalAndDomain(username, this.domain);
|
||||||
}
|
}
|
||||||
binding.fullJid.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString()));
|
binding.fullJid.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString()));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
binding.fullJid.setVisibility(View.INVISIBLE);
|
binding.fullJid.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
binding.fullJid.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import eu.siacs.conversations.ui.ManageAccountActivity;
|
||||||
import eu.siacs.conversations.ui.PickServerActivity;
|
import eu.siacs.conversations.ui.PickServerActivity;
|
||||||
import eu.siacs.conversations.ui.StartConversationActivity;
|
import eu.siacs.conversations.ui.StartConversationActivity;
|
||||||
import eu.siacs.conversations.ui.WelcomeActivity;
|
import eu.siacs.conversations.ui.WelcomeActivity;
|
||||||
|
import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class SignupUtils {
|
public class SignupUtils {
|
||||||
|
|
||||||
|
@ -20,9 +21,14 @@ public class SignupUtils {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent getTokenRegistrationIntent(final Activity activity, String domain, String preAuth) {
|
public static Intent getTokenRegistrationIntent(final Activity activity, Jid jid, String preAuth) {
|
||||||
final Intent intent = new Intent(activity, MagicCreateActivity.class);
|
final Intent intent = new Intent(activity, MagicCreateActivity.class);
|
||||||
intent.putExtra(MagicCreateActivity.EXTRA_DOMAIN, domain);
|
if (jid.isDomainJid()) {
|
||||||
|
intent.putExtra(MagicCreateActivity.EXTRA_DOMAIN, jid.getDomain());
|
||||||
|
} else {
|
||||||
|
intent.putExtra(MagicCreateActivity.EXTRA_DOMAIN, jid.getDomain());
|
||||||
|
intent.putExtra(MagicCreateActivity.EXTRA_USERNAME, jid.getEscapedLocal());
|
||||||
|
}
|
||||||
intent.putExtra(MagicCreateActivity.EXTRA_PRE_AUTH, preAuth);
|
intent.putExtra(MagicCreateActivity.EXTRA_PRE_AUTH, preAuth);
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/pick_your_username"
|
android:text="@string/pick_your_username"
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:hint="@string/username_hint"
|
android:hint="@string/username_hint"
|
||||||
|
android:textColor="?attr/edit_text_color"
|
||||||
android:inputType="textNoSuggestions" />
|
android:inputType="textNoSuggestions" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
@ -6,4 +6,6 @@
|
||||||
<string name="do_you_have_an_account">Do you already have an XMPP account? This might be the case if you are already using a different XMPP client or have used Conversations before. If not you can create a new XMPP account right now.\nHint: Some email providers also provide XMPP accounts.</string>
|
<string name="do_you_have_an_account">Do you already have an XMPP account? This might be the case if you are already using a different XMPP client or have used Conversations before. If not you can create a new XMPP account right now.\nHint: Some email providers also provide XMPP accounts.</string>
|
||||||
<string name="server_select_text">XMPP is a provider independent instant messaging network. You can use this client with what ever XMPP server you choose.\nHowever for your convenience we made it easy to create an account on conversations.im¹; a provider specially suited for the use with Conversations.</string>
|
<string name="server_select_text">XMPP is a provider independent instant messaging network. You can use this client with what ever XMPP server you choose.\nHowever for your convenience we made it easy to create an account on conversations.im¹; a provider specially suited for the use with Conversations.</string>
|
||||||
<string name="magic_create_text_on_x">You have been invited to %1$s. We will guide you through the process of creating an account.\nWhen picking %1$s as a provider you will be able to communicate with users of other providers by giving them your full XMPP address.</string>
|
<string name="magic_create_text_on_x">You have been invited to %1$s. We will guide you through the process of creating an account.\nWhen picking %1$s as a provider you will be able to communicate with users of other providers by giving them your full XMPP address.</string>
|
||||||
|
<string name="magic_create_text_fixed">You have been invited to %1$s. A username has already been picked for you. We will guide you through the process of creating an account.\nYou will be able to communicate with users of other providers by giving them your full XMPP address.</string>
|
||||||
|
<string name="your_server_invitation">Your server invitation</string>
|
||||||
</resources>
|
</resources>
|
|
@ -61,6 +61,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
|
||||||
public static final int OPTION_LOGGED_IN_SUCCESSFULLY = 6;
|
public static final int OPTION_LOGGED_IN_SUCCESSFULLY = 6;
|
||||||
public static final int OPTION_HTTP_UPLOAD_AVAILABLE = 7;
|
public static final int OPTION_HTTP_UPLOAD_AVAILABLE = 7;
|
||||||
public static final int OPTION_UNVERIFIED = 8;
|
public static final int OPTION_UNVERIFIED = 8;
|
||||||
|
public static final int OPTION_FIXED_USERNAME = 9;
|
||||||
private static final String KEY_PGP_SIGNATURE = "pgp_signature";
|
private static final String KEY_PGP_SIGNATURE = "pgp_signature";
|
||||||
private static final String KEY_PGP_ID = "pgp_id";
|
private static final String KEY_PGP_ID = "pgp_id";
|
||||||
public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>();
|
public final HashSet<Pair<String, String>> inProgressDiscoFetches = new HashSet<>();
|
||||||
|
|
|
@ -407,7 +407,14 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
final Jid jid = mAccount == null ? null : mAccount.getJid();
|
final Jid jid = mAccount == null ? null : mAccount.getJid();
|
||||||
|
|
||||||
if (SignupUtils.isSupportTokenRegistry() && jid != null && magicCreate && !jid.getDomain().equals(Config.MAGIC_CREATE_DOMAIN)) {
|
if (SignupUtils.isSupportTokenRegistry() && jid != null && magicCreate && !jid.getDomain().equals(Config.MAGIC_CREATE_DOMAIN)) {
|
||||||
final Intent intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), mAccount.getKey(Account.PRE_AUTH_REGISTRATION_TOKEN));
|
final Jid preset;
|
||||||
|
if (mAccount.isOptionSet(Account.OPTION_FIXED_USERNAME)) {
|
||||||
|
preset = jid.asBareJid();
|
||||||
|
} else {
|
||||||
|
preset = Jid.ofDomain(jid.getDomain());
|
||||||
|
}
|
||||||
|
final Intent intent = SignupUtils.getTokenRegistrationIntent(this, preset, mAccount.getKey(Account.PRE_AUTH_REGISTRATION_TOKEN));
|
||||||
|
StartConversationActivity.addInviteUri(intent, getIntent());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -415,6 +422,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
|
|
||||||
if (xmppConnectionService.getAccounts().size() == 0 && Config.MAGIC_CREATE_DOMAIN != null) {
|
if (xmppConnectionService.getAccounts().size() == 0 && Config.MAGIC_CREATE_DOMAIN != null) {
|
||||||
Intent intent = SignupUtils.getSignUpIntent(this, mForceRegister != null && mForceRegister);
|
Intent intent = SignupUtils.getSignUpIntent(this, mForceRegister != null && mForceRegister);
|
||||||
|
StartConversationActivity.addInviteUri(intent, getIntent());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -972,7 +980,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && QuickConversationsService.isConversations();
|
final boolean editable = !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && !mAccount.isOptionSet(Account.OPTION_FIXED_USERNAME) && QuickConversationsService.isConversations();
|
||||||
this.binding.accountJid.setEnabled(editable);
|
this.binding.accountJid.setEnabled(editable);
|
||||||
this.binding.accountJid.setFocusable(editable);
|
this.binding.accountJid.setFocusable(editable);
|
||||||
this.binding.accountJid.setFocusableInTouchMode(editable);
|
this.binding.accountJid.setFocusableInTouchMode(editable);
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class UriHandlerActivity extends AppCompatActivity {
|
||||||
public static final String ACTION_SCAN_QR_CODE = "scan_qr_code";
|
public static final String ACTION_SCAN_QR_CODE = "scan_qr_code";
|
||||||
private static final int REQUEST_SCAN_QR_CODE = 0x1234;
|
private static final int REQUEST_SCAN_QR_CODE = 0x1234;
|
||||||
private static final int REQUEST_CAMERA_PERMISSIONS_TO_SCAN = 0x6789;
|
private static final int REQUEST_CAMERA_PERMISSIONS_TO_SCAN = 0x6789;
|
||||||
|
private static final Pattern VCARD_XMPP_PATTERN = Pattern.compile("\nIMPP([^:]*):(xmpp:.+)\n");
|
||||||
private boolean handled = false;
|
private boolean handled = false;
|
||||||
|
|
||||||
public static void scan(Activity activity) {
|
public static void scan(Activity activity) {
|
||||||
|
@ -93,15 +93,16 @@ public class UriHandlerActivity extends AppCompatActivity {
|
||||||
final String preauth = xmppUri.getParamater("preauth");
|
final String preauth = xmppUri.getParamater("preauth");
|
||||||
final Jid jid = xmppUri.getJid();
|
final Jid jid = xmppUri.getJid();
|
||||||
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
|
if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
|
||||||
if (jid.isDomainJid()) {
|
if (jid.getEscapedLocal() != null && accounts.contains(jid.asBareJid())) {
|
||||||
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preauth);
|
Toast.makeText(this, R.string.account_already_exists, Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
intent = SignupUtils.getTokenRegistrationIntent(this, jid, preauth);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParamater("ibr"))) {
|
if (xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParamater("ibr"))) {
|
||||||
intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preauth);
|
intent = SignupUtils.getTokenRegistrationIntent(this, Jid.ofDomain(jid.getDomain()), preauth);
|
||||||
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
|
intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return;
|
return;
|
||||||
|
@ -195,8 +196,6 @@ public class UriHandlerActivity extends AppCompatActivity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern VCARD_XMPP_PATTERN = Pattern.compile("\nIMPP([^:]*):(xmpp:.+)\n");
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
super.onActivityResult(requestCode, requestCode, intent);
|
super.onActivityResult(requestCode, requestCode, intent);
|
||||||
|
|
Loading…
Reference in a new issue