Re: How to set a Session Variable during Login Logic
Re: How to set a Session Variable during Login Logic
- Subject: Re: How to set a Session Variable during Login Logic
- From: Art Isbell <email@hidden>
- Date: Tue, 3 Dec 2002 08:12:05 -1000
On Tuesday, December 3, 2002, at 07:13 AM,
<email@hidden> wrote:
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?
Something like the following should be headed in the right direction.
------------- Main.java ---------------
public class Main extends WOComponent {
public String username;
public String password;
public boolean isAuthenticated() {
NSMutableDictionary userCredentials = new
NSMutableDictionary();
if (username == null || password == null)
return false;
userCredentials.setObjectForKey(username,
"loginusername");
userCredentials.setObjectForKey(password,
"userspassword");
Session session = (Session)session();
NSArray foundObjects =
EOUtilities.objectsMatchingValues(session.defaultEditingContext(),
"USERDETAILS", userCredentials);
if (foundObjects.count() == 1) {
EOEnterpriseObject user =
(EOEnterpriseObject)foundObjects.lastObject();
String isAdministrator = (String)user.valueForKey("isAdministrator");
boolean isAdmin = ((isAdministrator != null) &&
isAdministrator.equals("y"));
session.setIsUserAdministrator(isAdmin);
return true;
}
NSLog.out.appendln("Authentication failed.");
session.setIsUserAdministrator(false);
return false;
}
}
------------- Session.java ---------------
public class Session extends WOSession {
protected boolean isUserAdministrator;
public void setIsUserAdministrator(boolean aFlag) {
isUserAdministrator = aFlag;
}
public boolean isUserAdministrator() {
return isUserAdministrator;
}
}
Art
_______________________________________________
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.