]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js
Don't feed big G to the objects hanging off of G if we don't have to. But can I...
[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) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('main.network'); this.network = new main.network();
8         this.controller = controller;
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.controller.view.name_prompt.value ]
22                         );
23
24                         if (init) {
25
26                                 this.key = this.network.request(
27                                         'open-ils.auth',
28                                         'open-ils.auth.authenticate.complete',
29                                         [ 
30                                                 this.controller.view.name_prompt.value,
31                                                 hex_md5(
32                                                         init +
33                                                         hex_md5(
34                                                                 this.controller.view.password_prompt.value
35                                                         )
36                                                 )
37                                         ]
38                                 );
39
40                                 this.error.sdump('D_AUTH','auth.session.key = ' + this.key + '\n');
41
42                                 if (Number(this.key) == 0) {
43                                         throw('Invalid name/password combination.');
44                                 } else if (instanceOf(this.key,ex)) {
45                                         throw(this.key.err_msg());
46                                 }
47
48                                 if (typeof this.on_init == 'function') {
49                                         this.error.sdump('D_AUTH','auth.session.on_init()\n');
50                                         this.on_init();
51                                 }
52
53                         } else {
54
55                                 var error = 'open-ils.auth.authenticate.init returned false\n';
56                                 this.error.sdump('D_ERROR',error);
57                                 this.controller.logoff();
58                                 throw(error);
59                         }
60
61                 } catch(E) {
62                         var error = 'Error on auth.session.init(): ' + E + '\n';
63                         this.error.sdump('D_ERROR',error); 
64
65                         if (typeof this.on_init_error == 'function') {
66                                 this.error.sdump('D_AUTH','auth.session.on_init_error()\n');
67                                 this.on_init_error(E);
68                         }
69
70                         //throw(E);
71                         if (typeof this.on_init == 'function') {
72                                 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
73                                 this.on_init();
74                         }
75                 }
76
77         },
78
79         'close' : function () { 
80                 this.error.sdump('D_AUTH','auth.session.close()\n'); 
81                 this.key = null;
82                 if (typeof this.G.on_close == 'function') {
83                         this.error.sdump('D_AUTH','auth.session.on_close()\n');
84                         this.G.on_close();
85                 }
86         }
87
88 }
89
90 dump('exiting auth/session.js\n');