]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js
some thinkos, offline fixes, remote xul testing
[working/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 (controller,mw,G) {
5
6         this.mw = mw; this.G = G; this.controller = controller;
7
8         return this;
9 };
10
11 auth.session.prototype = {
12
13         'init' : function () {
14
15                 try {
16                         var init = this.G.network.request(
17                                 'open-ils.auth',
18                                 'open-ils.auth.authenticate.init',
19                                 [ this.controller.view.name_prompt.value ]
20                         );
21
22                         if (init) {
23
24                                 this.key = this.G.network.request(
25                                         'open-ils.auth',
26                                         'open-ils.auth.authenticate.complete',
27                                         [ 
28                                                 this.controller.view.name_prompt.value,
29                                                 hex_md5(
30                                                         init +
31                                                         hex_md5(
32                                                                 this.controller.view.password_prompt.value
33                                                         )
34                                                 )
35                                         ]
36                                 );
37
38                                 this.G.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
39
40                                 if (Number(this.key) == 0) {
41                                         throw('Invalid name/password combination.');
42                                 } else if (instanceOf(this.key,ex)) {
43                                         throw(this.key.err_msg());
44                                 }
45
46                                 if (typeof this.on_init == 'function') {
47                                         this.G.error.sdump('D_AUTH','auth.session.on_init()\n');
48                                         this.on_init();
49                                 }
50
51                         } else {
52
53                                 var error = 'open-ils.auth.authenticate.init returned false\n';
54                                 this.G.error.sdump('D_ERROR',error);
55                                 this.controller.logoff();
56                                 throw(error);
57                         }
58
59                 } catch(E) {
60                         var error = 'Error on auth.session.init(): ' + E + '\n';
61                         this.G.error.sdump('D_ERROR',error); 
62
63                         if (typeof this.on_init_error == 'function') {
64                                 this.G.error.sdump('D_AUTH','auth.session.on_init_error()\n');
65                                 this.on_init_error(E);
66                         }
67
68                         //throw(E);
69                         if (typeof this.on_init == 'function') {
70                                 this.G.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
71                                 this.on_init();
72                         }
73                 }
74
75         },
76
77         'close' : function () { 
78                 this.G.error.sdump('D_AUTH','auth.session.close()\n'); 
79                 this.key = null;
80                 if (typeof this.G.on_close == 'function') {
81                         this.G.error.sdump('D_AUTH','auth.session.on_close()\n');
82                         this.G.on_close();
83                 }
84         }
85
86 }
87
88 dump('exiting auth/session.js\n');