7 function UserSession() {
8 this.cookie = new cookieObject("ses", 1, "/opac/", "ils_ses");
9 this.connected = false;
10 globalUserSession = this;
13 UserSession.prototype.destroy = function() {
14 debug("Removing user session");
15 this.connected = false;
16 this.session_id = null;
22 UserSession.prototype.persist = function() {
24 this.cookie = new cookieObject("ses", 1, "/opac/", "ils_ses");
26 if(!this.session_id) return;
29 this.cookie.put("ils_ses", this.session_id);
31 debug("Persisting session with session " +
32 this.session_id + " and uname " + this.username );
35 debug("Persisted session " + this.cookie.fields[UserSession.SES]);
40 UserSession.prototype.verifySession = function(ses) {
42 debug("Verifying session...");
44 debug("Session key passed in [" + ses + "], verifying...");
47 this.session_id = ses;
49 this.session_id = this.cookie.fields[UserSession.SES];
52 debug("Retrieveing user info for session " + this.session_id);
54 /* user is returning to the page with a session key */
55 var request = new RemoteRequest("open-ils.auth",
56 "open-ils.auth.session.retrieve", this.session_id );
61 var user = request.getResultObject();
64 if( typeof user == 'object' && user._isfieldmapper) {
66 debug("User retrieved, setting up user info");
67 this.username = user.usrname();
68 this.userObject = user;
69 this.connected = true;
74 debug("User session " + this.session_id + " is no longer valid");
80 debug("No session cookie found");
87 UserSession.instance = function() {
88 if( globalUserSession )
89 return globalUserSession;
90 return new UserSession();
93 UserSession.prototype.setSessionId = function( id ) {
94 debug("User session id " + id );
98 UserSession.prototype.getSessionId = function() {
99 return this.session_id;
102 UserSession.prototype.login = function( username, password ) {
104 if(!username || !password) { return false; }
105 this.username = username;
107 var init_request = new RemoteRequest( 'open-ils.auth',
108 'open-ils.auth.authenticate.init', username );
110 init_request.send(true);
111 var seed = init_request.getResultObject();
113 if( ! seed || seed == '0') {
114 /* XXX should be an exception */
115 alert( "Error Communicating with Authentication Server" );
119 var auth_request = new RemoteRequest( 'open-ils.auth',
120 'open-ils.auth.authenticate.complete', username,
121 hex_md5(seed + hex_md5(password)), "opac");
123 auth_request.send(true);
124 var auth_result = auth_request.getResultObject();
126 if(auth_result == '0') { return false; }
128 this.setSessionId(auth_result);
130 this.connected = true;
139 /* grab this users org unit */
140 /* if new_org_id is provided, it is used instead of the home_ou
142 UserSession.prototype.grabOrgUnit = function(org) {
143 var session = this.getSessionId();
146 "No session ID for user in grabOrgUnit()");
149 debug("Retrieving this users object");
151 var request = new RemoteRequest(
153 "open-ils.auth.session.retrieve",
156 this.userObject = request.getResultObject();
158 if(org) this.orgUnit = org;
159 else this.orgUnit = findOrgUnit(this.userObject.home_ou());
161 if(!paramObj.__depth)
162 globalSelectedDepth = findOrgDepth(this.orgUnit.ou_type());
163 if(!paramObj.__location)
164 globalPage.updateSelectedLocation(this.orgUnit);
165 globalPage.updateCurrentLocation(this.orgUnit);
174 UserSession.prototype.updatePassword = function(currentPassword, password) {
175 if(!password || !currentPassword) return null;
177 var request = new RemoteRequest(
179 "open-ils.actor.user.password.update",
187 try { resp = request.getResultObject(); }
189 if(instanceOf(E, ex))
197 this.password = password;
198 this.userObject.passwd(password);
206 UserSession.prototype.updateUsername = function(username) {
207 if(!username) return null;
208 var request = new RemoteRequest(
210 "open-ils.actor.user.username.update",
214 var resp = request.getResultObject();
216 this.username = username;
217 this.userObject.usrname(username);
223 UserSession.prototype.updateEmail = function(email) {
224 if(!email) return null;
225 var request = new RemoteRequest(
227 "open-ils.actor.user.email.update",
231 var resp = request.getResultObject();
233 this.userObject.email(email);