Re: Simple Stuff Help
Re: Simple Stuff Help
- Subject: Re: Simple Stuff Help
- From: David LeBer <email@hidden>
- Date: Sat, 15 Mar 2008 18:26:45 -0400
On 15-Mar-08, at 6:07 PM, Gustavo Pizano wrote:
Hello David,
Im doing as Im thinking it can be done based on the tip you send me,
it has some errors, i know. this is what im doing,
public WOComponent loginAction(){
Usuarios user = fetchUserWithCredentials();
WOComponent nextPage = null;
if (user != null){
}
return null;
}
public Usuarios fetchUserWithCredentials(){
Usuarios user = null;
EOEditingContext editingContext = this.defaultEditingContext();
NSMutableDictionary bindings = new NSMutableDictionary();
bindings.takeValueForKey(usrName,Usuarios.USERID_KEY);
bindings.takeValueForKey(password,Usuarios.PASSWORD_KEY);
try {
user = (Usuarios)
EOUtilities.objectMatchingValues(editingContext,
Usuarios.ENTITY_NAME, bindings);
} catch (EOObjectNotAvailableException e) {
// Couldn't find a match
// TODO
// might want to set a message variable so you can
// tell the user...
}
return user;
}
these methots are in the session.java... is it good idea to have
them there?
Well, when I wrote the sample I expected it to be in the
YourLoginComponent.java but you could put it anywhere I guess.
I'd probably keep the logingAction in the component and maybe move the
fetchUserWithCredentials into the session.
adn second, I know that the names in the tables of a db can be in
plural, but not the name of a java class, nto becuase of errors but
because of convention,
so what can I do there,?? make another class cales Usuario who
extends from Usuarios? (thats my thinking)
No, fix your model:
Entity name: Usuario
Table Name: USUARIOS // or whatever
Class Name: com.yourco.yourproj.model.Usuario
and second
dunno understand this line very well..
((Session)session()).setCurrentUser(person);
Well, again, my assumption was that he loginAction was in a component.
So after a successful login you'd want to keep the current user
around. A logical place for that would be in the session.
...in Session.java...
private Usuario _currentUser;
...
public Usuario currentUser() {
return _currentUser;
}
public voic setCurrentUser(Usuario u) {
_currentUser = u;
}
its not a session method ...
what to do with that methog, I understand is to assing the session
to that User.
Gus
On Mar 14, 2008, at 11:24 PM, David LeBer wrote:
On 14-Mar-08, at 11:30 PM, Gustavo Pizano wrote:
WOW Hold On!!
this is what i made form what I learned from teh tutrial, I
created a EOModel called UsersModel and there I create an entity
called Users which contains the follwoing atributes
lastName varchar(20)
name varchar(20)
userid int PK
admin_privilege_key int
password varchar(20)
so what im planing its to give the last atribute a valor of 1 or 0
depending if its admin or client respectlyvzly
I generated the EO
which has the accessors.
I was thinkin in make a WO called login with a form with
username(which it will be the id) and the password
so form there to the session.
Im assuming that I have some data already in the db.(at least an
admin and a client, for tests purposes )
so if its an admin it will open a new page (wo) which will have
(for now) an insert user, and all its attributes. and display all
the users or an specified user.
and if its a client then... well i dunno what to display so far
for the client.
What im having problem in understandin its about the
EOEditingContex, like WTH is that, i have something in my mind i
just need to assimilate it.
and well I wanna get the user who is loggin from the database to
see if its a admin or client. so i think i must use this
valueForKey(Stringkey)
and this should be in the Session.java no? just that something is
telling me I must use the EOEditingcontexts no?
An EOEditingContext (ec) is a sandbox that contains the
EOEnterpriseObjects (eo) you are working with. It tracks the
changes, inserts, deletes, etc, and when you call ec.saveChanges();
EOF looks at everything that has changed, generates the SQL, and
updates the db.
If you look at the methods listed here: <http://wiki.objectstyle.org/confluence/display/WO/Programming__WebObjects-EOF-Using+EOF-Fetching
> you will see that anytime you fetch from the db you need to
supply an ec to tell EOF what sandbox you want the eos to end up in.
So what you want to do is fetch the the User matching a given
username and password (using one of the methods listed in that wiki
page) and then ask it if is an admin and decide what page to
deliver. (I don't know what attribute name you gave to
admin_privilege_key so I chose isAdmin)
public String username; //
public String password;
public WOComponent loginAction() {
Person person = fetchUserWithCredentials();
WOComponent nextPage = null;
if (person != null) {
((Session)session()).setCurrentUser(person);
if (person.isAdmin().equals(new Integer(1)) {
nextPage = pageWithName("AdminUserLandingPage");
} else {
nextPage = pageWithName("RegularUserLandingPage");
}
}
return nextPage;
}
private Person fetchUserWithCredentials() {
// TODO
//Probably would want to validate that both a username and
password were
// were supplied here...
Person person = null;
EOEditingContext editingContext = session().defaultEditingContext();
NSMutableDictionary bindings = new NSMutableDictionary();
bindings.takeValueForKey(username, Person.USERNAME_KEY);
bindings.takeValueForKey(password, Person.PASSWORD_KEY);
try {
person = EOUtilities.objectMatchingValues(editingContext,
Person.ENTITY_NAME, bindings);
} catch (EOObjectNotAvailableException e) {
// Couldn't find a match
// TODO
// might want to set a message variable so you can
// tell the user...
}
return person;
}
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden