User authentication in Omeka scripts

46 views
Skip to first unread message

Jim Safley

unread,
Jul 13, 2011, 10:23:36 PM7/13/11
to Omeka Dev
I'm writing a script that partially loads Omeka so I can access its
API. Everything works until I try to get a non-public collection using
$db->getTable('Collection')->find(1). That returns NULL because the
database adapter automatically adds "WHERE (c.public = 1)" to the SQL,
perhaps because there is no authenticated user. I tried getting around
this by setting the identity and credentials of a superuser and
passing them to the Auth resource. The resulting message says,
"Authentication successful," but the SQL is still being overwritten,
possibly because authentication is stored in a session, which is not
available in a non-browser environment.

My question is this: when partially loading Omeka, how do I trick it
into thinking that I'm an authenticated user?

Kris Kelly

unread,
Jul 14, 2011, 10:05:01 AM7/14/11
to omek...@googlegroups.com
Two options for this:

1) Don't bootstrap the ACL. If you don't need the ACL for your shell-bound php script, then skipping that ought to ensure that none of those weird SQL clauses show up.

2) Try something like this in your script:

// Decide which user to authenticate
$user = $db->getTable('User')->find($id);
Omeka_Context::getInstance()->currentuser = $user;
// Now do everything else.

Kris

> --
> You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
> To post to this group, send email to omek...@googlegroups.com.
> To unsubscribe from this group, send email to omeka-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/omeka-dev?hl=en.
>

Reply all
Reply to author
Forward
0 new messages