Search in sources :

Example 6 with AuthTable

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

the class LoginActivity method saveCreds.

private void saveCreds(String user, String pass) {
    ArrayList<Auth> results = (new AuthTable()).getAuthsAsList(getApplicationContext(), Auth.SITE_STORYMAKER);
    for (Auth deleteAuth : results) {
        // only a single username/password is stored at a time
        deleteAuth.delete();
    }
    Auth storymakerAuth = new Auth(getApplicationContext(), "StoryMaker.cc", Auth.SITE_STORYMAKER, user, pass, null, null, new Date());
    storymakerAuth.save();
}
Also used : AuthTable(org.storymaker.app.model.AuthTable) Auth(org.storymaker.app.model.Auth) Date(java.util.Date)

Example 7 with AuthTable

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

the class AccountsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getIntent().getBooleanExtra("isDialog", false)) {
        setTheme(android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);
    }
    setContentView(R.layout.activity_accounts);
    boolean isUserLoggedIntoSM = false;
    Auth storymakerAuth = (new AuthTable()).getAuthDefault(getApplicationContext(), Auth.SITE_STORYMAKER);
    if (storymakerAuth != null) {
        // FIXME we should check a little more carefully if the auth credentials are valid
        isUserLoggedIntoSM = true;
    }
    Bundle bundle = null;
    Intent intent = getIntent();
    bundle = new Bundle();
    bundle.putBoolean("isDialog", intent.getBooleanExtra("isDialog", false));
    bundle.putBoolean("inSelectionMode", intent.getBooleanExtra("inSelectionMode", false));
    bundle.putBoolean("isUserLoggedIntoSM", isUserLoggedIntoSM);
    addChooseAccountFragment(bundle);
}
Also used : Bundle(android.os.Bundle) Auth(org.storymaker.app.model.Auth) AuthTable(org.storymaker.app.model.AuthTable) Intent(android.content.Intent)

Example 8 with AuthTable

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

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

the class ProjectsProvider method delete.

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    mCacheWordHandler.connectToService();
    setTimer(60000);
    SQLiteDatabase db = getDB();
    if (db != null) {
        int uriType = sURIMatcher.match(uri);
        switch(uriType) {
            case PROJECTS:
            case PROJECT_ID:
                return (new ProjectTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case SCENES:
            case SCENE_ID:
                return (new SceneTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case LESSONS:
            case LESSON_ID:
                return (new LessonTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case MEDIA:
            case MEDIA_ID:
                return (new MediaTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case AUTH:
            case AUTH_ID:
                return (new AuthTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case TAGS:
            case TAG_ID:
            case DISTINCT_TAGS:
            case DISTINCT_TAG_ID:
                return (new TagTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case JOBS:
            case JOB_ID:
                return (new JobTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case PUBLISH_JOBS:
            case PUBLISH_JOB_ID:
                return (new PublishJobTable(db)).delete(getContext(), uri, selection, selectionArgs);
            case AUDIO_CLIPS:
            case AUDIO_CLIP_ID:
                return (new AudioClipTable(db)).delete(getContext(), uri, selection, selectionArgs);
            default:
                throw new IllegalArgumentException("Unknown URI");
        }
    }
    return 0;
}
Also used : SceneTable(org.storymaker.app.model.SceneTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) JobTable(org.storymaker.app.model.JobTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) MediaTable(org.storymaker.app.model.MediaTable) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) AudioClipTable(org.storymaker.app.model.AudioClipTable) AuthTable(org.storymaker.app.model.AuthTable) TagTable(org.storymaker.app.model.TagTable) ProjectTable(org.storymaker.app.model.ProjectTable) LessonTable(org.storymaker.app.model.LessonTable)

Example 10 with AuthTable

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

the class ProjectsProvider method insert.

@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
    mCacheWordHandler.connectToService();
    setTimer(60000);
    SQLiteDatabase db = getDB();
    if (db != null) {
        long newId;
        int uriType = sURIMatcher.match(uri);
        switch(uriType) {
            case PROJECTS:
                return (new ProjectTable(db)).insert(getContext(), uri, values);
            case SCENES:
                return (new SceneTable(db)).insert(getContext(), uri, values);
            case LESSONS:
                return (new LessonTable(db)).insert(getContext(), uri, values);
            case MEDIA:
                return (new MediaTable(db)).insert(getContext(), uri, values);
            case AUTH:
                return (new AuthTable(db)).insert(getContext(), uri, values);
            case TAGS:
            case DISTINCT_TAGS:
                return (new TagTable(db)).insert(getContext(), uri, values);
            case JOBS:
                return (new JobTable(db)).insert(getContext(), uri, values);
            case PUBLISH_JOBS:
                return (new PublishJobTable(db)).insert(getContext(), uri, values);
            case AUDIO_CLIPS:
                return (new AudioClipTable(db)).insert(getContext(), uri, values);
            default:
                throw new IllegalArgumentException("Unknown URI");
        }
    }
    return null;
}
Also used : PublishJobTable(org.storymaker.app.model.PublishJobTable) JobTable(org.storymaker.app.model.JobTable) MediaTable(org.storymaker.app.model.MediaTable) AuthTable(org.storymaker.app.model.AuthTable) LessonTable(org.storymaker.app.model.LessonTable) SceneTable(org.storymaker.app.model.SceneTable) PublishJobTable(org.storymaker.app.model.PublishJobTable) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) AudioClipTable(org.storymaker.app.model.AudioClipTable) TagTable(org.storymaker.app.model.TagTable) ProjectTable(org.storymaker.app.model.ProjectTable) Nullable(android.support.annotation.Nullable)

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