1 dump('entering auth/session.js\n');
3 if (typeof auth == 'undefined') auth = {};
4 auth.session = function (view,login_type) {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('util.network'); this.network = new util.network();
9 this.login_type = login_type || 'staff';
14 auth.session.prototype = {
16 'init' : function () {
21 var init = this.network.request(
24 [ this.view.name_prompt.value ]
28 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
31 'username' : this.view.name_prompt.value,
35 this.view.password_prompt.value
41 if (data.ws_info[ this.view.server_prompt.value ]) {
42 params.type = this.login_type;
43 params.workstation = data.ws_info[ this.view.server_prompt.value ].name;
44 data.ws_name = params.workstation; data.stash('ws_name');
47 var robj = this.network.simple_request( 'AUTH_COMPLETE', [ params ]);
49 switch (robj.ilsevent) {
51 this.key = robj.payload.authtoken;
52 this.authtime = robj.payload.authtime;
54 case 1520 /* WORKSTATION_NOT_FOUND */:
55 alert(params.workstation + ' is not registered with this server.');
56 delete(params.workstation);
57 delete(data.ws_info[ this.view.server_prompt.value ]);
58 data.stash('ws_info');
59 data.ws_name = null; data.stash('ws_name');
61 robj = this.network.simple_request('AUTH_COMPLETE',[ params ]);
62 if (robj.ilsevent == 0) {
63 this.key = robj.payload.authtoken;
64 this.authtime = robj.payload.authtime;
66 //this.error.standard_unexpected_error_alert('auth.session.init',robj);
71 //obj.error.standard_unexpected_error_alert('auth.session.init',robj);
76 this.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
78 if (typeof this.on_init == 'function') {
79 this.error.sdump('D_AUTH','auth.session.on_init()\n');
85 var error = 'open-ils.auth.authenticate.init returned false\n';
86 this.error.sdump('D_ERROR',error);
91 alert('Login failed. Please check your Server Hostname, Username, Password, and your CAPS LOCK key.');
92 //obj.error.standard_unexpected_error_alert('Error on auth.session.init()',E);
94 if (typeof this.on_init_error == 'function') {
95 this.error.sdump('D_AUTH','auth.session.on_init_error()\n');
96 this.on_init_error(E);
98 if (typeof this.on_error == 'function') {
99 this.error.sdump('D_AUTH','auth.session.on_error()\n');
104 /* This was for testing
105 if (typeof this.on_init == 'function') {
106 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
113 'close' : function () {
115 obj.error.sdump('D_AUTH','auth.session.close()\n');
116 if (obj.key) obj.network.request(
118 api.AUTH_DELETE.method,
123 if (typeof obj.on_close == 'function') {
124 obj.error.sdump('D_AUTH','auth.session.on_close()\n');
131 dump('exiting auth/session.js\n');