GenieGate, Version 1.1.0 (PHP 5) manual

Chapter 8. Programmers API

Abstract

GenieGate is not just an application, it also provides a complete API for programmers to use. Through this API it is possible to store and access properties, perform authentication and listen for events. (it is also possible to do a great deal more, you should consult the api documents if you are interested)

People interested in using GenieGate for basic authentication may skip this chapter. However, it should be reassuring to know that it is available should your needs grow beyond what is already provided.

The actual details for this API are not covered here, it can be extracted from the source via phpdoc, doxygen or other tools. We hope to make the api available on the web site as soon as possible. The classes in the GenieGate_Api name space are considered the public API.

Login via the API

Logging in via the api is quite simple, 1 line in any PHP document, illustrated in the first example.

Example 8.1. 1-line login, using PHP


<?php require_once("/home/userId/geniegate/login.php"); ?>


It is important to note that /home/userId/geniegate/ is the complete path to your ~/geniegate/ directory.

Example 8.2. 2-line login, using PHP


<?php
require_once("/Users/macusr/geniegate/conf.php");
genieGateLogin("form.php");
?>

The above example allows you to specify your own form, in this case, a file called form.php will be used to produce a login form.

"Passive" login

Passive logins are useful in situations where you only need to protect portions of a document, wish to provide separate versions of the same document depending on whether or not a user has signed on.

A classic example would be providing a sign-on form to people who are not signed in.

Example 8.3. Passive login


<?php
require_once("/Users/macusr/geniegate/conf.php");
$user = genieGatePassive();
?>
<html>
	<head></head>
	<body>
<?php if($user) { ?>
	<p>Hello, you are signed in!</p>
<?php } else { ?>
	<p>Welcome guest, you are <i>NOT</i> signed in</p>
<?php } ?>
	</body>
</html>

The above example demonstrates a passive login. When the user is signed in, the message "Hello, you are signed in!" is shown. When the user is not signed in, the text "Welcome guest, you are NOT signed it" is shown.

[Important] Important

Although creating your own login forms are supported in both the free and paid versions, the free version must contain the advertising links. Please see the license for details. These must appear on each page containing a login or sign-up form.

Plug ins

If you are using Apache style passwords, then you have come into contact with plugins. They involve adding an entry to your PLUGINS and optionally setting up some other configuration sections.

Plugins are php classes that "listen" for events such as new user creation or account changes. They are typically designed to maintain synchronization with other applications that may need to know about these events.

To create a plug in, you should extend GenieGate_Api_Plugin and provide methods for the events you are interested in.

The logger plug in.  For a simple example plug in, GenieGate_Api_Plugin_Logger is a good place to start. It will log each event (and it's parameters) to a file. It is a useful plugin to assist in determining those events you are interested in.

Creating/Modifying the GenieGate libraries

Generally you should never need to modify the libraries of GenieGate. Doing so is not officially recommended, but it is possible with minimal hassles.

Please do NOT change the files in the global/ directory. You should copy them to your ~/geniegate/lib/ directory and edit them there.