]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/auth/session.js
throw an exception when auth fails
[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 (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                                 this.key = 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                                 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                                 if (typeof this.on_error == 'function') {
58                                         this.error.sdump('D_AUTH','auth.session.on_error()\n');
59                                         this.on_error();
60                                 }
61                                 throw(error);
62                         }
63
64                 } catch(E) {
65                         var error = 'Error on auth.session.init(): ' + 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
73                         throw(E);
74                         /* This was for testing
75                         if (typeof this.on_init == 'function') {
76                                 this.error.sdump('D_AUTH','auth.session.on_init() despite error\n');
77                                 this.on_init();
78                         }
79                         */
80                 }
81
82         },
83
84         'close' : function () { 
85                 this.error.sdump('D_AUTH','auth.session.close()\n'); 
86                 this.key = null;
87                 if (typeof this.on_close == 'function') {
88                         this.error.sdump('D_AUTH','auth.session.on_close()\n');
89                         this.on_close();
90                 }
91         }
92
93 }
94
95 dump('exiting auth/session.js\n');