use of org.storymaker.app.model.Auth in project storymaker by StoryMaker.
the class AccountsActivity method addChooseAccountFragment.
public void addChooseAccountFragment(Bundle bundle) {
FragmentManager fragManager = getSupportFragmentManager();
FragmentTransaction fragTrans = fragManager.beginTransaction();
List<Account> accounts = new ArrayList<>();
final AuthTable authTable = new AuthTable();
String[] siteAvailableNames = Account.CONTROLLER_SITE_NAMES;
String[] siteAvailableKeys = Account.CONTROLLER_SITE_KEYS;
Auth auth;
for (int i = 0; i < siteAvailableKeys.length; i++) {
auth = authTable.getAuthDefault(this, siteAvailableKeys[i]);
if (auth == null) {
accounts.add(new Account(-1, siteAvailableNames[i], siteAvailableKeys[i], "", "", null, false, false));
} else {
accounts.add(auth.convertToAccountObject());
}
}
caFragment = new ChooseAccountFragment();
caFragment.setArguments(bundle);
caFragment.setLoginIntent(new Intent(this, ConnectAccountActivity.class));
// FIXME we should probably make Account object parcelable and pass this through the bundle
caFragment.setAccountsList(accounts);
caFragment.setOnEventListener(new SiteController.OnEventListener() {
@Override
public void onSuccess(Account account) {
Auth auth = authTable.getAuthDefault(getApplicationContext(), account.getSite());
//if auth doesn't exist in db
if (auth == null) {
auth = new Auth(getApplicationContext(), -1, account.getName(), account.getSite(), null, null, null, null, null);
auth.insert();
}
//set id of account based on returned id of auth insert
account.setId(auth.getId());
auth.setCredentials(account.getCredentials());
auth.setData(account.getData());
auth.setUserName(account.getUserName());
auth.setExpires(null);
authTable.updateLastLogin(getApplicationContext(), account.getSite(), auth.getUserName());
auth.update();
}
@Override
public void onFailure(Account account, String failureMessage) {
Auth auth = authTable.getAuthDefault(getApplicationContext(), account.getSite());
if (auth != null) {
//TODO set variables here
auth.setCredentials(account.getCredentials());
auth.setUserName(account.getName());
auth.setData(account.getData());
// FIXME this is a hack to get isValid to fail, probably should be a setFailed() in auth that marks that we are busted
auth.setExpires(new Date());
auth.update();
}
}
@Override
public void onRemove(Account account) {
authTable.delete(getApplicationContext(), account.getId());
}
});
fragTrans.add(R.id.fragmentLayout, caFragment);
fragTrans.commit();
}
use of org.storymaker.app.model.Auth in project storymaker by StoryMaker.
the class PublishFragment method uploadClicked.
private void uploadClicked() {
PublishProfile pubProf = null;
if (mStoryPathInstance != null) {
pubProf = mStoryPathInstance.getPublishProfile();
}
if (pubProf != null && pubProf.getUploadSiteKeys() != null && pubProf.getUploadSiteKeys().size() > 0) {
// FIXME we should do this more robustly
boolean isUserLoggedIntoSM = false;
Auth storymakerAuth = (new AuthTable()).getAuthDefault(getActivity(), Auth.SITE_STORYMAKER);
if (storymakerAuth != null) {
// FIXME we should check a little more carefully if the auth credentials are valid
isUserLoggedIntoSM = true;
}
if (!isUserLoggedIntoSM) {
Intent i = new Intent(getActivity(), ConnectAccountActivity.class);
getActivity().startActivity(i);
}
// FIXME in this case it should just use the sharedprefs value
useTor = true;
// FIXME what if no uploadsitekeys are defined
mSiteKeys = pubProf.getUploadSiteKeys().toArray(new String[pubProf.getUploadSiteKeys().size()]);
publishToStoryMaker = (pubProf.getPublishSiteKeys().size() > 0 && pubProf.getPublishSiteKeys().get(0).equals("storymaker"));
// shareAuthor = intent.getBooleanExtra(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_AUTHOR, false);
// shareTitle = intent.getBooleanExtra(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_TITLE, false);
// shareTags = intent.getBooleanExtra(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_TAGS, false);
// shareDescription = intent.getBooleanExtra(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_DESCRIPTION, false);
// shareLocation = intent.getBooleanExtra(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_LOCATION, false);
// licenseUrl = intent.getStringExtra(ArchiveMetadataActivity.INTENT_EXTRA_LICENSE_URL);
startPublish();
} else {
launchChooseAccountsDialog();
}
}
use of org.storymaker.app.model.Auth in project storymaker by StoryMaker.
the class ServerManager method connect.
private // MalformedURLException, XmlRpcFault
void connect() throws // MalformedURLException, XmlRpcFault
IOException {
//if (mWordpress == null)
if (smWrapper == null) {
Auth auth = (new AuthTable()).getAuthDefault(mContext, Auth.SITE_STORYMAKER);
if (auth != null) {
String user = auth.getUserName();
String pass = auth.getCredentials();
if (user != null && user.length() > 0) {
connect(user, pass);
return;
}
}
Timber.e("connect() bailing out, user credentials are null or blank");
}
}
use of org.storymaker.app.model.Auth in project storymaker by StoryMaker.
the class ServerManager method logOut.
/**
* Log a user out of their StoryMaker account
*/
public void logOut() {
Auth checkAuth = (new AuthTable()).getAuthDefault(mContext, Auth.SITE_STORYMAKER);
// credentials should be deleted instead of expired
checkAuth.delete();
}
use of org.storymaker.app.model.Auth in project storymaker by StoryMaker.
the class ServerManager method post.
public // XmlRpcFault, MalformedURLException
String post(// XmlRpcFault, MalformedURLException
String title, // XmlRpcFault, MalformedURLException
String body, // XmlRpcFault, MalformedURLException
String embed, // XmlRpcFault, MalformedURLException
String[] catstrings, // XmlRpcFault, MalformedURLException
String medium, // XmlRpcFault, MalformedURLException
String mediaService, // XmlRpcFault, MalformedURLException
String mediaGuid, // XmlRpcFault, MalformedURLException
String mimeType, // XmlRpcFault, MalformedURLException
File file) throws // XmlRpcFault, MalformedURLException
IOException {
connect();
// need user name for group id
Auth auth = (new AuthTable()).getAuthDefault(mContext, Auth.SITE_STORYMAKER);
if (auth != null) {
String user = auth.getUserName();
if (user != null && user.length() > 0) {
return smWrapper.post(user, title, body, embed, catstrings, medium, mediaService, mediaGuid, mimeType, file);
}
}
Timber.e("can't post, no user name found");
return null;
}
Aggregations