]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/auth/session.js
toward workstation id
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / auth / session.js
1 dump('entering auth/session.js\n');
2
3 if (typeof auth == 'undefined') auth = {};
4 auth.session = function (view) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         this.view = view;
9
10         return this;
11 };
12
13 auth.session.prototype = {
14
15         'init' : function () {
16
17                 try {
18                         var init = this.network.request(
19                                 api.AUTH_INIT.app,
20                                 api.AUTH_INIT.method,
21                                 [ this.view.name_prompt.value ]
22                         );
23
24                         if (init) {
25                                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
26
27                                 var login_type = data.tmp_login_type || 'staff';
28
29                                 var params = [ 
30                                         this.view.name_prompt.value,
31                                         hex_md5(
32                                                 init +
33                                                 hex_md5(
34                                                         this.view.password_prompt.value
35                                                 )
36                                         ),
37                                         login_type,
38                                 ];
39
40                                 if (data.ws_id) {
41                                         params[3] = null; // org_id
42                                         params[4] = data.ws_id;
43                                 }
44
45                                 var robj = this.network.request(
46                                         api.AUTH_COMPLETE.app,
47                                         api.AUTH_COMPLETE.method,
48                                         params
49                                 );
50
51                                 if (robj.ilsevent == 0) {
52                                         this.key = robj.payload.authtoken;
53                                         this.authtime = robj.payload.authtime;
54                                 } else {
55                                         var error = robj.ilsevent + ' : ' + this.error.get_ilsevent( robj.ilsevent );
56                                         this.error.sdump('D_AUTH','auth.session.init: ' + error + '\n');
57                                         alert( error );
58                                         throw(robj);
59                                 }
60
61                                 this.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
62
63                                 if (typeof this.on_init == 'function') {
64                                         this.error.sdump('D_AUTH','auth.session.on_init()\n');
65                                         this.on_init();
66                                 }
67
68                         } else {
69
70                                 var error = 'open-ils.auth.authenticate.init returned false\n';
71                                 this.error.sdump('D_ERROR',error);
72                                 throw(error);
73                         }
74
75                 } catch(E) {
76                         var error = 'Error on auth.session.init(): ' + js2JSON(E) + '\n';
77                         this.error.sdump('D_ERROR',error); 
78
79                         if (typeof this.on_init_error == 'function') {
80                                 this.error.sdump('D_AUTH','auth.session.on_init_error()\n');
81                                 this.on_init_error(E);
82                         }
83                         if (typeof this.on_error == 'function') {
84                                 this.error.sdump('D_AUTH','auth.session.on_error()\n');
85                                 this.on_error();
86                         }
87
88                         //throw(E);
89                         /* This was for testing
90                         if (typeof this.on_init == 'function') {
91                                 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
92                                 this.on_init();
93                         }
94                         */
95                 }
96         },
97
98         'close' : function () { 
99                 var obj = this;
100                 obj.error.sdump('D_AUTH','auth.session.close()\n'); 
101                 if (obj.key) obj.network.request(
102                         api.AUTH_DELETE.app,
103                         api.AUTH_DELETE.method,
104                         [ obj.key ],
105                         function(req) {}
106                 );
107                 obj.key = null;
108                 if (typeof obj.on_close == 'function') {
109                         obj.error.sdump('D_AUTH','auth.session.on_close()\n');
110                         obj.on_close();
111                 }
112         }
113
114 }
115
116 dump('exiting auth/session.js\n');