]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/auth/session.js
handle the WORKSTATION_NOT_FOUND event for old registrations
[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,login_type) {
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         this.login_type = login_type || 'staff';
10
11         return this;
12 };
13
14 auth.session.prototype = {
15
16         'init' : function () {
17
18                 try {
19                         var init = this.network.request(
20                                 api.AUTH_INIT.app,
21                                 api.AUTH_INIT.method,
22                                 [ this.view.name_prompt.value ]
23                         );
24
25                         if (init) {
26                                 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
27
28                                 var params = { 
29                                         'username' : this.view.name_prompt.value,
30                                         'password' : hex_md5(
31                                                 init +
32                                                 hex_md5(
33                                                         this.view.password_prompt.value
34                                                 )
35                                         ),
36                                         'type' : 'temp',
37                                 };
38
39                                 if (data.ws_info[ this.view.server_prompt.value ]) {
40                                         params.type = this.login_type;
41                                         params.workstation = data.ws_info[ this.view.server_prompt.value ].name;
42                                         data.ws_name = params.workstation; data.stash('ws_name');
43                                 }
44
45                                 var robj = this.network.request(
46                                         api.AUTH_COMPLETE.app,
47                                         api.AUTH_COMPLETE.method,
48                                         [ params ]
49                                 );
50
51                                 switch (robj.ilsevent) {
52                                         case 0:
53                                                 this.key = robj.payload.authtoken;
54                                                 this.authtime = robj.payload.authtime;
55                                         break;
56                                         case 1520 /* WORKSTATION_NOT_FOUND */:
57                                                 alert(params.workstation + ' is not registered with this server.');
58                                                 delete(params.workstation);
59                                                 delete(data.ws_info[ this.view.server_prompt.value ]);
60                                                 data.stash('ws_info');
61                                                 data.ws_name = null; data.stash('ws_name');
62                                                 params.type = 'temp';
63                                                 robj = this.network.simple_request('AUTH_COMPLETE',[ params ]);
64                                                 if (robj.ilsevent == 0) {
65                                                         this.key = robj.payload.authtoken;
66                                                         this.authtime = robj.payload.authtime;
67                                                 } else {
68                                                         this.error.standard_unexpected_error_alert('auth.session.init',robj);
69                                                         throw(robj);
70                                                 }
71                                         break;
72                                         default:
73                                         this.error.standard_unexpected_error_alert('auth.session.init',robj);
74                                         throw(robj);
75                                         break;
76                                 }
77
78                                 this.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
79
80                                 if (typeof this.on_init == 'function') {
81                                         this.error.sdump('D_AUTH','auth.session.on_init()\n');
82                                         this.on_init();
83                                 }
84
85                         } else {
86
87                                 var error = 'open-ils.auth.authenticate.init returned false\n';
88                                 this.error.sdump('D_ERROR',error);
89                                 throw(error);
90                         }
91
92                 } catch(E) {
93                         var error = 'Error on auth.session.init(): ' + js2JSON(E) + '\n';
94                         this.error.sdump('D_ERROR',error); 
95
96                         if (typeof this.on_init_error == 'function') {
97                                 this.error.sdump('D_AUTH','auth.session.on_init_error()\n');
98                                 this.on_init_error(E);
99                         }
100                         if (typeof this.on_error == 'function') {
101                                 this.error.sdump('D_AUTH','auth.session.on_error()\n');
102                                 this.on_error();
103                         }
104
105                         //throw(E);
106                         /* This was for testing
107                         if (typeof this.on_init == 'function') {
108                                 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
109                                 this.on_init();
110                         }
111                         */
112                 }
113         },
114
115         'close' : function () { 
116                 var obj = this;
117                 obj.error.sdump('D_AUTH','auth.session.close()\n'); 
118                 if (obj.key) obj.network.request(
119                         api.AUTH_DELETE.app,
120                         api.AUTH_DELETE.method,
121                         [ obj.key ],
122                         function(req) {}
123                 );
124                 obj.key = null;
125                 if (typeof obj.on_close == 'function') {
126                         obj.error.sdump('D_AUTH','auth.session.on_close()\n');
127                         obj.on_close();
128                 }
129         }
130
131 }
132
133 dump('exiting auth/session.js\n');