• 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: [Newbie] Using FetchSpecs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Newbie] Using FetchSpecs


  • Subject: Re: [Newbie] Using FetchSpecs
  • From: Kieran Kelleher <email@hidden>
  • Date: Fri, 30 Apr 2004 22:04:41 -0400

............ and with attachment 2 of 2

On Apr 30, 2004, at 9:55 PM, Kieran Kelleher wrote:

Forget the drag the fetchSpec. Just make your two WOTextFields
andmanually type the 'value' bindings. Remember just because a binding
is not visible to the WO Builder GUI, it does not mean the binding is
not available at runtime. Here is an example of a login method I used
recently on a login page of a simple app.

    /*****************************************
     * Log in
     ****************************************/
     public WOComponent loginAction()
     {
	String shaPassword;

	// check that neither of the fields were empty
	if ( (loginEntries.objectForKey("loginName") == null ) ||
	     (loginEntries.objectForKey("password") == null) ) {
	    isBadLogin = true;
	    loginEntries.removeAllObjects();
	    return null;
	}

	// get the editing context
	EOEditingContext ec = session().defaultEditingContext();

         // get the fetch specification
	EOFetchSpecification fs =
	    EOFetchSpecification.fetchSpecificationNamed("fetch login user",
							 "EPUser");

	try {
	    // next SHA hash the password
	    shaPassword = new String( WKPassword.getEncodedPassword(
(String)loginEntries.objectForKey("password"),
"SHA") );
	}

	catch (NoSuchAlgorithmException e) {
	    System.out.println( "SHA encryption not available!: " +
e.toString());
	    shaPassword = new String("");
	}

	// redefine the key to be the SHA encoded password
	loginEntries.setObjectForKey(shaPassword, "password");

	System.out.println("Password after SHA: " +
(String)loginEntries.objectForKey("password"));

	// make the boundFs
	EOFetchSpecification boundFs =
	    fs.fetchSpecificationWithQualifierBindings(loginEntries);

	// Fetch matching objects
	NSArray fetchResults = ec.objectsWithFetchSpecification(boundFs);

	// if we found it, there should be only one, so let's work with first
one only
	if (fetchResults.count() > 0) {
	    /* we found it */

	    // if more than one, let's log it
	    if (fetchResults.count() > 1) {

	    }

	    // set session authenticated flag
	    Session session = (Session)session();
	    session.setAuthenticated(true);
	    session.setTheUser(
(EOEnterpriseObject)fetchResults.objectAtIndex(0) );

	} else {
	    isBadLogin = true;
	}

	// clear the user login data
	loginEntries.removeAllObjects();

         return null;
     } // end loginAction


The constructor of the component creates a new NSMutablbeDictionary
loginEntries. You have to MANUALLY type the bindings
loginEntries.username and loginEntries.password. I store the password
as an SHA encrypted string. I have two utility classes attached that
supports this. Essentially I just convert the password to the SHA
encrypted string before calling the fetchSpec.

[demime 0.98b removed an attachment of type multipart/appledouble]
_______________________________________________
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.


  • Follow-Ups:
    • Re: [Newbie] Using FetchSpecs
      • From: Kieran Kelleher <email@hidden>
    • Re: [Newbie] Using FetchSpecs
      • From: Kieran Kelleher <email@hidden>
References: 
 >[Newbie] Using FetchSpecs (From: Lucas Haley <email@hidden>)

  • Prev by Date: EOM: Keeping two Schemas in Synch
  • Next by Date: Re: [Newbie] Using FetchSpecs
  • Previous by thread: Re: [Newbie] Using FetchSpecs
  • Next by thread: Re: [Newbie] Using FetchSpecs
  • Index(es):
    • Date
    • Thread