Previous | Next | WireHose Developers Guide |
Next, you'll add the code that makes the signup page work.
private WHTag _tag; public void setTag(WHTag value) { _tag = value; } public WHTag tag() { return _tag; }
createAccount
method will use an
errorMsg
method to return error messages to the user:
public WOActionResults errorMsg(String msg) { message = helper().stringInComponent(this, msg); password = ""; passwordAgain = ""; return context().page(); }
missingField = "Please enter all fields"; passwordMismatch = "Your password did not match"; reservedID = "Sorry, that login is reserved";
private NSArray fetchMatchingUsers() { EOQualifier q = new EOKeyValueQualifier( "login", EOQualifier.QualifierOperatorEqual, login); EOFetchSpecification fs = new EOFetchSpecification(WHApplicationHelper.userEntityName(), q, null, true, true, null); return session().defaultEditingContext().objectsWithFetchSpecification(fs); }
createAccount
method itself:
public WOActionResults createAccount() { // sanity check user input if (login == null || password == null || passwordAgain == null || "".equals(login) || "".equals(password) || "".equals(passwordAgain)) { return errorMsg("missingField"); } // make sure passwords match if (!password.equals(passwordAgain)) { return errorMsg("passwordMismatch"); } // make sure login wasn't already used NSArray users = fetchMatchingUsers(); if (users.count() != 0) { return errorMsg("reservedID"); } else { // never know what the current user entity might be WHUser user = (WHUser)WHEnterpriseObject.createAndInsertInstance( session().defaultEditingContext(), WHApplicationHelper.userEntityName(), WHApplicationHelper.defaultAffiliate()); user.setDateLastLogin(new NSTimestamp()); user.setLogin(login); user.setPassword(password); session().defaultEditingContext().saveChanges(); // replace the guest user for this session helper().setUser(user); WHTagDrillerPage nextPage = (WHTagDrillerPage)pageWithName(helper().nameForPage("WHTagDrillerPage")); nextPage.setTag(tag()); WOActionResults response = nextPage.addTag(); // set a login cookie if the user asked for it if (shouldSaveCookie) { return helper().addLoginCookieToResponse(response.generateResponse()); } else { return response; } } }
http://127.0.0.1:2020/
Note: Several WireHose components, including the WHEditFetcher shown here, have a binding called hideDetails. If this binding resolves to true, then WHEditFetcher will show an abbreviated version of itself. See the NewsDemo sample application for an example which allows the user to control this with a pair of hide details/show details controls. |
Copyright ©2000-2003 Gary Teter. All rights reserved. WireHose is a trademark of Gary Teter.