<?php
-/** External authentication via HTTPD for FusionForge
+/**
+ * External authentication via HTTPD for FusionForge
* Copyright 2011, Roland Mas
+ * Copyright 2016, Franck Villaume - TrivialDev
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
*
*/
class AuthHTTPDPlugin extends ForgeAuthPlugin {
- function AuthHTTPDPlugin () {
- global $gfconfig;
- $this->ForgeAuthPlugin() ;
+ function __construct() {
+ parent::__construct();
$this->name = "authhttpd";
$this->text = _("HTTPD authentication");
$this->pkg_desc =
$this->_addHook("check_auth_session");
$this->_addHook("fetch_authenticated_user");
$this->_addHook("close_auth_session");
+ $this->_addHook('session_login_valid');
$this->saved_login = '';
$this->saved_user = NULL;
/**
* Display a form to input credentials
- * @param unknown_type $params
- * @return boolean
+ * @param array $params
+ * @return boolean
*/
function displayAuthForm(&$params) {
+ global $HTML;
if (!$this->isRequired() && !$this->isSufficient()) {
return true;
}
$return_to = $params['return_to'];
- $result = '';
-
- $result .= '<p>';
- $result .= _('Cookies must be enabled past this point.');
- $result .= '</p>';
+ $result = html_e('p', array(), _('Cookies must be enabled past this point.'));
- $result .= '<form action="' . util_make_url('/plugins/authhttpd/post-login.php') . '" method="get">
-<input type="hidden" name="form_key" value="' . form_generate_key() . '"/>
+ $result .= $HTML->openForm(array('action' => '/plugins/'.$this->name.'/post-login.php', 'method' => 'get'));
+ $result .= '<input type="hidden" name="form_key" value="' . form_generate_key() . '"/>
<input type="hidden" name="return_to" value="' . htmlspecialchars(stripslashes($return_to)) . '" />
<p><input type="submit" name="login" value="' . _('Login via HTTP authentication') . '" />
-</p>
-</form>' ;
-
+</p>';
+ $result .= $HTML->closeForm();
$params['html_snippets'][$this->name] = $result;
- $params['transparent_redirect_urls'][$this->name] = util_make_url('/plugins/authhttpd/post-login.php?return_to='.htmlspecialchars(stripslashes($return_to)));
+ $params['transparent_redirect_urls'][$this->name] = util_make_url('/plugins/'.$this->name.'/post-login.php?return_to='.htmlspecialchars(stripslashes($return_to)));
+ }
+
+
+ function session_login_valid($params) {
+ $user = user_get_object_by_name($params['loginname']);
+ $this->setAuthStateResult($params, $user);
+ return true;
}
/**
- * Is there a valid session?
- * @param unknown_type $params
+ * checkAuthSession - Is there a valid session?
+ * @param array $params
*/
function checkAuthSession(&$params) {
$this->saved_user = NULL;
$user = user_get_object_by_name($username);
}
- // TODO : shouldn't this part be factorized as it seems quite common for many plugins ?
- if ($user) {
- if ($this->isSufficient()) {
- $this->saved_user = $user;
- $params['results'][$this->name] = FORGE_AUTH_AUTHORITATIVE_ACCEPT;
-
- } else {
- $params['results'][$this->name] = FORGE_AUTH_NOT_AUTHORITATIVE;
- }
- } else {
- if ($this->isRequired()) {
- $params['results'][$this->name] = FORGE_AUTH_AUTHORITATIVE_REJECT;
- } else {
- $params['results'][$this->name] = FORGE_AUTH_NOT_AUTHORITATIVE;
- }
- }
+ $this->saved_user = $user;
+ $this->setAuthStateResult($params, $user);
}
/**
- * What GFUser is logged in?
- * @param unknown_type $params
+ * fetchAuthUser - What FFUser is logged in?
+ * @param array $params
*/
function fetchAuthUser(&$params) {
if ($this->saved_user && $this->isSufficient()) {