Search in sources :

Example 6 with Auth

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();
}
Also used : Account(io.scal.secureshare.model.Account) ChooseAccountFragment(io.scal.secureshare.lib.ChooseAccountFragment) AuthTable(org.storymaker.app.model.AuthTable) ArrayList(java.util.ArrayList) Intent(android.content.Intent) SiteController(io.scal.secureshare.controller.SiteController) Date(java.util.Date) FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Auth(org.storymaker.app.model.Auth)

Example 7 with Auth

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();
    }
}
Also used : PublishProfile(scal.io.liger.model.PublishProfile) Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable) Intent(android.content.Intent)

Example 8 with Auth

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");
    }
}
Also used : Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable)

Example 9 with Auth

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();
}
Also used : Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable)

Example 10 with Auth

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;
}
Also used : Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable)

Aggregations

Auth (org.storymaker.app.model.Auth)14 AuthTable (org.storymaker.app.model.AuthTable)14 SiteController (io.scal.secureshare.controller.SiteController)6 Project (org.storymaker.app.model.Project)6 PublishJob (org.storymaker.app.model.PublishJob)6 Handler (android.os.Handler)4 File (java.io.File)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)2 Date (java.util.Date)2 Media (org.storymaker.app.model.Media)2 Bundle (android.os.Bundle)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 ArchiveSiteController (io.scal.secureshare.controller.ArchiveSiteController)1 FacebookSiteController (io.scal.secureshare.controller.FacebookSiteController)1 FlickrSiteController (io.scal.secureshare.controller.FlickrSiteController)1 SSHSiteController (io.scal.secureshare.controller.SSHSiteController)1 SoundCloudSiteController (io.scal.secureshare.controller.SoundCloudSiteController)1 ChooseAccountFragment (io.scal.secureshare.lib.ChooseAccountFragment)1