Smutty
MVC Framework
Enigform Demo
If you don't already have the Enigform extension installed then you can download it from here. Before trying the login you'll have to add your public key, click on the next tab to do this. The login is done via Ajax.
To register your name and public key, just enter them into the form below and click the submit button.
#
# views/demo/enigform.tpl
#
{form url={ action="efLogin" } update="LoginResult"
feedback="LoginResult" gpgSigned="true"}
{field name="name" label="Name:"}
{submit text="Try Login"}
{form_end}
<div id="LoginResult"></div>
{form url={ action="efRegister" } feedback="RegisterResult"
update="RegisterResult" }
{field name="name" label="Name:"
url={ action="efCheckName" } update="NameCheck"}
<span id="NameCheck"></span>
{textarea name="public_key" label="Public Key:"}
{submit text="Register"}
{form_end}
<div id="RegisterResult"></div>
#
# controllers/DemoController.php
#
class DemoController extends Smutty_Controller {
function efLoginAction( $data ) {
if ( $key = $data->isVerified() ) {
$user = EnigformUser::find( $key->getKeyId(), 'gpgkeyid' );
if ( $user->name == $data->string('name') ) {
echo 'Welcome back ' . $user->name;
return;
}
}
echo 'Verification failed...';
}
function efRegisterAction( $data ) {
// check name isn't already taken
if ( !EnigformUser::find($data->string('name'),'name') ) {
$gpg = new Smutty_GPG();
// try and import the public key
if ( $key = $gpg->import($data->string('public_key')) ) {
$user = new EnigformUser();
$user->name = $data->string( 'name' );
$user->gpgkeyid = $key->getKeyId();
if ( $user->save() )
echo 'Registration Complete!';
else
echo 'could not save user';
}
else echo 'invalid public key';
}
else echo 'username is already taken';
}
function efCheckNameAction( $data ) {
if ( $name = $data->string('id') ) {
echo EnigformUser::fetchAll( false, array(
'name' => $name
)) ? 'Sorry, name taken...' : 'Username available!';
}
}
}