• 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 form based db auth
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie form based db auth


  • Subject: Re: Newbie form based db auth
  • From: james o <email@hidden>
  • Date: Fri, 2 May 2003 11:23:14 -0400

alvaro, here's a simple login page i ripped from the WOMovies example.
there's probably a 1000 ways to skin this cat.  good luck.

hth,
./james




public class LoginPage extends WOComponent {

    public Login loginFound;

    public String loginCheck, password;

    public boolean incorrect;

    public EOEditingContext editingContext;
    public EOQualifier qualifier;
    public EOFetchSpecification fetchSpec;

    public LoginPage(WOContext context) {
        super(context);
        editingContext = session().defaultEditingContext();
    }

// if the login is correct we'll send the user to page UserHome
// "startLogin" method is called from your form
// "loginCheck" and "password" are the strings we'll be searching for in our database
// bind them to your form


    public UserHome startLogin()
    {

//if the user hasn't entered any data return incorrect
//on my page i trigger a WOConditional that says something like, "Sorry, Username and Password Doesn't Match"
if (loginCheck == null || password == null ) {
incorrect = true;
return null;
}


//run the validateUser method below - you're sending it the strings, "loginCheck" and "password"
validateUser(loginCheck, password);


//if incorrect = true we're going to return them to the page the incorrect WOConditional will appear
if ( incorrect ){
return null;
}


        //if !incorrect we've found a match...
        //do stuff with your found login object

        //it's good - send loginFound to session
        //((Session)session()).assignLogin(loginFound);

        //go to the UserHome page now...
        UserHome nextPage = (UserHome)pageWithName("UserHome");
 	//you could do something like nextPage.sendLogin(loginFound);
        return nextPage;
    }

public EOEnterpriseObject ValidateUser(String username, String password){

        NSMutableArray args = new NSMutableArray();

        EOEditingContext ec=new EOEditingContext();
        args.addObject(username);
        args.addObject(password);

	//create the qualifier with username and password
        qualifier = EOQualifier.qualifierWithQualifierFormat
            ("username = %@ AND password = %@", args);

	//search the table "Users" for the username and password
        fetchSpec=new EOFetchSpecification("Users", qual, null);

//create an array with the found object...
//there's probably an EOUtility class that you could find an object with
//two strings... however, this works.
NSArray im=ec.objectsWithFetchSpecification(fs);
//if login found
if(im.count()==1){
loginFound = (Login)im.objectAtIndex(0);
incorrect = false;
return selectedLogin;
}


        else
            //NSLog.out.appendln("no matches found ");
        incorrect = true;
        return null;
    }
}
_______________________________________________
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.

References: 
 >Newbie form based db auth (From: Alvaro Muir <email@hidden>)

  • Prev by Date: API changes
  • Next by Date: Re: API changes
  • Previous by thread: Newbie form based db auth
  • Next by thread: Re: Newbie form based db auth
  • Index(es):
    • Date
    • Thread