Add ability to change password on server

Fixes #260
This commit is contained in:
Sam Whited 2014-12-23 17:19:00 -05:00 committed by Daniel Gultsch
parent 2081c1bef7
commit e4d9dca2fe
9 changed files with 139 additions and 88 deletions

View File

@ -10,6 +10,7 @@ import net.java.otr4j.crypto.OtrCryptoException;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.security.PublicKey;
import java.security.interfaces.DSAPublicKey; import java.security.interfaces.DSAPublicKey;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -152,7 +153,7 @@ public class Account extends AbstractEntity {
this.avatar = avatar; this.avatar = avatar;
} }
public static Account fromCursor(Cursor cursor) { public static Account fromCursor(final Cursor cursor) {
Jid jid = null; Jid jid = null;
try { try {
jid = Jid.fromParts(cursor.getString(cursor.getColumnIndex(USERNAME)), jid = Jid.fromParts(cursor.getString(cursor.getColumnIndex(USERNAME)),
@ -168,11 +169,11 @@ public class Account extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(AVATAR))); cursor.getString(cursor.getColumnIndex(AVATAR)));
} }
public boolean isOptionSet(int option) { public boolean isOptionSet(final int option) {
return ((options & (1 << option)) != 0); return ((options & (1 << option)) != 0);
} }
public void setOption(int option, boolean value) { public void setOption(final int option, final boolean value) {
if (value) { if (value) {
this.options |= 1 << option; this.options |= 1 << option;
} else { } else {
@ -243,34 +244,18 @@ public class Account extends AbstractEntity {
return keys; return keys;
} }
public String getSSLFingerprint() { public boolean setKey(final String keyName, final String keyValue) {
if (keys.has("ssl_cert")) {
try {
return keys.getString("ssl_cert");
} catch (JSONException e) {
return null;
}
} else {
return null;
}
}
public void setSSLCertFingerprint(String fingerprint) {
this.setKey("ssl_cert", fingerprint);
}
public boolean setKey(String keyName, String keyValue) {
try { try {
this.keys.put(keyName, keyValue); this.keys.put(keyName, keyValue);
return true; return true;
} catch (JSONException e) { } catch (final JSONException e) {
return false; return false;
} }
} }
@Override @Override
public ContentValues getContentValues() { public ContentValues getContentValues() {
ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
values.put(UUID, uuid); values.put(UUID, uuid);
values.put(USERNAME, jid.getLocalpart()); values.put(USERNAME, jid.getLocalpart());
values.put(SERVER, jid.getDomainpart()); values.put(SERVER, jid.getDomainpart());
@ -304,8 +289,8 @@ public class Account extends AbstractEntity {
if (this.otrEngine == null) { if (this.otrEngine == null) {
return null; return null;
} }
DSAPublicKey publicKey = (DSAPublicKey) this.otrEngine.getPublicKey(); final PublicKey publicKey = this.otrEngine.getPublicKey();
if (publicKey == null) { if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
return null; return null;
} }
this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey); this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey);
@ -338,7 +323,7 @@ public class Account extends AbstractEntity {
if (keys.has("pgp_signature")) { if (keys.has("pgp_signature")) {
try { try {
return keys.getString("pgp_signature"); return keys.getString("pgp_signature");
} catch (JSONException e) { } catch (final JSONException e) {
return null; return null;
} }
} else { } else {
@ -359,7 +344,7 @@ public class Account extends AbstractEntity {
} }
public boolean hasBookmarkFor(final Jid conferenceJid) { public boolean hasBookmarkFor(final Jid conferenceJid) {
for (Bookmark bookmark : this.bookmarks) { for (final Bookmark bookmark : this.bookmarks) {
final Jid jid = bookmark.getJid(); final Jid jid = bookmark.getJid();
if (jid != null && jid.equals(conferenceJid.toBareJid())) { if (jid != null && jid.equals(conferenceJid.toBareJid())) {
return true; return true;
@ -368,7 +353,7 @@ public class Account extends AbstractEntity {
return false; return false;
} }
public boolean setAvatar(String filename) { public boolean setAvatar(final String filename) {
if (this.avatar != null && this.avatar.equals(filename)) { if (this.avatar != null && this.avatar.equals(filename)) {
return false; return false;
} else { } else {
@ -395,7 +380,7 @@ public class Account extends AbstractEntity {
} }
public String getShareableUri() { public String getShareableUri() {
String fingerprint = this.getOtrFingerprint(); final String fingerprint = this.getOtrFingerprint();
if (fingerprint != null) { if (fingerprint != null) {
return "xmpp:" + this.getJid().toBareJid().toString() + "?otr-fingerprint="+fingerprint; return "xmpp:" + this.getJid().toBareJid().toString() + "?otr-fingerprint="+fingerprint;
} else { } else {
@ -419,4 +404,8 @@ public class Account extends AbstractEntity {
public void clearBlocklist() { public void clearBlocklist() {
getBlocklist().clear(); getBlocklist().clear();
} }
public boolean isOnlineAndConnected() {
return this.getStatus() == State.ONLINE && this.getXmppConnection() != null;
}
} }

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.MessageArchiveService;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.Xmlns; import eu.siacs.conversations.utils.Xmlns;
@ -117,7 +118,6 @@ public class IqGenerator extends AbstractGenerator {
} }
return packet; return packet;
} }
public IqPacket generateGetBlockList() { public IqPacket generateGetBlockList() {
final IqPacket iq = new IqPacket(IqPacket.TYPE_GET); final IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
iq.addChild("blocklist", Xmlns.BLOCKING); iq.addChild("blocklist", Xmlns.BLOCKING);
@ -138,4 +138,14 @@ public class IqGenerator extends AbstractGenerator {
block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); block.addChild("item").setAttribute("jid", jid.toBareJid().toString());
return iq; return iq;
} }
public IqPacket generateSetPassword(final Account account, final String newPassword) {
final IqPacket packet = new IqPacket(IqPacket.TYPE_SET);
packet.setTo(account.getServer());
final Element query = packet.addChild("query", Xmlns.REGISTER);
final Jid jid = account.getJid();
query.addChild("username").setContent(jid.isDomainJid() ? jid.toString() : jid.getLocalpart());
query.addChild("password").setContent(newPassword);
return packet;
}
} }

View File

@ -222,7 +222,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private OnMucRosterUpdate mOnMucRosterUpdate = null; private OnMucRosterUpdate mOnMucRosterUpdate = null;
private int mucRosterChangedListenerCount = 0; private int mucRosterChangedListenerCount = 0;
private SecureRandom mRandom; private SecureRandom mRandom;
private FileObserver fileObserver = new FileObserver( private final FileObserver fileObserver = new FileObserver(
FileBackend.getConversationsImageDirectory()) { FileBackend.getConversationsImageDirectory()) {
@Override @Override
@ -232,7 +232,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
}; };
private OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() { private final OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
@Override @Override
public void onJinglePacketReceived(Account account, JinglePacket packet) { public void onJinglePacketReceived(Account account, JinglePacket packet) {
@ -246,7 +246,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
private PendingIntent pendingPingIntent = null; private PendingIntent pendingPingIntent = null;
private WakeLock wakeLock; private WakeLock wakeLock;
private PowerManager pm; private PowerManager pm;
private OnBindListener mOnBindListener = new OnBindListener() { private final OnBindListener mOnBindListener = new OnBindListener() {
@Override @Override
public void onBind(final Account account) { public void onBind(final Account account) {
@ -261,7 +261,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
}; };
private OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() { private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() {
@Override @Override
public void onMessageAcknowledged(Account account, String uuid) { public void onMessageAcknowledged(Account account, String uuid) {
@ -279,7 +279,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
}; };
private LruCache<String, Bitmap> mBitmapCache; private LruCache<String, Bitmap> mBitmapCache;
private IqGenerator mIqGenerator = new IqGenerator(this); private final IqGenerator mIqGenerator = new IqGenerator(this);
private Thread mPhoneContactMergerThread; private Thread mPhoneContactMergerThread;
public PgpEngine getPgpEngine() { public PgpEngine getPgpEngine() {
@ -304,7 +304,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return this.mAvatarService; return this.mAvatarService;
} }
public void attachFileToConversation(Conversation conversation, final Uri uri, final UiCallback<Message> callback) { public void attachFileToConversation(final Conversation conversation,
final Uri uri,
final UiCallback<Message> callback) {
final Message message; final Message message;
if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) { if (conversation.getNextEncryption(forceEncryption()) == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", message = new Message(conversation, "",
@ -1082,7 +1084,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} }
} }
public void createAccount(Account account) { public void createAccount(final Account account) {
account.initOtrEngine(this); account.initOtrEngine(this);
databaseBackend.createAccount(account); databaseBackend.createAccount(account);
this.accounts.add(account); this.accounts.add(account);
@ -1090,7 +1092,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
updateAccountUi(); updateAccountUi();
} }
public void updateAccount(Account account) { public void updateAccount(final Account account) {
this.statusListener.onStatusChanged(account); this.statusListener.onStatusChanged(account);
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
reconnectAccount(account, false); reconnectAccount(account, false);
@ -1098,9 +1100,24 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
getNotificationService().updateErrorNotification(); getNotificationService().updateErrorNotification();
} }
public void deleteAccount(Account account) { public void updateAccountPasswordOnServer(final Account account, final String newPassword) {
if (account.isOnlineAndConnected()) {
final IqPacket iq = getIqGenerator().generateSetPassword(account, newPassword);
sendIqPacket(account, iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE_RESULT) {
account.setPassword(newPassword);
updateAccount(account);
}
}
});
}
}
public void deleteAccount(final Account account) {
synchronized (this.conversations) { synchronized (this.conversations) {
for (Conversation conversation : conversations) { for (final Conversation conversation : conversations) {
if (conversation.getAccount() == account) { if (conversation.getAccount() == account) {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
leaveMuc(conversation); leaveMuc(conversation);

View File

@ -318,7 +318,7 @@ public class ConversationActivity extends XmppActivity
menuUnblock.setVisible(false); menuUnblock.setVisible(false);
} }
final Account account = this.getSelectedConversation().getAccount(); final Account account = this.getSelectedConversation().getAccount();
if (account.getStatus() != Account.State.ONLINE || !account.getXmppConnection().getFeatures().blocking()) { if (account.isOnlineAndConnected() || !account.getXmppConnection().getFeatures().blocking()) {
menuBlock.setVisible(false); menuBlock.setVisible(false);
menuUnblock.setVisible(false); menuUnblock.setVisible(false);
} }

View File

@ -40,6 +40,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private EditText mPassword; private EditText mPassword;
private EditText mPasswordConfirm; private EditText mPasswordConfirm;
private CheckBox mRegisterNew; private CheckBox mRegisterNew;
private CheckBox mChangePassword;
private Button mCancelButton; private Button mCancelButton;
private Button mSaveButton; private Button mSaveButton;
private TableLayout mMoreTable; private TableLayout mMoreTable;
@ -63,7 +64,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private boolean mFetchingAvatar = false; private boolean mFetchingAvatar = false;
private OnClickListener mSaveButtonClickListener = new OnClickListener() { private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
@Override @Override
public void onClick(final View v) { public void onClick(final View v) {
@ -74,6 +75,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
return; return;
} }
final boolean registerNewAccount = mRegisterNew.isChecked(); final boolean registerNewAccount = mRegisterNew.isChecked();
final boolean changePassword = mChangePassword.isChecked();
final Jid jid; final Jid jid;
try { try {
jid = Jid.fromString(mAccountJid.getText().toString()); jid = Jid.fromString(mAccountJid.getText().toString());
@ -89,7 +91,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
final String password = mPassword.getText().toString(); final String password = mPassword.getText().toString();
final String passwordConfirm = mPasswordConfirm.getText().toString(); final String passwordConfirm = mPasswordConfirm.getText().toString();
if (registerNewAccount) { if (registerNewAccount || changePassword) {
if (!password.equals(passwordConfirm)) { if (!password.equals(passwordConfirm)) {
mPasswordConfirm mPasswordConfirm
.setError(getString(R.string.passwords_do_not_match)); .setError(getString(R.string.passwords_do_not_match));
@ -98,14 +100,22 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
} }
if (mAccount != null) { if (mAccount != null) {
mAccount.setPassword(password);
try { try {
mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : ""); mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : "");
mAccount.setServer(jid.getDomainpart()); mAccount.setServer(jid.getDomainpart());
} catch (final InvalidJidException ignored) { } catch (final InvalidJidException ignored) {
} }
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); if (changePassword) {
xmppConnectionService.updateAccount(mAccount); if (mAccount.isOnlineAndConnected()) {
xmppConnectionService.updateAccountPasswordOnServer(mAccount, mPassword.getText().toString());
} else {
mPassword.setError(getResources().getString(R.string.account_status_no_internet));
}
} else {
mAccount.setPassword(password);
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.updateAccount(mAccount);
}
} else { } else {
try { try {
if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) { if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) {
@ -114,7 +124,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
mAccountJid.requestFocus(); mAccountJid.requestFocus();
return; return;
} }
} catch (InvalidJidException e) { } catch (final InvalidJidException e) {
return; return;
} }
mAccount = new Account(jid.toBareJid(), password); mAccount = new Account(jid.toBareJid(), password);
@ -132,10 +142,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
}; };
private OnClickListener mCancelButtonClickListener = new OnClickListener() { private final OnClickListener mCancelButtonClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(final View v) {
finish(); finish();
} }
}; };
@ -167,47 +177,53 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
}); });
} }
private UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() { private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
@Override @Override
public void userInputRequried(PendingIntent pi, Avatar avatar) { public void userInputRequried(final PendingIntent pi, final Avatar avatar) {
finishInitialSetup(avatar); finishInitialSetup(avatar);
} }
@Override @Override
public void success(Avatar avatar) { public void success(final Avatar avatar) {
finishInitialSetup(avatar); finishInitialSetup(avatar);
} }
@Override @Override
public void error(int errorCode, Avatar avatar) { public void error(final int errorCode, final Avatar avatar) {
finishInitialSetup(avatar); finishInitialSetup(avatar);
} }
}; };
private TextWatcher mTextWatcher = new TextWatcher() { private final TextWatcher mTextWatcher = new TextWatcher() {
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
int count) {
updateSaveButton(); updateSaveButton();
} }
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
int after) {
} }
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(final Editable s) {
final boolean registrationReady = mAccount != null &&
mAccount.isOnlineAndConnected() &&
mAccount.getXmppConnection().getFeatures().register();
if (jidToEdit != null && mAccount != null && registrationReady &&
!mAccount.getPassword().equals(s.toString()) && !"".equals(s.toString())) {
mChangePassword.setVisibility(View.VISIBLE);
} else {
mChangePassword.setVisibility(View.INVISIBLE);
mChangePassword.setChecked(false);
}
} }
}; };
private OnClickListener mAvatarClickListener = new OnClickListener() { private final OnClickListener mAvatarClickListener = new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(final View view) {
if (mAccount!=null) { if (mAccount != null) {
Intent intent = new Intent(getApplicationContext(), final Intent intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class); PublishProfilePictureActivity.class);
intent.putExtra("account", mAccount.getJid().toBareJid().toString()); intent.putExtra("account", mAccount.getJid().toBareJid().toString());
startActivity(intent); startActivity(intent);
@ -220,7 +236,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override @Override
public void run() { public void run() {
Intent intent; final Intent intent;
if (avatar != null) { if (avatar != null) {
intent = new Intent(getApplicationContext(), intent = new Intent(getApplicationContext(),
StartConversationActivity.class); StartConversationActivity.class);
@ -251,8 +267,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mSaveButton.setEnabled(true); this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor()); this.mSaveButton.setTextColor(getPrimaryTextColor());
if (jidToEdit != null) { if (jidToEdit != null) {
if (mAccount != null if (mAccount != null && mAccount.isOnlineAndConnected()) {
&& mAccount.getStatus() == Account.State.ONLINE) {
this.mSaveButton.setText(R.string.save); this.mSaveButton.setText(R.string.save);
if (!accountInfoEdited()) { if (!accountInfoEdited()) {
this.mSaveButton.setEnabled(false); this.mSaveButton.setEnabled(false);
@ -268,7 +283,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
protected boolean accountInfoEdited() { protected boolean accountInfoEdited() {
return (!this.mAccount.getJid().toBareJid().equals( return (!this.mAccount.getJid().toBareJid().toString().equals(
this.mAccountJid.getText().toString())) this.mAccountJid.getText().toString()))
|| (!this.mAccount.getPassword().equals( || (!this.mAccount.getPassword().equals(
this.mPassword.getText().toString())); this.mPassword.getText().toString()));
@ -284,7 +299,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
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);
@ -295,6 +310,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mAvatar = (ImageView) findViewById(R.id.avater); this.mAvatar = (ImageView) findViewById(R.id.avater);
this.mAvatar.setOnClickListener(this.mAvatarClickListener); this.mAvatar.setOnClickListener(this.mAvatarClickListener);
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new); this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
this.mChangePassword = (CheckBox) findViewById(R.id.account_change_password);
this.mStats = (LinearLayout) findViewById(R.id.stats); this.mStats = (LinearLayout) findViewById(R.id.stats);
this.mSessionEst = (TextView) findViewById(R.id.session_est); this.mSessionEst = (TextView) findViewById(R.id.session_est);
this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version); this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
@ -312,20 +328,20 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener); this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener); this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener);
this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more); this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more);
this.mRegisterNew final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(final CompoundButton buttonView,
@Override final boolean isChecked) {
public void onCheckedChanged(CompoundButton buttonView, if (isChecked) {
boolean isChecked) { mPasswordConfirm.setVisibility(View.VISIBLE);
if (isChecked) { } else {
mPasswordConfirm.setVisibility(View.VISIBLE); mPasswordConfirm.setVisibility(View.GONE);
} else {
mPasswordConfirm.setVisibility(View.GONE);
}
updateSaveButton();
} }
}); updateSaveButton();
}
};
this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
this.mChangePassword.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
} }
@Override @Override
@ -340,8 +356,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
showBlocklist.setVisible(false); showBlocklist.setVisible(false);
showMoreInfo.setVisible(false); showMoreInfo.setVisible(false);
} else if (mAccount.getStatus() != Account.State.ONLINE) { } else if (mAccount.getStatus() != Account.State.ONLINE) {
showBlocklist.setVisible(false); showBlocklist.setVisible(false);
showMoreInfo.setVisible(false); showMoreInfo.setVisible(false);
} else if (!mAccount.getXmppConnection().getFeatures().blocking()) { } else if (!mAccount.getXmppConnection().getFeatures().blocking()) {
showBlocklist.setVisible(false); showBlocklist.setVisible(false);
} }
@ -368,6 +384,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
getActionBar().setTitle(R.string.action_add_account); getActionBar().setTitle(R.string.action_add_account);
} }
} }
this.mChangePassword.setVisibility(View.GONE);
this.mChangePassword.setChecked(false);
} }
} }
@ -415,11 +433,15 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} }
if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) { if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) {
this.mRegisterNew.setVisibility(View.VISIBLE); this.mRegisterNew.setVisibility(View.VISIBLE);
this.mChangePassword.setVisibility(View.GONE);
this.mChangePassword.setChecked(false);
this.mRegisterNew.setChecked(true); this.mRegisterNew.setChecked(true);
this.mPasswordConfirm.setText(this.mAccount.getPassword()); this.mPasswordConfirm.setText(this.mAccount.getPassword());
} else { } else {
this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setVisibility(View.GONE);
this.mRegisterNew.setChecked(false); this.mRegisterNew.setChecked(false);
this.mChangePassword.setVisibility(View.GONE);
this.mChangePassword.setChecked(false);
} }
if (this.mAccount.getStatus() == Account.State.ONLINE if (this.mAccount.getStatus() == Account.State.ONLINE
&& !this.mFetchingAvatar) { && !this.mFetchingAvatar) {
@ -474,7 +496,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(final View v) {
if (copyTextToClipboard(fingerprint, R.string.otr_fingerprint)) { if (copyTextToClipboard(fingerprint, R.string.otr_fingerprint)) {
Toast.makeText( Toast.makeText(

View File

@ -3,4 +3,5 @@ package eu.siacs.conversations.utils;
public final class Xmlns { public final class Xmlns {
public static final String BLOCKING = "urn:xmpp:blocking"; public static final String BLOCKING = "urn:xmpp:blocking";
public static final String ROSTER = "jabber:iq:roster"; public static final String ROSTER = "jabber:iq:roster";
public static final String REGISTER = "jabber:iq:register";
} }

View File

@ -1082,6 +1082,10 @@ public class XmppConnection implements Runnable {
return hasDiscoFeature(account.getServer(), Xmlns.BLOCKING); return hasDiscoFeature(account.getServer(), Xmlns.BLOCKING);
} }
public boolean register() {
return hasDiscoFeature(account.getServer(), Xmlns.REGISTER);
}
public boolean sm() { public boolean sm() {
return streamId != null; return streamId != null;
} }

View File

@ -79,6 +79,15 @@
android:textColor="@color/primarytext" android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeBody" /> android:textSize="?attr/TextSizeBody" />
<CheckBox
android:id="@+id/account_change_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/change_password"
android:textColor="@color/primarytext"
android:textSize="?attr/TextSizeBody" />
<TextView <TextView
android:id="@+id/account_confirm_password_desc" android:id="@+id/account_confirm_password_desc"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -336,8 +345,6 @@
android:visibility="visible" android:visibility="visible"
android:contentDescription="@string/copy_otr_clipboard_description"/> android:contentDescription="@string/copy_otr_clipboard_description"/>
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -46,6 +46,7 @@
<string name="contact_blocked">Contact blocked</string> <string name="contact_blocked">Contact blocked</string>
<string name="remove_bookmark_text">Would you like to remove %s as a bookmark? The conversation associated with this bookmark will not be removed.</string> <string name="remove_bookmark_text">Would you like to remove %s as a bookmark? The conversation associated with this bookmark will not be removed.</string>
<string name="register_account">Register new account on server</string> <string name="register_account">Register new account on server</string>
<string name="change_password">Change password</string>
<string name="share_with">Share with</string> <string name="share_with">Share with</string>
<string name="start_conversation">Start Conversation</string> <string name="start_conversation">Start Conversation</string>
<string name="invite_contact">Invite Contact</string> <string name="invite_contact">Invite Contact</string>
@ -249,7 +250,7 @@
<string name="private_message_to">to %s</string> <string name="private_message_to">to %s</string>
<string name="send_private_message_to">Send private message to %s</string> <string name="send_private_message_to">Send private message to %s</string>
<string name="connect">Connect</string> <string name="connect">Connect</string>
<string name="account_already_exists">This account does already exist</string> <string name="account_already_exists">This account already exists</string>
<string name="next">Next</string> <string name="next">Next</string>
<string name="server_info_session_established">Current session established</string> <string name="server_info_session_established">Current session established</string>
<string name="additional_information">Additional Information</string> <string name="additional_information">Additional Information</string>