source: ISOcat/trunk/mod-ISOcat-interface-gi/interface/JSXAPPS/ISOcat/js/org/isocat/gui/Password.js @ 2029

Last change on this file since 2029 was 2029, checked in by mwindhouwer, 12 years ago

Initial import of all the *cats, i.e., ISOcat, RELcat and SCHEMAcat.

File size: 5.5 KB
Line 
1jsx3.util.Logger.getLogger("org.isocat").info("Loading class[org.isocat.gui.Password]");
2
3/**
4 * The Password controller
5 * @author Menzo.Windhouwer@mpi.nl
6 */
7jsx3.lang.Class.defineClass("org.isocat.gui.Password", null, [], function(Password, Password_prototype) {
8       
9        /**
10         * The class logger
11         */
12        Password.log = jsx3.util.Logger.getLogger("org.isocat.gui.Password");
13       
14        /**
15         * The root block of the component
16         */
17        Password_prototype.view;
18       
19        /**
20         * The old Password field
21         */
22        Password_prototype.oldPassword;
23       
24        /**
25         * The new Password field
26         */
27        Password_prototype.newPassword;
28               
29        /**
30         * The check Password field
31         */
32        Password_prototype.checkPassword;
33
34    /**
35         * The help tabs
36         */
37        Password_prototype.help;
38       
39    /**
40         * The error text
41         */
42        Password_prototype.err;
43       
44        /**
45         * Constructor
46         */
47        Password_prototype.init = function(view) {
48                org.isocat.gui.Password.log.info("initialize Password["+this+"]");
49
50                this.view = view;
51                org.isocat.gui.Password.log.info("- Password view["+this.view+"]");
52                this.oldPassword = this.view.getDescendantOfName("oldPasswordField");
53                org.isocat.gui.Password.log.info("- oldPassword["+this.oldPassword+"]");
54                this.newPassword = this.view.getDescendantOfName("newPasswordField");
55                org.isocat.gui.Password.log.info("- newPassword["+this.newPassword+"]");
56                this.checkPassword = this.view.getDescendantOfName("checkPasswordField");
57                org.isocat.gui.Password.log.info("- oldPassword["+this.checkPassword+"]");
58                this.help = this.view.getDescendantOfName("help");
59                org.isocat.gui.Password.log.info("- help["+this.help+"]");
60                this.err = this.view.getDescendantOfName("errorText");
61                org.isocat.gui.Password.log.info("- help["+this.help+"]");
62               
63                org.isocat.gui.Password.log.info("initialized Password["+this+"]");
64               
65                this.view.controller = this;
66               
67                // create message
68                var message = {
69                        jss: "org.pagebus.msg.Message",
70                        jssv: "1.0.0",
71                        header: { },
72                        body: this
73                };
74               
75                // publish the message using PageBus
76                window.PageBus.publish("org.isocat.gui.Password.init", message);
77        };
78       
79        /**
80         * Set focus to the first field
81         */
82        Password_prototype.focus = function() {
83                this.view.focus();
84                // TIBCO hack: first the dialog needs to claim focus, then we can move the focus to the user name field, the sleep takes care of the delay
85                jsx3.sleep(function() { this.oldPassword.focus();},"focusPassword",this,true);
86        };
87       
88        /**
89         * The actual Password is requested
90         */
91        Password_prototype.change = function() {
92                org.isocat.gui.Password.log.info("welcome to change password ...");
93                org.isocat.gui.Password.log.info("old["+this.oldPassword.getValue()+"]");
94        org.isocat.gui.Password.log.info("new["+this.newPassword.getValue()+"]");
95        org.isocat.gui.Password.log.info("check["+this.checkPassword.getValue()+"]");
96                var res = false;
97                if (!this.oldPassword.doValidate()) {
98                    this.err.setText("Please provide your old password!",true);
99                        this.help.setSelectedIndex(1,true);
100                        this.oldPassword.focus();
101                        org.isocat.gui.Password.log.info("invalid old password");
102                } else if (!this.newPassword.doValidate()) {
103                    this.err.setText("Please provide your new password! It should be at least 6 symbols long and not contain any whitespace.",true);
104                        this.help.setSelectedIndex(1,true);
105                        this.newPassword.focus();
106                        org.isocat.gui.Password.log.info("invalid new password");
107                } else if (!this.checkPassword.doValidate()) {
108                    this.err.setText("Please retype your new password!",true);
109                        this.help.setSelectedIndex(1,true);
110                        this.checkPassword.focus();
111                        org.isocat.gui.Password.log.info("invalid check password");
112                } else if (org.isocat.trim(this.newPassword.getValue()) != org.isocat.trim(this.checkPassword.getValue())) {
113                    this.err.setText("Please retype your new password!",true);
114                        this.help.setSelectedIndex(1,true);
115                        this.checkPassword.focus();
116                        org.isocat.gui.Password.log.info("differences between new and check password");
117                } else {
118                    var pass = org.isocat.trim(this.newPassword.getValue());
119                    org.isocat.gui.Password.log.info("change password ...");
120                        this.view.doClose();
121                    var uri = "http://localhost:8080/isocat/rest/user/"+org.isocat.profile.user()+"/password";
122                    org.isocat.gui.Password.log.info("uri["+uri+"]");
123                    var req = new jsx3.net.Request().open("POST",uri,false,org.isocat.profile.user(),org.isocat.profile.pass());
124                    req.setRequestHeader("Content-Type","application/xml");
125                    var out = new jsx3.xml.Document();
126            out.createDocumentElement("pwd").setValue(pass);
127                    org.isocat.gui.Password.log.info("out["+out.toString()+"]");
128                        req.send(out.toString());
129                        var status = req.getStatus();
130                org.isocat.gui.Password.log.info("status["+status+"]");
131                        if (status == "200") {
132                            org.isocat.APP.alert("Password changed","Your password has been changed, please log back in! it may take up to an hour before your new account details are synchronized with the ISOcat forum. So if logging in to the forum fails, please try again after one hour.",null,"OK");
133                            org.isocat.profile._password = pass;
134                    org.isocat.logout();
135                            res = true;
136            } else {
137                org.isocat.APP.alert("Error","An unexpected error has occured, please contact the ISOcat system administrator!",null,"OK");
138                    org.isocat.gui.Password.log.info("change password ... failed");
139            }
140                }
141                org.isocat.gui.Password.log.info("welcome to change password ... goodbye");
142                return res;
143        };
144       
145});
Note: See TracBrowser for help on using the repository browser.