Search in sources :

Example 11 with AuthTable

use of org.storymaker.app.model.AuthTable 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 12 with AuthTable

use of org.storymaker.app.model.AuthTable 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 13 with AuthTable

use of org.storymaker.app.model.AuthTable 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 14 with AuthTable

use of org.storymaker.app.model.AuthTable 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)

Example 15 with AuthTable

use of org.storymaker.app.model.AuthTable in project storymaker by StoryMaker.

the class ServerManager method index.

// NEW/TEMP
// DOWNLOAD AVAILABE INDEX FOR CURRENT USER AND SAVE TO TARGET FILE
// RETURN TRUE IF SUCCESSFUL
public boolean index() {
    try {
        connect();
    } catch (IOException ioe) {
        Timber.e("UNABLE TO CONNECT TO SERVER, CAN'T GET INDEX");
        return false;
    }
    // TODO: IF ENDPOINT ONLY REQUIRES TOKEN, DO WE CARE ABOUT AUTH/USER?
    Auth auth = (new AuthTable()).getAuthDefault(mContext, Auth.SITE_STORYMAKER);
    if (auth != null) {
        String user = auth.getUserName();
        if (user != null && user.length() > 0) {
            // load baseline index
            HashMap<String, ExpansionIndexItem> contentItems = IndexManager.loadAvailableOrderIndex(mContext);
            // download users index
            // TODO: WHERE IS INTERFACE VERSION SPECIFIED?
            JSONArray jArray = smWrapper.index(1);
            if (jArray == null) {
                Timber.e("FAILED TO DOWNLOAD NEW ASSIGNMENTS");
                return false;
            }
            if (jArray.length() == 0) {
                Timber.d("NO ASSIGNMENTS FOUND, INDEX WILL NOT BE UPDATED");
                return true;
            }
            // convert items and add to index
            for (int i = 0; i < jArray.length(); i++) {
                try {
                    JSONObject jObject = jArray.getJSONObject(i);
                    String filePath = "Android/data/" + mContext.getPackageName() + "/files/";
                    ExpansionIndexItem contentItem = new // packageName
                    ExpansionIndexItem(// packageName
                    jObject.getString("organization"), // expansionId
                    jObject.getString("uuid"), Integer.parseInt(jObject.getString("sortOrder")), // patchOrder (using arbitrary negative value to avoid collisions with existing items
                    "" + (-1 - i), jObject.getString("contentType"), // expansionFileVersion
                    "" + jObject.getInt("version"), // expansionFilePath
                    filePath, // expansionFileUrl - obb filename
                    jObject.getString("obb_file").substring(0, jObject.getString("obb_file").lastIndexOf("/") + 1), // expansionThumbnail
                    jObject.getString("thumbnail_path"));
                    contentItem.setTitle(jObject.getString("title"));
                    contentItem.setDescription(jObject.getString("description"));
                    contentItem.setExpansionFileSize(jObject.getLong("size"));
                    contentItem.setExpansionFileChecksum(jObject.getString("obb_checksum"));
                    contentItem.setDateUpdated(jObject.getString("updated"));
                    contentItems.put(contentItem.getPatchOrder(), contentItem);
                    Timber.d("ADDED ITEM TO INDEX (" + contentItem.getTitle() + ")");
                } catch (JSONException je) {
                    Timber.e("FAILED TO EXTRACT VALUE FROM JSON OBJECT (ARRAY ELEMENT " + i + "): " + je.getMessage());
                }
            }
            IndexManager.saveAvailableIndex(mContext, contentItems);
            Timber.d("SAVED UPDATED INDEX");
            return true;
        } else {
            Timber.e("NO USER NAME");
        }
    } else {
        Timber.e("NOT LOGGED IN");
    }
    Timber.e("CAN'T DOWNLOAD NEW ASSIGNMENTS");
    return false;
}
Also used : JSONObject(org.json.JSONObject) Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable) JSONArray(org.json.JSONArray) ExpansionIndexItem(scal.io.liger.model.ExpansionIndexItem) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

AuthTable (org.storymaker.app.model.AuthTable)18 Auth (org.storymaker.app.model.Auth)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 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)4 AudioClipTable (org.storymaker.app.model.AudioClipTable)4 JobTable (org.storymaker.app.model.JobTable)4 LessonTable (org.storymaker.app.model.LessonTable)4 MediaTable (org.storymaker.app.model.MediaTable)4 ProjectTable (org.storymaker.app.model.ProjectTable)4 PublishJobTable (org.storymaker.app.model.PublishJobTable)4 SceneTable (org.storymaker.app.model.SceneTable)4 TagTable (org.storymaker.app.model.TagTable)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)2 Nullable (android.support.annotation.Nullable)2 Date (java.util.Date)2