• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple Stuff Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple Stuff Help


  • Subject: Re: Simple Stuff Help
  • From: David LeBer <email@hidden>
  • Date: Sat, 15 Mar 2008 00:24:14 -0400


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


_______________________________________________ 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
  • Follow-Ups:
    • Re: Simple Stuff Help
      • From: Gustavo Pizano <email@hidden>
References: 
 >Simple Stuff Help (From: Gustavo Pizano <email@hidden>)
 >Re: Simple Stuff Help (From: Chuck Hill <email@hidden>)
 >Re: Simple Stuff Help (From: Gustavo Pizano <email@hidden>)

  • Prev by Date: Re: Simple Stuff Help
  • Next by Date: Re: WWDC 08
  • Previous by thread: Re: Simple Stuff Help
  • Next by thread: Re: Simple Stuff Help
  • Index(es):
    • Date
    • Thread