use of org.awesomeapp.messenger.plugin.xmpp.XmppConnection in project Zom-Android by zom.
the class AccountActivity method createNewAccount.
public void createNewAccount(final String usernameNew, final String passwordNew, final long newAccountId, final boolean useTor) {
if (mCreateAccountTask != null && (!mCreateAccountTask.isCancelled())) {
mCreateAccountTask.cancel(true);
}
mCreateAccountTask = new AsyncTask<Void, Void, String>() {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(AccountActivity.this);
dialog.setCancelable(true);
dialog.setMessage(getString(R.string.registering_new_account_));
dialog.show();
}
@Override
protected String doInBackground(Void... params) {
ContentResolver cr = getContentResolver();
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, mProviderId, false, /* don't keep updated */
null);
try {
settingsForDomain(mDomain, mPort, settings);
HashMap<String, String> aParams = new HashMap<String, String>();
XmppConnection xmppConn = new XmppConnection(AccountActivity.this);
xmppConn.initUser(mProviderId, newAccountId);
xmppConn.registerAccount(settings, usernameNew, passwordNew, aParams);
// settings closed in registerAccount
} catch (Exception e) {
LogCleaner.error(ImApp.LOG_TAG, "error registering new account", e);
return e.getLocalizedMessage();
} finally {
settings.close();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
dialog = null;
}
} catch (java.lang.IllegalArgumentException iae) {
// dialog may not be attached to window if Activity was closed
}
if (result != null) {
Toast.makeText(AccountActivity.this, "error creating account: " + result, Toast.LENGTH_LONG).show();
// AccountActivity.this.setResult(Activity.RESULT_CANCELED);
// AccountActivity.this.finish();
} else {
mSignInHelper.activateAccount(mProviderId, newAccountId);
mSignInHelper.signIn(passwordNew, mProviderId, newAccountId, true);
AccountActivity.this.setResult(Activity.RESULT_OK);
AccountActivity.this.finish();
}
}
}.execute();
}
use of org.awesomeapp.messenger.plugin.xmpp.XmppConnection in project Zom-Android by zom.
the class AccountViewFragment method createNewAccount.
public void createNewAccount(final String usernameNew, final String passwordNew, final long newAccountId, final boolean useTor) {
if (mCreateAccountTask != null && (!mCreateAccountTask.isCancelled())) {
mCreateAccountTask.cancel(true);
}
mCreateAccountTask = new AsyncTask<Void, Void, String>() {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = new ProgressDialog(getActivity());
dialog.setCancelable(true);
dialog.setMessage(getString(R.string.registering_new_account_));
dialog.show();
}
@Override
protected String doInBackground(Void... params) {
ContentResolver cr = getActivity().getContentResolver();
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, mProviderId, false, /* don't keep updated */
null);
try {
settingsForDomain(mDomain, mPort, settings);
HashMap<String, String> aParams = new HashMap<String, String>();
XmppConnection xmppConn = new XmppConnection(getActivity());
xmppConn.initUser(mProviderId, newAccountId);
xmppConn.registerAccount(settings, usernameNew, passwordNew, aParams);
// settings closed in registerAccount
} catch (Exception e) {
LogCleaner.error(ImApp.LOG_TAG, "error registering new account", e);
return e.getLocalizedMessage();
} finally {
settings.close();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
dialog = null;
}
} catch (java.lang.IllegalArgumentException iae) {
// dialog may not be attached to window if Activity was closed
}
if (result != null) {
Toast.makeText(getActivity(), "error creating account: " + result, Toast.LENGTH_LONG).show();
// AccountActivity.this.setResult(Activity.RESULT_CANCELED);
// AccountActivity.this.finish();
} else {
mSignInHelper.activateAccount(mProviderId, newAccountId);
mSignInHelper.signIn(passwordNew, mProviderId, newAccountId, true);
// AccountViewFragment.this.setResult(Activity.RESULT_OK);
// AccountViewFragment.this.finish();
}
}
}.execute();
}
use of org.awesomeapp.messenger.plugin.xmpp.XmppConnection in project Zom-Android by zom.
the class OnboardingManager method changePassword.
public static boolean changePassword(Activity context, long providerId, long accountId, String oldPassword, String newPassword) {
try {
XmppConnection xmppConn = new XmppConnection(context);
xmppConn.initUser(providerId, accountId);
boolean success = xmppConn.changeServerPassword(providerId, accountId, oldPassword, newPassword);
return success;
} catch (Exception e) {
return false;
}
}
use of org.awesomeapp.messenger.plugin.xmpp.XmppConnection in project Zom-Android by zom.
the class OnboardingManager method registerAccount.
public static OnboardingAccount registerAccount(Context context, String nickname, String username, String password, String domain, String server, int port) throws JSONException {
if (password == null)
password = generatePassword();
ContentResolver cr = context.getContentResolver();
ImPluginHelper helper = ImPluginHelper.getInstance(context);
// xmpp FIXME
long providerId = helper.createAdditionalProvider(helper.getProviderNames().get(0));
long accountId = ImApp.insertOrUpdateAccount(cr, providerId, -1, nickname, username, password);
Uri accountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(providerId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, providerId, false, /* don't keep updated */
null);
settings.setRequireTls(true);
settings.setTlsCertVerify(true);
settings.setAllowPlainAuth(false);
try {
settings.setDomain(domain);
settings.setPort(port);
if (server != null) {
// if we have a host, then we should use it
settings.setServer(server);
settings.setDoDnsSrv(false);
} else {
settings.setServer(null);
settings.setDoDnsSrv(true);
}
settings.requery();
HashMap<String, String> aParams = new HashMap<String, String>();
XmppConnection xmppConn = new XmppConnection(context);
xmppConn.initUser(providerId, accountId);
boolean success = xmppConn.registerAccount(settings, username, password, aParams);
if (success) {
OnboardingAccount result = new OnboardingAccount();
result.username = username;
result.domain = domain;
result.password = password;
result.providerId = providerId;
result.accountId = accountId;
result.nickname = nickname;
// now keep this account signed-in
ContentValues values = new ContentValues();
values.put(Imps.AccountColumns.KEEP_SIGNED_IN, 1);
cr.update(accountUri, values, null, null);
settings.close();
return result;
}
} catch (Exception e) {
LogCleaner.error(ImApp.LOG_TAG, "error registering new account", e);
}
ImApp.deleteAccount(context.getContentResolver(), accountId, providerId);
settings.close();
return null;
}
Aggregations