Site Utilities
Login Form 
- Class name: (k-login)
- Version: 1.0
-
jQuery Interactive feature
-
Tapestry Integration
Login form may appear directly on a page or it may appear in a collapsible form, opened by clicking on the "Please, sign-in" link.
If you want the login form to appear opened on a page, simply remove the class "collapsible" from the form tag.
HTML5 Plain Code
-
<form id="login" class="k-login" method="post" action="">
-
<fieldset>
-
<legend>Sign in</legend>
-
<p><label for="userid-tag">User identifier</label>
-
<input type="text" id="userid-tag" name="userid-tag" /></p>
-
<p><label for="password-tag">Password</label>
-
<input type="password" id="password-tag" name="password-tag" title="Password must include at least one digit and one special character" />
-
<span class="lost-password"><a href="#">Forgot your password?</a></span></p>
-
<p><input type="submit" value="ok" /></p>
-
</fieldset>
-
<p class="to-register">
-
<strong>Not registered yet ?</strong> » <a href="#">Register now</a></p>
-
</form>
CSS Code
-
form.k-login {color: #050505; background: #FFF;}
-
form.k-login fieldset {padding: 0; margin: 0;}
-
form.k-login fieldset p {padding: 0.5em 1em;}
-
form.k-login input[type=submit] {margin-top: 1em;}
-
.lost-password {display: block; font-size: 80%;}
-
p.to-register {
-
color: #FFF;
-
background: #808080;
-
padding: 0.5em 4%;
-
}
-
p.to-register a, p.to-register a:link, p.to-register a:visited {
-
color: #FFF;
-
background: #808080;
-
}
IE Backward Compatibility
In order to correct display bugs for Internet Explorer versions prior to 9, your html pages need to call the following file by Conditional Comments:
Simple Tapestry Integration
You may want to create an internationalized web site, here is an example of a properties file :
password-required=Password must include at least one digit and one special character
register=Not registered yet ?: >> Register now
forgotten-password=Forgot your password?
sign-in=Sign in
submit-label=OK
please-sign-in=Please, sign in
The Template
-
<t:kawwa2.CollapsiblePanel id="loginLink" t:header="please-sign-in">
-
<form t:type="form" t:id="loginForm" class="k-login collapsible">
-
<fieldset>
-
<legend>${message:sign-in}</legend>
-
<t:errors/>
-
<p><t:label t:for="login" />
-
<input t:type="textField" t:id="login"/></p>
-
<p><t:label t:for="password" />
-
<input t:type="passwordfield" t:id="password" class="k-field-comment" />
-
<span class="lost-password">
-
<a t:type="pagelink" t:page="collapsible">${message:forgotten-password}</a>
-
</span>
-
</p>
-
<p><input t:type="submit" value="${message:submit-label}" /></p>
-
</fieldset>
-
<p class="to-register">
-
<a t:type="pagelink" t:page="mainnav">
-
<t:outputraw t:value="message:register"/>
-
</a>
-
</p>
-
</form>
-
</t:kawwa2.CollapsiblePanel>
Java Implementation
-
@Property
-
@Validate(value="required")
-
private String login;
-
@Property
-
@Validate(value="required")
-
private String password;
-
@Component(id="loginForm")
-
private Form loginForm;
-
@Inject
-
private Messages messages;
-
/*@Inject
-
private your.business.package.UserManager userManager;*/
-
@OnEvent(value=EventConstants.VALIDATE, component="loginForm")
-
public void validation(){
-
//Test the values of login and password, or pass the values to your UserManager
-
//if(!userManager.successfullyAuthenticates(login, password)){
-
if(!"tapestry".equals(login) || !"tapestry".equals(password)){
-
String errorMessage = "Wrong login or password";
-
if(messages.contains("wrong-login-password"))
-
errorMessage = messages.get("wrong-login-password");
-
loginForm.recordError(errorMessage);
-
}
-
}
-
/*
-
* This method is only called if you've NOT used the "recordError" method exposed by the Form component
-
*/
-
@OnEvent(value=EventConstants.SUCCESS, component="loginForm")
-
public void loggingSuccess(){
-
//save the user in the session
-
}
-
/*
-
* This method is only called if you've used the "recordError" method exposed by the Form component
-
*/
-
@OnEvent(value=EventConstants.FAILURE, component="loginForm")
-
public void loggingFailure(){
-
//increment a persistent counter to limit the number of tries
-
}
-
/*
-
* This method is always called
-
*/
-
@OnEvent(value=EventConstants.SUBMIT, component="loginForm")
-
public void loggingSubmit(){
-
//
-
}
Advanced Tapestry Integration Based On Tapestry Security
Tynamo's tapestry-security is a comprehensive security module that provides tight integration with Apache Shiro, an established, high-performing and easy-to-use security framework for Tapestry applications.This project comes with a variety of components allowing you to easily get informations about the connected user.You only need to add the following dependency to your project, and then configure cautiously your project as explained in the guide.
<dependency>
<groupId>org.tynamo</groupId>
<artifactId>tapestry-security</artifactId>
<version>0.4.0</version>
</dependency>
Here is a list of components you can find in this project :
- Authenticated
- NotAuthenticated
- User
- Guest
- HasAnyRoles
- HasPermission
- HasRole
- LacksPermission
- LacksRole
- LoginForm
- LoginLink
NB: please note that the LoginForm component used in the template below isn't "kawwa2 compliant", you may prefer to use the form exposed at the top of the page, in the Simple Tapestry Implementation.
The Template
-
<t:security.notauthenticated>
-
<t:security.loginform />
-
</t:security.notauthenticated>
-
<t:security.authenticated>
-
Welcome ${currentUser.displayableName}! <t:actionlink t:id="logout">Logout</t:actionlink>
-
<div>
-
<t:security.haspermission permission="admin">
-
Can you feel the power of admin rights !?<br/>
-
<t:actionlink t:id="boom">This button will make the web site explose.</t:actionlink>
-
</t:security.haspermission>
-
<t:security.lackspermission permission="admin">
-
Sorry, as a stupid local user you can't do high level actions.
-
</t:security.lackspermission>
-
</div>
-
</t:security.authenticated>