Source for file class.login.php
Documentation is available at class.login.php
require_once 'HTML/AJAX/Action.php';
define('ERR_USERNAME_EMPTY', 'You forgot to enter a username, please try again');
define('ERR_USERNAME_INVALID', 'The username you entered is invalid. Please try "peter" (without quotes)');
define('ERR_PASSWORD_EMPTY', 'You forgot to enter a password, please try again');
define('ERR_PASSWORD_INVALID', 'The password you entered is invalid. Please try "gabriel" (without quotes)');
define('ERR_EMAIL_EMPTY', 'You forgot to enter an e-mail address');
define('ERR_EMAIL_INVALID', 'The e-mail address you entered is invalid. Please enter a valid e-mail address.');
* Login class used in the "login form" example
* Please note: Constructors and private methods marked with _ are never exported in proxies to JavaScript
* @author Gilles van den Hoven <gilles@webunity.nl>
* @copyright 2005 Gilles van den Hoven
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: 0.5.7
* @link http://pear.php.net/package/HTML_AJAX
* PHP5 requires a constructor
* Checks the proper syntax
function _checkEmail ($strEmail) {
return (preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $strEmail));
* Checks if the passed values are correct.
* @param array the form object
//--------------------------------------------------
//--------------------------------------------------
// Array to hold the messages
// Set all form values that they validated. Could be improved by analyzing
// the values passed in $objForm and setting values accordingly.
$arrValidated['username'] = true;
$arrValidated['password'] = true;
$arrValidated['email'] = true;
// Never trust the values passed by users :)
$objForm = new stdClass ();
$objForm->username = trim($arrayForm['username']);
$objForm->password = trim($arrayForm['password']);
$objForm->email = trim($arrayForm['email']);
//--------------------------------------------------
//--------------------------------------------------
if ($objForm->username == '') {
$arrValidated['username'] = false;
} else if ($objForm->username != 'peter') {
$arrValidated['username'] = false;
if ($objForm->password == '') {
$arrValidated['password'] = false;
} else if ($objForm->password != 'gabriel') {
$arrValidated['password'] = false;
if ($objForm->email == '') {
$arrValidated['email'] = false;
} else if ($this->_checkEmail ($objForm->email ) == false ) {
$arrValidated['email'] = false;
//--------------------------------------------------
//--------------------------------------------------
// Create the message list
if (count($arrMessages) > 0 ) {
foreach ($arrMessages as $strTemp) {
$strMessages.= '<li>'. $strTemp. '</li>';
// Create a response object
$objResponse->assignAttr ('messages', 'innerHTML', $strMessages);
$objResponse->insertScript ("toggleElement('messages', ". (($strMessages != '') ? 1 : 0 ). ");");
// Generate the scripts to update the form elements' label and input element
foreach ($arrValidated as $strKey => $blnValue) {
$objResponse->insertScript ("setElement('". $strKey. "', ". (($blnValue) ? '1' : '0'). ");");
if ($strMessages == "") {
$objResponse->insertAlert ("Well done chap!");
Documentation generated on Mon, 11 Mar 2019 15:59:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|