added global UI properties, cookie-reading APIs to CookieControl, moved
HttpVeniceUISession initialization into a script file (session_init.js)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
//
|
||||
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
// Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
// Copyright (C) 2001-2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
|
||||
@@ -96,8 +96,9 @@ else if (op=="login")
|
||||
if (dlg.getValue("saveme").booleanValue())
|
||||
{ // If the user wants a cookie, give it to them!
|
||||
cctl = vlib.queryCookieControl(rinput);
|
||||
cctl.savePersistentCookie(CookieControl.LOGIN_COOKIE,user.getAuthenticationToken(),
|
||||
CookieControl.LOGIN_COOKIE_AGE);
|
||||
cctl.savePersistentCookie(rinput.getConfigProperty("login.cookie"),user.getAuthenticationToken(),
|
||||
vlib.toInteger(rinput.getConfigProperty("login.cookie.age")));
|
||||
|
||||
} // end if
|
||||
|
||||
// Clear the left menus (to force recomputation) and bounce us back to whereever we were
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
// Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
// Copyright (C) 2001-2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
|
||||
@@ -31,7 +31,7 @@ if (user.isLoggedIn())
|
||||
{ // user is logged in - we want to log out
|
||||
// TODO: only remove the login cookie if it was actually set!
|
||||
cctl = vlib.queryCookieControl(rinput);
|
||||
cctl.deleteCookie(CookieControl.LOGIN_COOKIE); // remove the login cookie
|
||||
cctl.deleteCookie(rinput.getConfigProperty("login.cookie")); // remove the login cookie
|
||||
sctl = vlib.querySessionControl(rinput);
|
||||
sctl.endSession();
|
||||
|
||||
|
||||
50
scripts/session_init.js
Normal file
50
scripts/session_init.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
// (the "License"); you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
// language governing rights and limitations under the License.
|
||||
//
|
||||
// The Original Code is the Venice Web Communities System.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
// Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
|
||||
importPackage(Packages.com.silverwrist.venice.core);
|
||||
importPackage(Packages.com.silverwrist.venice.except);
|
||||
importPackage(Packages.com.silverwrist.venice.ui);
|
||||
importPackage(Packages.com.silverwrist.venice.ui.helpers);
|
||||
|
||||
// Get the request and the session.
|
||||
rinput = bsf.lookupBean("request");
|
||||
sess = vlib.castVeniceUISession(bsf.lookupBean("session"));
|
||||
|
||||
// Get the login cookie name and the CookieControl service.
|
||||
cookie_name = rinput.getConfigProperty("login.cookie");
|
||||
cctl = vlib.queryCookieControl(rinput);
|
||||
if (cctl.isCookiePresent(cookie_name))
|
||||
{ // get the login cookie value and try to use it to log in
|
||||
logger.debug("cookie " + cookie_name + " found");
|
||||
logged_in = false;
|
||||
try
|
||||
{ // attempt to log the user in with the cookie
|
||||
logged_in = sess.user.authenticateWithToken(cctl.getCookie(cookie_name));
|
||||
|
||||
} // end try
|
||||
catch (e)
|
||||
{ // login failed
|
||||
logger.error("caught " + vlib.exceptionType(e) + ": " + e.message);
|
||||
logged_in = false;
|
||||
|
||||
} // end catch
|
||||
|
||||
if (!logged_in) // not logged in - delete the cookie
|
||||
cctl.deleteCookie(cookie_name);
|
||||
|
||||
} // end if
|
||||
else
|
||||
logger.debug("cookie " + cookie_name + " not found");
|
||||
Reference in New Issue
Block a user