[open-ils-commits] r9325 - trunk/Open-ILS/web/js/dojo/openils
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Apr 13 12:28:54 EDT 2008
Author: erickson
Date: 2008-04-13 11:51:04 -0400 (Sun, 13 Apr 2008)
New Revision: 9325
Added:
trunk/Open-ILS/web/js/dojo/openils/User.js
Log:
user and auth session management class
Added: trunk/Open-ILS/web/js/dojo/openils/User.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/User.js (rev 0)
+++ trunk/Open-ILS/web/js/dojo/openils/User.js 2008-04-13 15:51:04 UTC (rev 9325)
@@ -0,0 +1,88 @@
+/* ---------------------------------------------------------------------------
+ * Copyright (C) 2008 Georgia Public Library Service
+ * Bill Erickson <erickson at esilibrary.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * ---------------------------------------------------------------------------
+ */
+
+if(!dojo._hasResource["openils.User"]) {
+
+ dojo._hasResource["openils.User"] = true;
+ dojo.provide("openils.User");
+ dojo.require('openils.Event');
+
+ dojo.declare('openils.User', null, {});
+
+ openils.User.user = null;
+ openils.User.authtoken = null;
+ openils.User.authtime = null;
+
+ var ses = new OpenSRF.ClientSession('open-ils.auth');
+
+ openils.User.getBySession = function(onComplete) {
+ var req = ses.request('open-ils.auth.session.retrieve', openils.User.authtoken);
+ req.oncomplete = function(r) {
+ var user = r.recv().content();
+ openils.User.user = user;
+ if(onComplete)
+ onComplete(user);
+ }
+ req.send();
+ }
+
+ openils.User.getById = function(id, onComplete) {
+ var ases = new OpenSRF.ClientSession('open-ils.actor');
+ var req = ases.request('open-ils.actor.user.retrieve', openils.User.authtoken, id);
+ if(onComplete) {
+ req.oncomplete = function(r) {
+ var user = r.recv().content();
+ onComplete(user);
+ }
+ req.send();
+ } else {
+ req.timeout = 10;
+ req.send();
+ return req.recv().content();
+ }
+ }
+
+
+ /**
+ * Logs in, sets the authtoken/authtime vars, and fetches the logged in user
+ */
+ openils.User.login = function(args, onComplete) {
+ var initReq = ses.request('open-ils.auth.authenticate.init', args.username);
+
+ initReq.oncomplete = function(r) {
+ var seed = r.recv().content();
+ alert(seed);
+ var loginInfo = {
+ password : hex_md5(seed + hex_md5(args.passwd)),
+ type : args.type || 'opac',
+ org : args.location,
+ };
+
+ var authReq = ses.request('open-ils.auth.authenticate.complete', loginInfo);
+ authReq.oncomplete = function(rr) {
+ var data = rr.recv().content();
+ openils.User.authtoken = data.payload.authtoken;
+ openils.User.authtime = data.payload.authtime;
+ openils.User.getBySession(onComplete);
+ }
+ authReq.send();
+ }
+
+ initReq.send();
+ }
+}
+
+
More information about the open-ils-commits
mailing list