You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by jake123 <ja...@gmail.com> on 2006/09/25 21:21:22 UTC

Login/Change Pasword Component

Hi, I am trying to write a component that will handle my login into my secure
pages in my application. When I am logged in the component will display that
name of the logged in user and some other information. I will also have a
for where the user can change password. The form contains Old Password, New
Password and Confirmnew Password label and input box and a button connected
to a listener. I have validation on the input boxes for required valie and a
min length. but I the validation pass this step I want to add some more
validation in my onChangePassword() metod. I want to check the old Password
agains the db, and also that new password and confirm password are the same
before I update the db. So My question is this: how do I add my own errors
in the onChangePassword() listener method to the delegate that the allready
done the basic validation. My .page file for these  (labels and input boxes)
look like this:

 <!-- CHANGE PASSWORD FORM  -->	
		<component id="changePasswordForm" type="Form" >
			<binding name="listener" value="listener:onChangePassword" />
			<binding name="delegate" value="beans.delegate" />
		</component>
	
		<!-- INPUT BOXES -->
		<component id="inputOldPassword" type="TextField" >
	        <binding name="value" value="oldPassword" />
	        <binding name="hidden" value="true" />    
	    	<binding name="displayName" value="literal:Old Password"/>
	    	<binding name="validators" value="validators:required,minLength=5" />
	    </component>
	    
	    <component id="inputNewPassword" type="TextField">
	   		<binding name="value" value="newPassword" /> 
	   		<binding name="hidden" value="true" />
	        <binding name="displayName" value="literal:New Password"/>
	        <binding name="validators" value="validators:required,minLength=5"
/>
	    </component>
	    
	    <component id="inputConfirmNewPassword" type="TextField">
	   		<binding name="value" value="confirmNewPassword" /> 
	   		<binding name="hidden" value="true" />
	        <binding name="displayName" value="literal:Confirm New Password"/>
	        <binding name="validators" value="validators:required,minLength=5"
/>
	    </component>
	    
	    <!-- LABELS -->
	    <component id="oldPasswordLabel" type="FieldLabel" >
	    	<binding name="field" value="component:inputOldPassword" />
	    </component>
	    
	    <component id="newPasswordLabel" type="FieldLabel" >
	    	<binding name="field" value="component:inputNewPassword" />
	    </component>
	    
	    <component id="confirmNewPasswordLabel" type="FieldLabel" >
	    	<binding name="field" value="component:inputConfirmNewPassword" />
	    </component>
	
		<!-- VALIDATION -->
		<property name="changePasswordCurrentFieldTracking" />
		
		<component id="changePasswordErrors" type="For" >
			<binding name="source" value="beans.delegate.fieldTracking" />
			<binding name="value" value="changePasswordCurrentFieldTracking" />
		</component>
		
		<component id="changePasswordError" type="Delegator" >
			<binding name="delegate"
value="changePasswordCurrentFieldTracking.errorRenderer" />
		</component>
		
		<component id="changepasswordIsInError" type="If">
			<binding name="condition"
value="changePasswordCurrentFieldTracking.inError" />
		</component>


and my onchangePassword() look like this:

	public String onChangePassword() {
		ValidationDelegate delegate = getDelegate();

		if (delegate.getHasErrors()) {
			return null;
		} else {
			/* check if oldPassword  match password from db */
			AppUserService appUserService =
(AppUserService)getServiceLocator().locate("appUserService");
			AppUser currentUser =
appUserService.getUserByPrimaryKey(getSessionUserInfo().getUserName());
			if (!currentUser.getUserPassword().equals(getOldPassword())) {
				//TODO : Add error message
				System.out.println("Login: onChangePassword - Old Password is not equals
with password from db");
			}			
			/* check that newPassword and confirmNewPassword are the same */
			if (!getNewPassword().equals(getConfirmedNewPassword())) {
				//TODO : add error message
				System.out.println("Login: onChangePassword - New Password is not equal
with confirm new Password");
			}			
			/* check if there is any new errors before updating AppUser */
			if (delegate.getHasErrors()) {
				return null;
			} else {
				/* set the new username to appUser and then Update */
				currentUser.setUserPassword(getNewPassword());
				appUserService.saveOrUpdateAppUser(currentUser);
				/* add update message */
				setUpdateMessage("Your password has been changed!");
			}			
		}		
		return null;
	}

Thanks
Jacob
-- 
View this message in context: http://www.nabble.com/Login-Change-Pasword-Component-tf2333791.html#a6493456
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Login/Change Pasword Component

Posted by Jesse Kuhnert <jk...@gmail.com>.
I think you can just call getBean("delegate") in your listener method and
add your custom errors to that directly.

You might want to download one of the tapestry sample applications or look
the the jumpstart site to see how a somewhat fully functional application
might do:
http://tapestry.apache.org/tapestry4.1/QuickStart/contributed.html

On 9/25/06, jake123 <ja...@gmail.com> wrote:
>
>
> Hi, I am trying to write a component that will handle my login into my
> secure
> pages in my application. When I am logged in the component will display
> that
> name of the logged in user and some other information. I will also have a
> for where the user can change password. The form contains Old Password,
> New
> Password and Confirmnew Password label and input box and a button
> connected
> to a listener. I have validation on the input boxes for required valie and
> a
> min length. but I the validation pass this step I want to add some more
> validation in my onChangePassword() metod. I want to check the old
> Password
> agains the db, and also that new password and confirm password are the
> same
> before I update the db. So My question is this: how do I add my own errors
> in the onChangePassword() listener method to the delegate that the
> allready
> done the basic validation. My .page file for these  (labels and input
> boxes)
> look like this:
>
> <!-- CHANGE PASSWORD FORM  -->
>                 <component id="changePasswordForm" type="Form" >
>                         <binding name="listener"
> value="listener:onChangePassword" />
>                         <binding name="delegate" value="beans.delegate" />
>                 </component>
>
>                 <!-- INPUT BOXES -->
>                 <component id="inputOldPassword" type="TextField" >
>                 <binding name="value" value="oldPassword" />
>                 <binding name="hidden" value="true" />
>                 <binding name="displayName" value="literal:Old Password"/>
>                 <binding name="validators"
> value="validators:required,minLength=5" />
>             </component>
>
>             <component id="inputNewPassword" type="TextField">
>                         <binding name="value" value="newPassword" />
>                         <binding name="hidden" value="true" />
>                 <binding name="displayName" value="literal:New Password"/>
>                 <binding name="validators"
> value="validators:required,minLength=5"
> />
>             </component>
>
>             <component id="inputConfirmNewPassword" type="TextField">
>                         <binding name="value" value="confirmNewPassword"
> />
>                         <binding name="hidden" value="true" />
>                 <binding name="displayName" value="literal:Confirm New
> Password"/>
>                 <binding name="validators"
> value="validators:required,minLength=5"
> />
>             </component>
>
>             <!-- LABELS -->
>             <component id="oldPasswordLabel" type="FieldLabel" >
>                 <binding name="field" value="component:inputOldPassword"
> />
>             </component>
>
>             <component id="newPasswordLabel" type="FieldLabel" >
>                 <binding name="field" value="component:inputNewPassword"
> />
>             </component>
>
>             <component id="confirmNewPasswordLabel" type="FieldLabel" >
>                 <binding name="field"
> value="component:inputConfirmNewPassword" />
>             </component>
>
>                 <!-- VALIDATION -->
>                 <property name="changePasswordCurrentFieldTracking" />
>
>                 <component id="changePasswordErrors" type="For" >
>                         <binding name="source" value="
> beans.delegate.fieldTracking" />
>                         <binding name="value"
> value="changePasswordCurrentFieldTracking" />
>                 </component>
>
>                 <component id="changePasswordError" type="Delegator" >
>                         <binding name="delegate"
> value="changePasswordCurrentFieldTracking.errorRenderer" />
>                 </component>
>
>                 <component id="changepasswordIsInError" type="If">
>                         <binding name="condition"
> value="changePasswordCurrentFieldTracking.inError" />
>                 </component>
>
>
> and my onchangePassword() look like this:
>
>         public String onChangePassword() {
>                 ValidationDelegate delegate = getDelegate();
>
>                 if (delegate.getHasErrors()) {
>                         return null;
>                 } else {
>                         /* check if oldPassword  match password from db */
>                         AppUserService appUserService =
> (AppUserService)getServiceLocator().locate("appUserService");
>                         AppUser currentUser =
> appUserService.getUserByPrimaryKey(getSessionUserInfo().getUserName());
>                         if
> (!currentUser.getUserPassword().equals(getOldPassword())) {
>                                 //TODO : Add error message
>                                 System.out.println("Login:
> onChangePassword - Old Password is not equals
> with password from db");
>                         }
>                         /* check that newPassword and confirmNewPassword
> are the same */
>                         if
> (!getNewPassword().equals(getConfirmedNewPassword())) {
>                                 //TODO : add error message
>                                 System.out.println("Login:
> onChangePassword - New Password is not equal
> with confirm new Password");
>                         }
>                         /* check if there is any new errors before
> updating AppUser */
>                         if (delegate.getHasErrors()) {
>                                 return null;
>                         } else {
>                                 /* set the new username to appUser and
> then Update */
>                                 currentUser.setUserPassword
> (getNewPassword());
>                                 appUserService.saveOrUpdateAppUser
> (currentUser);
>                                 /* add update message */
>                                 setUpdateMessage("Your password has been
> changed!");
>                         }
>                 }
>                 return null;
>         }
>
> Thanks
> Jacob
> --
> View this message in context:
> http://www.nabble.com/Login-Change-Pasword-Component-tf2333791.html#a6493456
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo/(and a dash of TestNG), team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com