Skip to content

Commit

Permalink
add: new 'Login' plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ziirish committed Aug 7, 2013
1 parent dfe161d commit 19dabf7
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/pages/LoginPage.class.php
Expand Up @@ -90,18 +90,38 @@ public function printLoginForm($redirection){
$this->printHTMLFooter();
}

private function checkPluginLogin($username, $password) {
if ($this->plugEng->existPluginOfType('login')) {
$tmpArray = array($username, $password);
return $this->plugEng->doHookBoolean('login', $tmpArray);
}
return false;
}

/**
* Check for user login.
* @return <code>true</code> if allowed, <code>false</code> otherwise.
*/
private function checkLogin() {
$user = $this->db->query(
'SELECT * ' .
'FROM fmb_members ' .
'WHERE mem_login = ? AND mem_passwd = ?',
array($_REQUEST['login'], sha1($_REQUEST['password'])),
DBPlugin::SQL_QUERY_FIRST
) ? $this->db->getSQLResult() : array();
$user = array();

if ($this->checkPluginLogin($_REQUEST['login'], $_REQUEST['password'])) {
$user = $this->db->query(
'SELECT * '.
'FROM fmb_members '.
'WHERE mem_login = ?',
array($_REQUEST['login']),
DBPlugin::SQL_QUERY_FIRST
) ? $this->db->getSQLResult() : array();
} else {
$user = $this->db->query(
'SELECT * ' .
'FROM fmb_members ' .
'WHERE mem_login = ? AND mem_passwd = ?',
array($_REQUEST['login'], sha1($_REQUEST['password'])),
DBPlugin::SQL_QUERY_FIRST
) ? $this->db->getSQLResult() : array();
}

if ($user != array()) {
$_SESSION['usrID'] = $user['mem_id'];
Expand Down
72 changes: 72 additions & 0 deletions src/plugins/LoginPlugin.class.php
@@ -0,0 +1,72 @@
<?php
/*
Copyright 2009 - 2012 - Etienne 'lenaing' GIRONDEL <lenaing@gmail.com>
FMB :
------------
This software is an homemade PHP Blog engine.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*/

/**
* LoginPlugin.class.php file.
* This file contains the sourcecode of the abstract LoginPlugin class.
* Every FMB caching plugin should extends this class.
* @package FMB
* @subpackage Plugins
* @author Ziirish <ziirish@ziirish.info>
* @version 0.1b
*/
namespace FMB\Plugins;
use FMB\Core\Core;
use FMB\Plugins\Plugin;
use FMB\Plugins\LoginPluginInterface;

// Loading required files.
Core::loadFile('src/plugins/Plugin.class.php', true);
Core::loadFile('src/plugins/LoginPlugin.interface.php', true);

/**
* LoginPlugin abstract class.
* This file contains the LoginPlugin abstract class.
* @package FMB
* @subpackage Plugins
* @author Ziirish <ziirish@ziirish.info>
* @version 0.1b
* @abstract
*/
abstract class LoginPlugin extends Plugin implements LoginPluginInterface
{

public final function __construct()
{
parent::__construct('template');
}

}
?>
65 changes: 65 additions & 0 deletions src/plugins/LoginPlugin.interface.php
@@ -0,0 +1,65 @@
<?php
/*
Copyright 2009 - 2012 - Etienne 'lenaing' GIRONDEL <lenaing@gmail.com>
FMB :
------------
This software is an homemade PHP Blog engine.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*/

/**
* LoginPlugin.interface.php file.
* This file contains the sourcecode of the LoginPlugin interface.
* @package FMB
* @subpackage Plugins
* @author Ziirish <ziirish@ziirish.info>
* @version 0.1b
*/
namespace FMB\Plugins;

/**
* LoginPlugin interface.
* This file contains the LoginPlugin interface.
* @package FMB
* @subpackage Plugins
* @author Ziirish <ziirish@ziirish.info>
* @version 0.1b
*/
interface LoginPluginInterface
{
/**
* Check if a login/password is valid
* @param string $login Login to test.
* @param string $password Password to test.
* @return TRUE if login/password is valid.
*/
public function checkLogin($login, $password);
}

?>
34 changes: 34 additions & 0 deletions src/plugins/PluginEngine.class.php
Expand Up @@ -433,6 +433,40 @@ public function doHookConcatBoolean($hookName, $parameters = NULL)
return $result;
}

/**
* Execute given hook with eventual parameters and return as soon as one
* result is true.
* @access public
* @param string $hookName Name of the hook to execute.
* @param array $parameters Parameters to pass to plugins methods.
* @return string The concatenated answers of all plugins to this hook.
* If all answers are false, the result will be false.
* Otherwise the result will be true.
*/
public function doHookBoolean($hookName, $parameters = NULL)
{
$result = false;

if (isset(self::$_pluginsHooks["$hookName"])
&& is_array(self::$_pluginsHooks["$hookName"])) {

/* Search for loaded plugins. */
foreach (self::$_pluginsHooks["$hookName"] as $hook) {
$plugin = self::getPlugin($hook['pluginName']);

if (NULL != $plugin) {
if (method_exists($plugin, $hook['pluginMethod'])) {
if ($plugin->$hook['pluginMethod']($parameters)) {
return true;
}
}
}
}
}

return $result;
}

/**
* Check required FMB version for given plugin.
* @access private
Expand Down

0 comments on commit 19dabf7

Please sign in to comment.