1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2008 Georgia Public Library Service
3 * Bill Erickson <erickson@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
17 if(!dojo._hasResource["openils.User"]) {
19 dojo._hasResource["openils.User"] = true;
20 dojo.provide("openils.User");
21 dojo.require('openils.Event');
23 dojo.declare('openils.User', null, {});
25 openils.User.user = null;
26 openils.User.authtoken = null;
27 openils.User.authtime = null;
29 var ses = new OpenSRF.ClientSession('open-ils.auth');
31 openils.User.getBySession = function(onComplete) {
32 var req = ses.request('open-ils.auth.session.retrieve', openils.User.authtoken);
33 req.oncomplete = function(r) {
34 var user = r.recv().content();
35 openils.User.user = user;
42 openils.User.getById = function(id, onComplete) {
43 var ases = new OpenSRF.ClientSession('open-ils.actor');
44 var req = ases.request('open-ils.actor.user.retrieve', openils.User.authtoken, id);
46 req.oncomplete = function(r) {
47 var user = r.recv().content();
54 return req.recv().content();
60 * Logs in, sets the authtoken/authtime vars, and fetches the logged in user
62 openils.User.login = function(args, onComplete) {
63 var initReq = ses.request('open-ils.auth.authenticate.init', args.username);
65 initReq.oncomplete = function(r) {
66 var seed = r.recv().content();
69 password : hex_md5(seed + hex_md5(args.passwd)),
70 type : args.type || 'opac',
74 var authReq = ses.request('open-ils.auth.authenticate.complete', loginInfo);
75 authReq.oncomplete = function(rr) {
76 var data = rr.recv().content();
77 openils.User.authtoken = data.payload.authtoken;
78 openils.User.authtime = data.payload.authtime;
79 openils.User.getBySession(onComplete);