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();
}
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);
}
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();
}
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;
}
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;
}
Aggregations