added Config.java varibale to lock account creation to specfic domain

This commit is contained in:
Daniel Gultsch 2015-08-03 22:58:17 +02:00
parent 9b91d0bf75
commit c617cf6ef8
9 changed files with 112 additions and 33 deletions

View File

@ -8,6 +8,10 @@ public final class Config {
public static final String LOGTAG = "conversations"; public static final String LOGTAG = "conversations";
public static final String DOMAIN_LOCK = null; //only allow account creation for this domain
public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox
public static final int PING_MAX_INTERVAL = 300; public static final int PING_MAX_INTERVAL = 300;
public static final int PING_MIN_INTERVAL = 30; public static final int PING_MIN_INTERVAL = 30;
public static final int PING_TIMEOUT = 10; public static final int PING_TIMEOUT = 10;

View File

@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
@ -421,8 +422,13 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private void updateView() { private void updateView() {
final MucOptions mucOptions = mConversation.getMucOptions(); final MucOptions mucOptions = mConversation.getMucOptions();
final User self = mucOptions.getSelf(); final User self = mucOptions.getSelf();
mAccountJid.setText(getString(R.string.using_account, mConversation String account;
.getAccount().getJid().toBareJid())); if (Config.DOMAIN_LOCK != null) {
account = mConversation.getAccount().getJid().getLocalpart();
} else {
account = mConversation.getAccount().getJid().toBareJid().toString();
}
mAccountJid.setText(getString(R.string.using_account, account));
mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48))); mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
setTitle(mConversation.getName()); setTitle(mConversation.getName());
mFullJid.setText(mConversation.getJid().toBareJid().toString()); mFullJid.setText(mConversation.getJid().toBareJid().toString());

View File

@ -33,6 +33,7 @@ import org.whispersystems.libaxolotl.IdentityKey;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
@ -359,7 +360,13 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
} else { } else {
contactJidTv.setText(contact.getJid().toString()); contactJidTv.setText(contact.getJid().toString());
} }
accountJidTv.setText(getString(R.string.using_account, contact.getAccount().getJid().toBareJid())); String account;
if (Config.DOMAIN_LOCK != null) {
account = contact.getAccount().getJid().getLocalpart();
} else {
account = contact.getAccount().getJid().toBareJid().toString();
}
accountJidTv.setText(getString(R.string.using_account, account));
badge.setImageBitmap(avatarService().get(contact, getPixel(72))); badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
badge.setOnClickListener(this.onBadgeClick); badge.setOnClickListener(this.onBadgeClick);

View File

@ -63,6 +63,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private TextView mSessionEst; private TextView mSessionEst;
private TextView mOtrFingerprint; private TextView mOtrFingerprint;
private TextView mAxolotlFingerprint; private TextView mAxolotlFingerprint;
private TextView mAccountJidLabel;
private ImageView mAvatar; private ImageView mAvatar;
private RelativeLayout mOtrFingerprintBox; private RelativeLayout mOtrFingerprintBox;
private RelativeLayout mAxolotlFingerprintBox; private RelativeLayout mAxolotlFingerprintBox;
@ -87,17 +88,34 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
xmppConnectionService.updateAccount(mAccount); xmppConnectionService.updateAccount(mAccount);
return; return;
} }
final boolean registerNewAccount = mRegisterNew.isChecked(); final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
if (Config.DOMAIN_LOCK != null && mAccountJid.getText().toString().contains("@")) {
mAccountJid.setError(getString(R.string.invalid_username));
mAccountJid.requestFocus();
return;
}
final Jid jid; final Jid jid;
try { try {
jid = Jid.fromString(mAccountJid.getText().toString()); if (Config.DOMAIN_LOCK != null) {
jid = Jid.fromParts(mAccountJid.getText().toString(),Config.DOMAIN_LOCK,null);
} else {
jid = Jid.fromString(mAccountJid.getText().toString());
}
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
mAccountJid.setError(getString(R.string.invalid_jid)); if (Config.DOMAIN_LOCK != null) {
mAccountJid.setError(getString(R.string.invalid_username));
} else {
mAccountJid.setError(getString(R.string.invalid_jid));
}
mAccountJid.requestFocus(); mAccountJid.requestFocus();
return; return;
} }
if (jid.isDomainJid()) { if (jid.isDomainJid()) {
mAccountJid.setError(getString(R.string.invalid_jid)); if (Config.DOMAIN_LOCK != null) {
mAccountJid.setError(getString(R.string.invalid_username));
} else {
mAccountJid.setError(getString(R.string.invalid_jid));
}
mAccountJid.requestFocus(); mAccountJid.requestFocus();
return; return;
} }
@ -123,13 +141,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.updateAccount(mAccount); xmppConnectionService.updateAccount(mAccount);
} else { } else {
try { if (xmppConnectionService.findAccountByJid(jid) != null) {
if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) { mAccountJid.setError(getString(R.string.account_already_exists));
mAccountJid.setError(getString(R.string.account_already_exists)); mAccountJid.requestFocus();
mAccountJid.requestFocus();
return;
}
} catch (final InvalidJidException e) {
return; return;
} }
mAccount = new Account(jid.toBareJid(), password); mAccount = new Account(jid.toBareJid(), password);
@ -285,10 +299,17 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
protected boolean accountInfoEdited() { protected boolean accountInfoEdited() {
return this.mAccount != null && (!this.mAccount.getJid().toBareJid().toString().equals( if (this.mAccount == null) {
this.mAccountJid.getText().toString()) return false;
|| !this.mAccount.getPassword().equals( }
this.mPassword.getText().toString())); final String unmodified;
if (Config.DOMAIN_LOCK != null) {
unmodified = this.mAccount.getJid().getLocalpart();
} else {
unmodified = this.mAccount.getJid().toBareJid().toString();
}
return !unmodified.equals(this.mAccountJid.getText().toString()) ||
!this.mAccount.getPassword().equals(this.mPassword.getText().toString());
} }
@Override @Override
@ -306,6 +327,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
setContentView(R.layout.activity_edit_account); setContentView(R.layout.activity_edit_account);
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid); this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
this.mAccountJid.addTextChangedListener(this.mTextWatcher); this.mAccountJid.addTextChangedListener(this.mTextWatcher);
this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label);
if (Config.DOMAIN_LOCK != null) {
this.mAccountJidLabel.setText(R.string.username);
this.mAccountJid.setHint(R.string.username_hint);
}
this.mPassword = (EditText) findViewById(R.id.account_password); this.mPassword = (EditText) findViewById(R.id.account_password);
this.mPassword.addTextChangedListener(this.mTextWatcher); this.mPassword.addTextChangedListener(this.mTextWatcher);
this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm); this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
@ -348,6 +374,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
}; };
this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword); this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
if (Config.DISALLOW_REGISTRATION_IN_UI) {
this.mRegisterNew.setVisibility(View.GONE);
}
} }
@Override @Override
@ -406,9 +435,6 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
android.R.layout.simple_list_item_1,
xmppConnectionService.getKnownHosts());
if (this.jidToEdit != null) { if (this.jidToEdit != null) {
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit); this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
updateAccountInformation(true); updateAccountInformation(true);
@ -421,7 +447,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mCancelButton.setEnabled(false); this.mCancelButton.setEnabled(false);
this.mCancelButton.setTextColor(getSecondaryTextColor()); this.mCancelButton.setTextColor(getSecondaryTextColor());
} }
this.mAccountJid.setAdapter(mKnownHostsAdapter); if (Config.DOMAIN_LOCK == null) {
final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
android.R.layout.simple_list_item_1,
xmppConnectionService.getKnownHosts());
this.mAccountJid.setAdapter(mKnownHostsAdapter);
}
updateSaveButton(); updateSaveButton();
} }
@ -451,7 +482,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private void updateAccountInformation(boolean init) { private void updateAccountInformation(boolean init) {
if (init) { if (init) {
this.mAccountJid.setText(this.mAccount.getJid().toBareJid().toString()); if (Config.DOMAIN_LOCK != null) {
this.mAccountJid.setText(this.mAccount.getJid().getLocalpart());
} else {
this.mAccountJid.setText(this.mAccount.getJid().toBareJid().toString());
}
this.mPassword.setText(this.mAccount.getPassword()); this.mPassword.setText(this.mAccount.getPassword());
} }
if (this.jidToEdit != null) { if (this.jidToEdit != null) {

View File

@ -13,6 +13,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.PhoneHelper;
@ -192,7 +193,13 @@ public class PublishProfilePictureActivity extends XmppActivity {
} else { } else {
loadImageIntoPreview(avatarUri); loadImageIntoPreview(avatarUri);
} }
this.accountTextView.setText(this.account.getJid().toBareJid().toString()); String account;
if (Config.DOMAIN_LOCK != null) {
account = this.account.getJid().getLocalpart();
} else {
account = this.account.getJid().toBareJid().toString();
}
this.accountTextView.setText(account);
} }
} }

View File

@ -289,7 +289,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void toggleContactBlock() { protected void toggleContactBlock() {
final int position = contact_context_id; final int position = contact_context_id;
BlockContactDialog.show(this, xmppConnectionService, (Contact)contacts.get(position)); BlockContactDialog.show(this, xmppConnectionService, (Contact) contacts.get(position));
} }
protected void deleteContact() { protected void deleteContact() {
@ -299,7 +299,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.action_delete_contact); builder.setTitle(R.string.action_delete_contact);
builder.setMessage(getString(R.string.remove_contact_text, builder.setMessage(getString(R.string.remove_contact_text,
contact.getJid())); contact.getJid()));
builder.setPositiveButton(R.string.delete, new OnClickListener() { builder.setPositiveButton(R.string.delete, new OnClickListener() {
@Override @Override
@ -319,7 +319,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.delete_bookmark); builder.setTitle(R.string.delete_bookmark);
builder.setMessage(getString(R.string.remove_bookmark_text, builder.setMessage(getString(R.string.remove_bookmark_text,
bookmark.getJid())); bookmark.getJid()));
builder.setPositiveButton(R.string.delete, new OnClickListener() { builder.setPositiveButton(R.string.delete, new OnClickListener() {
@Override @Override
@ -368,7 +368,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
final Jid accountJid; final Jid accountJid;
try { try {
accountJid = Jid.fromString((String) spinner.getSelectedItem()); if (Config.DOMAIN_LOCK != null) {
accountJid = Jid.fromParts((String) spinner.getSelectedItem(),Config.DOMAIN_LOCK,null);
} else {
accountJid = Jid.fromString((String) spinner.getSelectedItem());
}
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
return; return;
} }
@ -379,8 +383,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
jid.setError(getString(R.string.invalid_jid)); jid.setError(getString(R.string.invalid_jid));
return; return;
} }
final Account account = xmppConnectionService final Account account = xmppConnectionService.findAccountByJid(accountJid);
.findAccountByJid(accountJid);
if (account == null) { if (account == null) {
dialog.dismiss(); dialog.dismiss();
return; return;
@ -428,7 +431,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
final Jid accountJid; final Jid accountJid;
try { try {
accountJid = Jid.fromString((String) spinner.getSelectedItem()); if (Config.DOMAIN_LOCK != null) {
accountJid = Jid.fromParts((String) spinner.getSelectedItem(),Config.DOMAIN_LOCK,null);
} else {
accountJid = Jid.fromString((String) spinner.getSelectedItem());
}
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
return; return;
} }
@ -576,7 +583,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
this.mActivatedAccounts.clear(); this.mActivatedAccounts.clear();
for (Account account : xmppConnectionService.getAccounts()) { for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) { if (account.getStatus() != Account.State.DISABLED) {
this.mActivatedAccounts.add(account.getJid().toBareJid().toString()); if (Config.DOMAIN_LOCK != null) {
this.mActivatedAccounts.add(account.getJid().getLocalpart());
} else {
this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
}
} }
} }
final Intent intent = getIntent(); final Intent intent = getIntent();

View File

@ -11,6 +11,7 @@ import android.widget.TextView;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.ManageAccountActivity;
@ -35,7 +36,11 @@ public class AccountAdapter extends ArrayAdapter<Account> {
view = inflater.inflate(R.layout.account_row, parent, false); view = inflater.inflate(R.layout.account_row, parent, false);
} }
TextView jid = (TextView) view.findViewById(R.id.account_jid); TextView jid = (TextView) view.findViewById(R.id.account_jid);
jid.setText(account.getJid().toBareJid().toString()); if (Config.DOMAIN_LOCK != null) {
jid.setText(account.getJid().getLocalpart());
} else {
jid.setText(account.getJid().toBareJid().toString());
}
TextView statusView = (TextView) view.findViewById(R.id.account_status); TextView statusView = (TextView) view.findViewById(R.id.account_status);
ImageView imageView = (ImageView) view.findViewById(R.id.account_image); ImageView imageView = (ImageView) view.findViewById(R.id.account_image);
imageView.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48))); imageView.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));

View File

@ -42,6 +42,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_toRightOf="@+id/avater"> android:layout_toRightOf="@+id/avater">
<TextView <TextView
android:id="@+id/account_jid_label"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/account_settings_jabber_id" android:text="@string/account_settings_jabber_id"

View File

@ -499,4 +499,7 @@
<string name="search_for_contacts_or_groups">Search for contacts or groups</string> <string name="search_for_contacts_or_groups">Search for contacts or groups</string>
<string name="send_private_message">Send private message</string> <string name="send_private_message">Send private message</string>
<string name="user_has_left_conference">%s has left the conference!</string> <string name="user_has_left_conference">%s has left the conference!</string>
<string name="username">Username</string>
<string name="username_hint">Username</string>
<string name="invalid_username">This is not a valid username</string>
</resources> </resources>