How to set a Session Variable during Login Logic
How to set a Session Variable during Login Logic
- Subject: How to set a Session Variable during Login Logic
- From: <email@hidden>
- Date: Tue, 3 Dec 2002 17:13:10 +0000 (GMT)
I want to set a boolean key (called
isUserAdministrator) within the session.java code.
This key will be consulted by conditionals throughout
the rest of the Web App as to whether any edit buttons
are displayed.
I have a EOModel for a users table that has username,
password and isAdministrator attributes. The code
below is my main.java code that Authenticates the user
and password. I need to access the third attribute
behind the scenes and set the Session Boolean Key to
true if the isAdministrator value = "y".
Can anybody give me a tip (or even better the code) on
how to do this? Any help would greatly be appreciated.
Thanks
Toby Beedell
------------- Main.java ---------------
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.directtoweb.*;
import com.webobjects.foundation.*;
import com.webobjects.eoaccess.*;
import java.util.*;
public class Main extends WOComponent {
public String username;
public String password;
public boolean wantsWebAssistant=false;
public Main(WOContext aContext) {
super(aContext);
}
public WOComponent defaultPage() {
D2W.factory().setWebAssistantEnabled(wantsWebAssistant);
return D2W.factory().defaultPage(session());
return pageWithName("PAC_QueryART");
}
public WOComponent login() {
if (isAuthenticated())
return defaultPage();
return null;
}
public boolean isAuthenticated() {
NSMutableDictionary userCredentials = new
NSMutableDictionary();
if (username == null || password == null)
return false;
userCredentials.setObjectForKey(username,
"loginusername");
userCredentials.setObjectForKey(password,
"userspassword");
NSArray foundObjects =
EOUtilities.objectsMatchingValues(session().defaultEditingContext(),
"USERDETAILS", userCredentials);
if (foundObjects.count() == 1) {
return true;
}
NSLog.out.appendln("Authentication failed.");
return false;
}
}
------------- Session.java ---------------
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
public class Session extends WOSession {
protected boolean isUserAdministrator;
protected String userAdministratorStatus;
public Session() {
super();
/* ** Put your per-session initialization code
here ** */
}
public boolean isUserAdministrator() {
if (userAdministratorStatus == "y") {
return true;
} else {
return false;
}
}
}
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.