api chang
[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('main.network'); this.network = new main.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                                 'open-ils.auth',
20                                 'open-ils.auth.authenticate.init',
21                                 [ this.view.name_prompt.value ]
22                         );
23
24                         if (init) {
25
26                                 var robj = this.network.request(
27                                         'open-ils.auth',
28                                         'open-ils.auth.authenticate.complete',
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;
42                                 } else {
43                                         var error = robj.ilsevent + ' : ' + this.error.get_ilsevent( robj.ilsevent );
44                                         this.error.sdump('D_AUTH','auth.session.init: ' + error + '\n');
45                                         alert( error );
46                                         throw(robj);
47                                 }
48
49                                 this.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
50
51                                 if (typeof this.on_init == 'function') {
52                                         this.error.sdump('D_AUTH','auth.session.on_init()\n');
53                                         this.on_init();
54                                 }
55
56                         } else {
57
58                                 var error = 'open-ils.auth.authenticate.init returned false\n';
59                                 this.error.sdump('D_ERROR',error);
60                                 throw(error);
61                         }
62
63                 } catch(E) {
64                         var error = 'Error on auth.session.init(): ' + js2JSON(E) + '\n';
65                         this.error.sdump('D_ERROR',error); 
66
67                         if (typeof this.on_init_error == 'function') {
68                                 this.error.sdump('D_AUTH','auth.session.on_init_error()\n');
69                                 this.on_init_error(E);
70                         }
71                         if (typeof this.on_error == 'function') {
72                                 this.error.sdump('D_AUTH','auth.session.on_error()\n');
73                                 this.on_error();
74                         }
75
76                         //throw(E);
77                         /* This was for testing
78                         if (typeof this.on_init == 'function') {
79                                 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
80                                 this.on_init();
81                         }
82                         */
83                 }
84         },
85
86         'close' : function () { 
87                 this.error.sdump('D_AUTH','auth.session.close()\n'); 
88                 this.key = null;
89                 if (typeof this.on_close == 'function') {
90                         this.error.sdump('D_AUTH','auth.session.on_close()\n');
91                         this.on_close();
92                 }
93         }
94
95 }
96
97 dump('exiting auth/session.js\n');