From 35c60eb7cc7e6dd961b8ce7fc87326a9874eed31 Mon Sep 17 00:00:00 2001 From: erickson Date: Sun, 13 Apr 2008 15:51:04 +0000 Subject: [PATCH] user and auth session management class git-svn-id: svn://svn.open-ils.org/ILS/trunk@9325 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/User.js | 88 ++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Open-ILS/web/js/dojo/openils/User.js diff --git a/Open-ILS/web/js/dojo/openils/User.js b/Open-ILS/web/js/dojo/openils/User.js new file mode 100644 index 0000000000..c547abc29f --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/User.js @@ -0,0 +1,88 @@ +/* --------------------------------------------------------------------------- + * Copyright (C) 2008 Georgia Public Library Service + * Bill Erickson + * + * 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(); + } +} + + -- 2.11.0