]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js
move network, window, and controller from main to util
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / 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
26                                 var robj = this.network.request(
27                                         api.auth_complete.app,
28                                         api.auth_complete.method,
29                                         [ 
30                                                 this.view.name_prompt.value,
31                                                 hex_md5(
32                                                         init +
33                                                         hex_md5(
34                                                                 this.view.password_prompt.value
35                                                         )
36                                                 )
37                                         ]
38                                 );
39
40                                 if (robj.ilsevent == 0) {
41                                         this.key = robj.payload.authtoken;
42                                         this.authtime = robj.payload.authtime;
43                                 } else {
44                                         var error = robj.ilsevent + ' : ' + this.error.get_ilsevent( robj.ilsevent );
45                                         this.error.sdump('D_AUTH','auth.session.init: ' + error + '\n');
46                                         alert( error );
47                                         throw(robj);
48                                 }
49
50                                 this.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
51
52                                 if (typeof this.on_init == 'function') {
53                                         this.error.sdump('D_AUTH','auth.session.on_init()\n');
54                                         this.on_init();
55                                 }
56
57                         } else {
58
59                                 var error = 'open-ils.auth.authenticate.init returned false\n';
60                                 this.error.sdump('D_ERROR',error);
61                                 throw(error);
62                         }
63
64                 } catch(E) {
65                         var error = 'Error on auth.session.init(): ' + js2JSON(E) + '\n';
66                         this.error.sdump('D_ERROR',error); 
67
68                         if (typeof this.on_init_error == 'function') {
69                                 this.error.sdump('D_AUTH','auth.session.on_init_error()\n');
70                                 this.on_init_error(E);
71                         }
72                         if (typeof this.on_error == 'function') {
73                                 this.error.sdump('D_AUTH','auth.session.on_error()\n');
74                                 this.on_error();
75                         }
76
77                         //throw(E);
78                         /* This was for testing
79                         if (typeof this.on_init == 'function') {
80                                 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
81                                 this.on_init();
82                         }
83                         */
84                 }
85         },
86
87         'close' : function () { 
88                 this.error.sdump('D_AUTH','auth.session.close()\n'); 
89                 this.key = null;
90                 if (typeof this.on_close == 'function') {
91                         this.error.sdump('D_AUTH','auth.session.on_close()\n');
92                         this.on_close();
93                 }
94         }
95
96 }
97
98 dump('exiting auth/session.js\n');