long oilsUtilsIntervalToSeconds( const char* interval );
+/**
+ * Creates actor.usr_activity entries
+ * @return The number of rows created. 0 or 1.
+ */
+int oilsUtilsTrackUserActivity( long usr, const char* ewho, const char* ewhat, const char* ehow );
+
#ifdef __cplusplus
}
#endif
osrfAppRegisterMethod(
MODULENAME,
+ "open-ils.auth.authenticate.verify",
+ "oilsAuthComplete",
+ "Verifies the user provided a valid username and password."
+ "Params and are the same as open-ils.auth.authenticate.complete."
+ "Returns SUCCESS event on success, failure event on failure", 1, 0);
+
+
+ osrfAppRegisterMethod(
+ MODULENAME,
"open-ils.auth.session.retrieve",
"oilsAuthSessionRetrieve",
"Pass in the auth token and this retrieves the user object. The auth "
- "type"
- "org"
- "workstation"
+ - "agent" (what software/interface/3rd-party is making the request)
The password is required. Either a username or a barcode must also be present.
int orgloc = (int) jsonObjectGetNumber(jsonObjectGetKeyConst(args, "org"));
const char* workstation = jsonObjectGetString(jsonObjectGetKeyConst(args, "workstation"));
const char* barcode = jsonObjectGetString(jsonObjectGetKeyConst(args, "barcode"));
+ const char* ewho = jsonObjectGetString(jsonObjectGetKeyConst(args, "agent"));
const char* ws = (workstation) ? workstation : "";
uname = freeable_uname = oilsFMGetString( userObj, "usrname" );
}
- if( passOK ) {
- response = oilsAuthHandleLoginOK( userObj, uname, type, orgloc, workstation );
+ if( passOK ) { // login successful
+
+ char* ewhat = "login";
+
+ if (0 == strcmp(ctx->method->name, "open-ils.auth.authenticate.verify")) {
+ response = oilsNewEvent( OSRF_LOG_MARK, OILS_EVENT_SUCCESS );
+ ewhat = "verify";
+
+ } else {
+ response = oilsAuthHandleLoginOK( userObj, uname, type, orgloc, workstation );
+ }
+
+ oilsUtilsTrackUserActivity(
+ oilsFMGetObjectId(userObj),
+ ewho, ewhat,
+ osrfAppSessionGetIngress()
+ );
} else {
response = oilsNewEvent( OSRF_LOG_MARK, OILS_EVENT_AUTH_FAILED );
return id;
}
+int oilsUtilsTrackUserActivity(long usr, const char* ewho, const char* ewhat, const char* ehow) {
+ if (!usr && !(ewho || ewhat || ehow)) return 0;
+ int rowcount = 0;
+
+ jsonObject* params = jsonParseFmt(
+ "{\"from\":[\"actor.insert_usr_activity\", %ld, \"%s\", \"%s\", \"%s\"]}",
+ usr,
+ (NULL == ewho) ? "" : ewho,
+ (NULL == ewhat) ? "" : ewhat,
+ (NULL == ehow) ? "" : ehow
+ );
+
+ osrfAppSession* session = osrfAppSessionClientInit("open-ils.cstore");
+ osrfAppSessionConnect(session);
+ int reqid = osrfAppSessionSendRequest(session, NULL, "open-ils.cstore.transaction.begin", 1);
+ osrfMessage* omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+
+ if(omsg) {
+ osrfMessageFree(omsg);
+ reqid = osrfAppSessionSendRequest(session, params, "open-ils.cstore.json_query", 1);
+ omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+
+ if(omsg) {
+ const jsonObject* rows = osrfMessageGetResult(omsg);
+ if (rows) rowcount = rows->size;
+ osrfMessageFree(omsg); // frees rows
+ if (rowcount) {
+ reqid = osrfAppSessionSendRequest(session, NULL, "open-ils.cstore.transaction.commit", 1);
+ omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+ osrfMessageFree(omsg);
+ } else {
+ reqid = osrfAppSessionSendRequest(session, NULL, "open-ils.cstore.transaction.rollback", 1);
+ omsg = osrfAppSessionRequestRecv(session, reqid, 60);
+ osrfMessageFree(omsg);
+ }
+ }
+ }
+
+ osrfAppSessionFree(session); // calls disconnect internally
+ jsonObjectFree(params);
+ return rowcount;
+}
+
+
oilsEvent* oilsUtilsCheckPerms( int userid, int orgid, char* permissions[], int size ) {
if (!permissions) return NULL;