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