root/apps/reference/trunk/coreEnvironment/session.js

Revision 8694, 8.6 kB (checked in by zumbrunn, 3 years ago)

removed spaces prefixing example code which were needed with the perl based jsdoc but get in the way with jsdoc-toolkit

  • Property cvs2svn:cvs-rev set to 1.9
  • Property svn:keywords set to Date Revision Author HeadURL Id
Line 
1 /*
2  * Helma License Notice
3  *
4  * The contents of this file are subject to the Helma License
5  * Version 2.0 (the "License"). You may not use this file except in
6  * compliance with the License. A copy of the License is available at
7  * http://adele.helma.org/download/helma/license.txt
8  *
9  * Copyright 1998-2007 Helma Software. All Rights Reserved.
10  *
11  * $RCSfile: session.js,v $
12  * $Author$
13  * $Revision$
14  * $Date$
15  */
16
17 /**
18  * @fileoverview Default properties and methods of the session object.
19  */
20
21
22 /**
23  * This object is automatically instantiated as the session property
24  * of the global object (or global.session).
25  * <br /><br />
26  * The session object is a host object representing the session 
27  * for the request that is currently handled by the scripting
28  * environment.
29  * <br /><br />
30  * Each web request is associated with a SessionObject
31  * representing a 'user session'. Helma recognises requests
32  * being made from the same client within the same session through
33  * a session cookie named 'HopSession'. If no such cookie is sent
34  * with the request, Helma will set that a cookie with a random
35  * hash with the next response.
36  * <br /><br />
37  * Within the scripting environment 'session' always
38  * represents the current session of the user, who initiated
39  * the web request.
40  * <br /><br />
41  * Besides that default session object, it is also possible
42  * to fetch active sessions of other clients through the method
43  * app.getSessions(), and to create additional SessionObjects
44  * through app.createSession().
45  * <br /><br />
46  * For further details also see the JavaDocs for
47  * helma.framework.core.SessionBean. Since that class is a
48  * JavaBean all get- and set-methods are also directly
49  * available as properties of that object.
50  *
51  * @type SessionBean
52  * @see Packages.helma.framework.core.SessionBean
53  */
54 session = new Object();
55
56
57 /**
58  * The unique identifier for a session object (session cookie).
59  * <br /><br />
60  * Contains the unique identifier of the current
61  * session, which is equivalent to the value stored in
62  * the HopSession-cookie on the client side.
63  * <br /><br />
64  * This property is read-only.
65  * <br /><br />
66  * Example:
67  * <pre>res.writeln(session._id);
68  * <i>1fcca129764400&#64;eefa22dfab</i></pre>
69  *
70  * @type String
71  */
72 session._id = new String();
73
74
75 /**
76  * The cookie value of a session.
77  * <br /><br />
78  * Contains the unique identifier of the current
79  * session, which is equivalent to the value stored
80  * in the HopSession-cookie on the client side.
81  * <br /><br />
82  * This property is read-only.
83  * <br /><br />
84  * Example:
85  * <pre>res.writeln(session.cookie);
86  * <i>1fcca129764400&#64;eefa22dfab</i></pre>
87  *
88  * @type String
89  */
90 session.cookie = new String();
91
92
93 /**
94  * Object providing space for run-time user data (user cache).
95  * <br /><br />
96  * This property of the SessionObject offers the
97  * possibility to store arbitrary data within the current
98  * user session. Note, that this can just be used as a
99  * temporary storage, since sessions are not stored
100  * persistently within Helma, and are generally lost when
101  * the application is restarted.
102  * <br /><br />
103  * Example:
104  * <pre>session.data.lastclick = new Date();
105  * session.data.language = "en";
106  * &nbsp;
107  * res.write(session.data);
108  * <i>TransientNode session</i>
109  * &nbsp;
110  * for (var p in session.data)
111  * &nbsp;&nbsp;res.writeln(p + ": " + session.data[p]);
112  * <i>lastclick: Fri Jul 12 14:08:20 CEST 2002
113  * language: en</i>
114  * &nbsp;
115  * res.write(session.data.lastclick);
116  * <i>Fri Jul 12 14:08:20 CEST 2002</i>
117  * &nbsp;
118  * res.write(session.data["language"]);
119  * <i>en</i></pre>
120  *
121  * @type TransientNode
122  */
123 session.data = new Object();
124
125
126 /**
127  * The date a session was created or a login or logout was performed the last time.
128  * <br /><br />
129  * This is a convenience property to acknowledge
130  * that pages are often dependent on the login status
131  * and must be re-rendered when a user has logged in,
132  * logged out or is running with a new session.
133  * <br /><br />
134  * Contains the timestamp of when the associated
135  * client started the session, or logged in, or
136  * logged out the last time, whichever happened most
137  * recently.
138  * <br /><br />
139  * This property is read- and write-able.
140  * <br /><br />
141  * Example:
142  * <pre>if (session.lastModified < this.modifytime)
143  * &nbsp;&nbsp;renderSkin("main");
144  * else
145  * &nbsp;&nbsp;res.notModified();</pre>
146  *
147  * @type Date
148  */
149 session.lastModified = new Date();
150
151
152 /**
153  * If set, the message will be available during the next request as res.message
154  *
155  * @type String
156  */
157 session.message = new String();
158
159
160 /**
161  * A reference to the user object associated with the current session.
162  * <br /><br />
163  * Contains a reference to the UserObject associated
164  * with this session. This property is null if the client
165  * has not been logged in yet, or has already been logged
166  * out. Checking this for being unequal to null is the
167  * usual way to check whether a client is logged in or not.
168  * This property is read-only, but can be set through the
169  * method session.login(User usr).
170  * <br /><br />
171  * Example:
172  * <pre>session.login("tobi", "mumbl3");
173  * res.write(session.user);
174  * <i>HopObject tobi</i>
175  * &nbsp;
176  * res.write(session.user.registered);
177  * <i>Thu Jun 28 17:25:33 CEST 2001</i>
178  * &nbsp;
179  * res.write(session.user["url"]);
180  * <i>http://helma.org</i></pre>
181  *
182  * @type User
183  */
184 session.user = new User();
185
186
187 /**
188  * A date object representing the time this user's session was last active.
189  * <br /><br />
190  * Contains the timestamp of the last web request, that
191  * has been submitted by that client. This property is
192  * read-only, but can be set to the current time through
193  * session.touch().
194  * <br /><br />
195  * For new sessions, if the session represents a
196  * registered user the result equals the date the user
197  * was logged in the last time; otherwise the result
198  * equals the current date.
199  * <br /><br />
200  * This property is read-only
201  * <br /><br />
202  * Example:
203  * <pre>res.write(session.lastActive())
204  * <i>Thu Nov 02 16:12:13 GMT+01:00 2000</i></pre>
205  *
206  * @return Date of last request by this user
207  * @type Date
208  */
209 session.lastActive = function() {};
210
211
212 /**
213  * Logs in a user defined by its name and a password phrase, or by directly passing a HopObject.
214  * <br /><br />
215  * There are two variants of session.login():
216  * <br /><br />
217  * If called with one HopObject argument, the session
218  * is associated with the user represented by the
219  * HopObject.
220  * <br /><br />
221  * If called with two string arguments, it returns true
222  * if the user name / password pair matches the stored
223  * values in the database and false otherwise.
224  * <br /><br />
225  * Associates the passed User to that session,
226  * i.e. logs the client in as that User. The property
227  * user of the session object will refer to the User.
228  * <br /><br />
229  * Example:
230  * <pre>var login = session.login("tobi", "mumbl3");
231  * if (login)
232  * &nbsp;&nbsp;res.write("Welcome back, " + session.user.name + "!");
233  * else
234  * &nbsp;&nbsp;res.write("Oops, please try again...");
235  * <i>Welcome back, tobi!</i></pre>
236  *
237  * @param {User|String} user either as User object to be logged in or the username to be checked as string
238  * @param {String} password as String, if the first parameter is a username
239  * @return Boolean true if the user was logged in, otherwise false
240  * @type Boolean
241  */
242 session.login = function(user,password) {};
243
244
245 /**
246  * Logs out a user.
247  * <br /><br />
248  * Removes the reference to a User associated with
249  * the current session, if such a reference exists.
250  * Additionally the global function onLogout will
251  * be called.
252  * <br /><br />
253  * Example:
254  * <pre>res.write(session);
255  * <i>[Session for user tobi]</i>
256  * &nbsp;
257  * session.logout();
258  * res.write(session);
259  * <i>[Anonymous Session]</i></pre>
260  */
261 session.logout = function() {};
262
263
264 /**
265  * A date object representing the time a user's session was started.
266  * <br /><br />
267  * This property is read-only.
268  * <br /><br />
269  * Example:
270  * <pre>res.write(session.onSince());
271  * <i>Fri Aug 10 16:36:36 GMT+02:00 2001</i></pre>
272  *
273  * @return Date when the current session was started.
274  * @type Date
275  */
276 session.onSince = function() {};
277
278
279 /**
280  * Refreshes the user's session.
281  * <br /><br />
282  * The session's expiration date is set to the current date
283  * plus session timeout. This also happens automatically
284  * when a user request is sent to Helma.
285  * <br /><br />
286  * The lastActive property will be set to the current
287  * timestamp. Useful to artificially avoid a session timeout.
288  * <br /><br />
289  * Example:
290  * <pre>res.writeln(session.lastActive);
291  * <i>Fri Jul 12 14:40:20 CEST 2002</i>
292  * &nbsp;
293  * session.touch();
294  * &nbsp;
295  * res.writeln(session.lastActive);
296  * <i>Fri Jul 12 14:55:20 CEST 2002</i></pre>
297  */     
298 session.touch = function() {};
299
Note: See TracBrowser for help on using the browser.