1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-25 07:21:03 +02:00

Handle some of the import options better in alt_auth, plus odd tidy ups

This commit is contained in:
e107steved
2009-11-08 10:34:23 +00:00
parent 15a83d309a
commit 5d09cd5137
8 changed files with 390 additions and 259 deletions

View File

@@ -24,10 +24,10 @@ if (!is_object($euf))
define('AUTH_UNKNOWN', 4);
define('AUTH_NOT_AVAILABLE', 5);
function alt_auth_get_authlist()
function alt_auth_get_authlist($incE107 = TRUE)
{
$authlist = array("e107");
$handle=opendir(e_PLUGIN."alt_auth");
$authlist = $incE107 ? array('e107') : array();
$handle=opendir(e_PLUGIN.'alt_auth');
while ($file = readdir($handle))
{
if(preg_match("/^(.*)_auth\.php/",$file,$match))
@@ -40,6 +40,21 @@ function alt_auth_get_authlist()
}
function alt_auth_get_dropdown($name, $curval = '', $options = '')
{
$optList = explode(',', $options);
$authList = array_merge($optList, alt_auth_get_authlist(FALSE));
$ret = "<select class='tbox' name='{$name}'>\n";
foreach ($authList as $v)
{
$sel = ($curval == $v ? " selected = 'selected' " : '');
$ret .= "<option value='{$v}'{$sel} >{$v}</option>\n";
}
$ret .= "</select>\n";
return $ret;
}
// All user fields which might, just possibly, be transferred. The array key is the corresponding field in the E107 user database; code prefixes it with 'xf_' to get the parameter
// 'default' may be a single value to set the same for all connect methods, or an array to set different defaults.
$alt_auth_user_fields = array(

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/alt_auth/alt_auth_conf.php,v $
| $Revision: 1.5 $
| $Date: 2009-07-21 19:49:36 $
| $Author: e107coders $
| $Revision: 1.6 $
| $Date: 2009-11-08 10:34:23 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
$eplug_admin = true;
@@ -37,7 +37,7 @@ if(isset($_POST['updateprefs']))
unset($temp);
$temp['auth_method'] = $tp->toDB($_POST['auth_method']);
$temp['auth_noconn'] = intval($_POST['auth_noconn']);
$temp['auth_nouser'] = intval($_POST['auth_nouser']);
$temp['auth_method2'] = $tp->toDB($_POST['auth_method2']);
if ($admin_log->logArrayDiffs($temp, $pref, 'AUTH_01'))
{
save_prefs(); // Only save if changes
@@ -63,6 +63,23 @@ if(isset($_POST['updateeufs']))
}
}
// Avoid need for lots of checks later
if (!isset($pref['auth_badpassword'])) $pref['auth_badpassword'] = 0;
if (!isset($pref['auth_noconn'])) $pref['auth_noconn'] = 0;
// Convert prefs
if (isset($pref['auth_nouser']))
{
$pref['auth_method2'] = 'none'; // Default to no fallback
if ($pref['auth_nouser'])
{
$pref['auth_method2'] = 'e107';
}
unset($pref['auth_nouser']);
if (!isset($pref['auth_badpassword'])) $pref['auth_badpassword'] = 0;
save_prefs();
}
$authlist = alt_auth_get_authlist();
if (isset($pref['auth_extended']))
@@ -75,13 +92,6 @@ else
$authExtended = array();
}
$auth_dropdown = "<select class='tbox' name='auth_method'>\n";
foreach($authlist as $a)
{
$s = ($pref['auth_method'] == $a) ? "selected='selected'" : "";
$auth_dropdown .= "<option value='{$a}' {$s}>".$a."</option>\n";
}
$auth_dropdown .= "</select>\n";
if(isset($message))
{
@@ -99,19 +109,29 @@ $text = "
<tr>
<td>".LAN_ALT_1.": </td>
<td>".
$auth_dropdown."
alt_auth_get_dropdown('auth_method', $pref['auth_method'], 'e107')."
</td>
</tr>
<tr>
<td>".LAN_ALT_6.":<br />
</td>
<td>".LAN_ALT_78.":<br /></td>
<td>
<select class='tbox' name='auth_noconn'>";
$sel = (isset($pref['auth_noconn']) && $pref['auth_noconn'] ? "" : " selected = 'selected' ");
$sel = (!$pref['auth_badpassword'] ? "" : " selected = 'selected' ");
$text .= "<option value='0' {$sel} >".LAN_ALT_FAIL."</option>";
$sel = (isset($pref['auth_noconn']) && $pref['auth_noconn'] ? " selected = 'selected' " : "");
$sel = ($pref['auth_badpassword'] ? " selected = 'selected' " : "");
$text .= "<option value='1' {$sel} >".LAN_ALT_FALLBACK."</option>
</select><div class='smalltext field-help'>".LAN_ALT_79."</div>
</td>
</tr>
<tr>
<td>".LAN_ALT_6.":<br /></td>
<td>
<select class='tbox' name='auth_noconn'>";
$sel = (!$pref['auth_noconn'] ? "" : " selected = 'selected' ");
$text .= "<option value='0' {$sel} >".LAN_ALT_FAIL."</option>";
$sel = ($pref['auth_noconn'] ? " selected = 'selected' " : "");
$text .= "<option value='1' {$sel} >".LAN_ALT_FALLBACK."</option>
</select><div class='smalltext field-help'>".LAN_ALT_7."</div>
</td>
@@ -121,13 +141,8 @@ $text .= "<option value='1' {$sel} >".LAN_ALT_FALLBACK."</option>
<td>".LAN_ALT_8.":<br />
</td>
<td>
<select class='tbox' name='auth_nouser'>";
$sel = (isset($pref['auth_nouser']) && $pref['auth_nouser'] ? "" : " selected = 'selected' ");
$text .= "<option value='0' {$sel} >".LAN_ALT_FAIL."</option>";
$sel = (isset($pref['auth_nouser']) && $pref['auth_nouser'] ? " selected = 'selected' " : "");
$text .= "<option value='1' {$sel} >".LAN_ALT_FALLBACK."</option>
</select><div class='smalltext field-help'>".LAN_ALT_9."</div>
<td>".alt_auth_get_dropdown('auth_method2', $pref['auth_method2'], 'none')."
<div class='smalltext field-help'>".LAN_ALT_9."</div>
</td>
</tr>
</table>
@@ -141,10 +156,7 @@ $text .= "<option value='1' {$sel} >".LAN_ALT_FALLBACK."</option>
$ns -> tablerender(LAN_ALT_3, $text);
//$extendedFields = $euf->user_extended_get_fields();
//$extendedFields = &$euf->fieldDefinitions;
//print_a($extendedFields);
if (count($euf->fieldDefinitions))
if ($euf->userCount)
{
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_user_extended.php');
$fl = &$euf->fieldDefinitions;

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/alt_auth/alt_auth_login_class.php,v $
| $Revision: 1.9 $
| $Date: 2009-07-21 19:21:26 $
| $Revision: 1.10 $
| $Date: 2009-11-08 10:34:23 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@@ -21,14 +21,23 @@ define('AA_DEBUG1',FALSE);
class alt_login
{
function alt_login($method, &$username, &$userpass)
protected $e107;
public function __construct($method, &$username, &$userpass)
{
global $pref, $admin_log;
global $pref;
$this->e107 = e107::getInstance();
$newvals=array();
define('AUTH_SUCCESS', -1);
define('AUTH_NOUSER', 1);
define('AUTH_BADPASSWORD', 2);
define('AUTH_NOCONNECT', 3);
if ($method == 'none')
{
return AUTH_NOCONNECT;
}
require_once(e_PLUGIN.'alt_auth/'.$method.'_auth.php');
$_login = new auth_login;
@@ -64,7 +73,7 @@ class alt_login
if (isset($_login->copyMethods[$k]))
{
$newvals[$k] = $this->translate($_login->copyMethods[$k], $v);
if (AA_DEBUG1) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth convert",$k.': '.$v.'=>'.$newvals[$k],FALSE,LOG_TO_ROLLING);
if (AA_DEBUG1) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth convert",$k.': '.$v.'=>'.$newvals[$k],FALSE,LOG_TO_ROLLING);
}
}
}
@@ -88,7 +97,7 @@ class alt_login
$qry = "SELECT u.user_id,u.".implode(',u.',array_keys($db_vals)).", ue.user_extended_id, ue.".implode(',ue.',array_keys($xFields))." FROM `#user` AS u
LEFT JOIN `#user_extended` AS ue ON ue.user_extended_id = u.user_id
WHERE u.user_loginname='{$username}' ";
if (AA_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Query: {$qry}[!br!]".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Query: {$qry}[!br!]".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
}
else
{
@@ -108,14 +117,14 @@ class alt_login
validatorClass::addFieldTypes($userMethods->userVettingInfo,$newUser);
$newUser['WHERE'] = '`user_id`='.$row['user_id'];
$aa_sql->db_Update('user',$newUser);
if (AA_DEBUG1) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User data update: ".print_r($newUser,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG1) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User data update: ".print_r($newUser,TRUE),FALSE,LOG_TO_ROLLING);
}
foreach ($xFields as $k => $v)
{
if ($row[$k] == $v) unset($xFields[$k]);
}
if (AA_DEBUG1) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User data read: ".print_r($row,TRUE)."[!br!]".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User xtnd read: ".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG1) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User data read: ".print_r($row,TRUE)."[!br!]".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User xtnd read: ".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (count($xFields))
{
$xArray = array();
@@ -124,21 +133,21 @@ class alt_login
{
$ue->addFieldTypes($xArray); // Add in the data types for storage
$xArray['WHERE'] = '`user_extended_id`='.intval($row['user_id']);
if (AA_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User xtnd update: ".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","User xtnd update: ".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
$aa_sql->db_Update('user_extended',$xArray );
}
else
{ // Never been an extended user fields record for this user
$xArray['data']['user_extended_id'] = $row['user_id'];
$ue->addDefaultFields($xArray); // Add in the data types for storage, plus any default values
if (AA_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Write new extended record".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Write new extended record".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
$aa_sql->db_Insert('user_extended',$xArray);
}
}
}
else
{ // Just add a new user
if (AA_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Add new user: ".print_r($db_vals,TRUE)."[!br!]".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Alt auth login","Add new user: ".print_r($db_vals,TRUE)."[!br!]".print_r($xFields,TRUE),FALSE,LOG_TO_ROLLING);
if (!isset($db_vals['user_name'])) $db_vals['user_name'] = $username;
if (!isset($db_vals['user_loginname'])) $db_vals['user_loginname'] = $username;
if (!isset($db_vals['user_join'])) $db_vals['user_join'] = time();
@@ -161,12 +170,12 @@ class alt_login
$xArray['data'] = $xFields;
$ue->addDefaultFields($xArray); // Add in the data types for storage, plus any default values
$result = $aa_sql->db_Insert('user_extended',$xArray);
if (AA_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),'DEBUG','Alt auth login',"Add extended: UID={$newID} result={$result}",FALSE,LOG_TO_ROLLING);
if (AA_DEBUG) $this->e107->admin_log->e_log_event(10,debug_backtrace(),'DEBUG','Alt auth login',"Add extended: UID={$newID} result={$result}",FALSE,LOG_TO_ROLLING);
}
}
else
{ // Error adding user to database - possibly a conflict on unique fields
$admin_log->e_log_event(10,__FILE__.'|'.__FUNCTION__.'@'.__LINE__,'ALT_AUTH','Alt auth login','Add user fail: DB Error '.$aa_sql->mySQLlastErrText."[!br!]".print_r($db_vals,TRUE),FALSE,LOG_TO_ROLLING);
$this->e107->admin_log->e_log_event(10,__FILE__.'|'.__FUNCTION__.'@'.__LINE__,'ALT_AUTH','Alt auth login','Add user fail: DB Error '.$aa_sql->mySQLlastErrText."[!br!]".print_r($db_vals,TRUE),FALSE,LOG_TO_ROLLING);
return LOGIN_DB_ERROR;
}
}
@@ -176,21 +185,28 @@ class alt_login
{ // Failure modes
switch($login_result)
{
case AUTH_NOUSER:
/*
case AUTH_NOUSER: // Now handled differently
if(!varset($pref['auth_nouser'],0))
{
$username=md5('xx_nouser_xx');
return LOGIN_ABORT;
}
break;
*/
case AUTH_NOCONNECT:
if(!varset($pref['auth_noconn']))
if(varset($pref['auth_noconn'], TRUE))
{
$username=md5('xx_noconn_xx');
return LOGIN_ABORT;
return LOGIN_TRY_OTHER;
}
$username=md5('xx_noconn_xx');
return LOGIN_ABORT;
break;
case AUTH_BADPASSWORD:
if(varset($pref['auth_badpassword'], TRUE))
{
return LOGIN_TRY_OTHER;
}
$userpass=md5('xx_badpassword_xx');
return LOGIN_ABORT; // Not going to magically be able to log in!
break;
@@ -199,9 +215,9 @@ class alt_login
return LOGIN_ABORT; // catch-all just in case
}
// Function to implement copy methods
function translate($method, $word)
public function translate($method, $word)
{
global $tp;
switch ($method)

View File

@@ -11,20 +11,20 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/alt_auth/languages/English/admin_alt_auth.php,v $
| $Revision: 1.3 $
| $Date: 2009-07-05 18:47:52 $
| $Revision: 1.4 $
| $Date: 2009-11-08 10:34:23 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
define('LAN_ALT_1', 'Current authorisation type');
define('LAN_ALT_1', 'Primary authorisation type');
define('LAN_ALT_2', 'Update settings');
define('LAN_ALT_3', 'Choose Alternate Authorisation Type');
define('LAN_ALT_4', 'Configure parameters for');
define('LAN_ALT_5', 'Configure authorisation parameters');
define('LAN_ALT_6', 'Failed connection action');
define('LAN_ALT_7', 'If connection to the alternate method fails, how should that be handled?');
define('LAN_ALT_8', 'User not found action');
define('LAN_ALT_9', 'If username is not found using alternate method, how should that be handled?');
define('LAN_ALT_7', 'If connection to the primary authorisation type fails (and its not the local e107 DB), how should that be handled?');
define('LAN_ALT_8', 'Secondary authorisation type');
define('LAN_ALT_9', 'This is used if the primary authorisation method cannot find the user');
define('LAN_ALT_10', 'User login name field');
define('LAN_ALT_11', 'User password field');
@@ -96,9 +96,11 @@ define('LAN_ALT_74', 'Upper first');
define('LAN_ALT_75', 'Upper words');
define('LAN_ALT_76', 'User class restriction (a numeric value - zero or blank for everyone)');
define('LAN_ALT_77', 'Only users in this class (on the database set above) are permitted access');
define('LAN_ALT_78', 'Failed password action');
define('LAN_ALT_79', 'If user exists in primary DB, but enters an incorrect password, how should that be handled?');
define('LAN_ALT_FALLBACK', 'Use e107 user table');
define('LAN_ALT_FALLBACK', 'Use secondary authorisation');
define('LAN_ALT_FAIL', 'Failed login');
define('LAN_ALT_UPDATESET', 'Update settings');
define('LAN_ALT_UPDATED','Settings updated');

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Id: plugin.xml,v 1.7 2009-10-20 03:49:21 e107coders Exp $ -->
<!-- $Id: plugin.xml,v 1.8 2009-11-08 10:34:23 e107steved Exp $ -->
<e107Plugin name="LAN_ALT_65" version="0.4" compatibility="0.8" installRequired="true" >
<author name="e107 Inc." url="e107.org" email="mcfly@e107.org" />
@@ -15,7 +15,8 @@
</adminLinks>
<mainPrefs>
<pref name="auth_noconn">0</pref>
<pref name="auth_nouser">0</pref>
<pref name="auth_badpassword">0</pref>
<pref name="auth_method2">0</pref>
<pref name="auth_extended"></pref>
</mainPrefs>
</e107Plugin>