package votorola.a.web.wic.authen; // Copyright 2008-2013, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;
import votorola.a.web.wic.*;
import votorola.g.lang.*;
import votorola.g.locale.*;
/** An alias test login option for a login page. It includes an HTML text field backed by a
* Java string field "aliasInput", which must be present in the login page.
*
* @see WC_Alias.html
*/
@ThreadRestricted("wicket") final class WC_Alias extends Panel
{
/** Constructs a WC_Alias.
*
* @param page the login page in which the option will appear.
*/
WC_Alias( final String id, final VPageHTML page, final VRequestCycle cycle )
{
super( id );
final BundleFormatter bun = cycle.bunW();
add( new Label( "or",
bun.l( "a.web.wic.authen.WP_Login.or_XHT" )).setEscapeModelStrings( false ));
add( new Label( "or-test", bun.l( "a.web.wic.authen.WP_Login.or-test" )));
add( new Label( "aliasLabel", bun.l( "a.web.wic.authen.WP_Login.alias" )));
final TextField field = new TextField( "alias",
new PropertyModel( page, "aliasInput" ));
VPageHTML.invalidStyled( VPageHTML.inputLengthConstrained( field ));
add( field );
add( new Label( "aliasDescription",
bun.l( "a.web.wic.authen.WP_Login.aliasDescription" )));
}
// ------------------------------------------------------------------------------------
/** Converts a user's chosen alias to an email address.
*/
static @ThreadSafe String toEmail( final String alias )
{
final StringBuilder b = new StringBuilder( 32 );
for( int c = 0, cN = alias.length(); c < cN; ++c )
{
if( b.length() >= 60 ) break; // max for local part actually 64, per qmail addresses(5)
char ch = alias.charAt( c );
// ch = Character.toUpperCase( ch ); // make the aliases stand out in the UI
// if( (ch < '0' || ch > '9') && (ch < 'A' || ch > 'Z') ) ch = '-';
//// not till I normalize them, currently that's a BUG (normalize?)
// ch = Character.toLowerCase( ch );
// if( (ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') ) ch = '-'; // potentially illegal
//// but allow mixed case, e.g. for descriptive naming of pseudo-pipes
if( (ch < '0' || ch > '9')
&& (ch < 'A' || ch > 'Z')
&& (ch < 'a' || ch > 'z') ) ch = '-'; // potentially illegal
b.append( ch );
}
final String prefix = "test-";
if( !b.toString().startsWith( prefix )) b.insert( 0, prefix );
b.append( "@zelea.com" );
return b.toString();
}
}