}
//-----------------------------------------------------------------------------------------------
-// This function is necessary for admin prefs update after upgrade from 2.1
-//
+
function get_user_by_login($user_id)
{
$sql = "SELECT * FROM ".TB_PREF."users WHERE user_id=".db_escape($user_id);
}
//-----------------------------------------------------------------------------------------------
-
+//
+// Obsolete, to be removed in 2.4. This function as been spleet into get_user_auth/get_user_by_login
+// in FA 2.3.6
+//
function get_user_for_login($user_id, $password)
{
set_global_connection();
//-----------------------------------------------------------------------------------------------
+function get_user_auth($user_id, $password)
+{
+ set_global_connection();
+
+ $sql = "SELECT * FROM ".TB_PREF."users WHERE user_id = ".db_escape($user_id)." AND"
+ ." password=".db_escape($password);
+
+ return db_num_rows(db_query($sql, "could not get validate user login for $user_id")) != 0;
+}
+
+//-----------------------------------------------------------------------------------------------
+
function update_user_visitdate($user_id)
{
$sql = "UPDATE ".TB_PREF."users SET last_visit_date='". date("Y-m-d H:i:s") ."'
$this->set_company($company);
$this->logged = false;
- $Auth_Result = get_user_for_login($loginname, $password);
+ set_global_connection();
- if (db_num_rows($Auth_Result) > 0)
+ // Use external authentication source if any.
+ // Keep in mind you need to have user data set for $loginname
+ // in FA users table anyway to successfully log in.
+ $Auth_Result = hook_authenticate($loginname, $password);
+
+ if (!isset($Auth_Result)) // if not used: standard method
+ $Auth_Result = get_user_auth($loginname, md5($password));
+
+ if ($Auth_Result)
{
- $myrow = db_fetch($Auth_Result);
+ $myrow = get_user_by_login($loginname);
$this->old_db = isset($myrow["full_access"]);
if (! @$myrow["inactive"]) {
if ($this->old_db) {
//
// Returns: amount in words as string.
-/* commented out in base class to enable use with hook_invoke_last
function price_in_words($amount, $doc_type)
{
}
-*/
//
// Exchange rate currency $curr as on date $date.
// Keep in mind FA has internally implemented 3 exrate providers
// with apprioprate provider set, otherwise implement your own.
// Returns: $curr value in home currency units as a real number.
-/* commented out in base class to enable use with hook_invoke_last
function retrieve_exrate($curr, $date)
{
// $provider = 'ECB'; // 'ECB', 'YAHOO' or 'GOOGLE'
// return get_extern_rate($curr, $provider, $date);
return null;
}
-*/
+
+ // External authentication
+ // If used should return true after successfull athentication, false otherwise.
+ function authenticate($login, $password)
+ {
+ return null;
+ }
// Generic function called at the end of Tax Report (report 709)
// Can be used e.g. for special database updates on every report printing
// or to print special tax report footer
return $result;
}
/*
- Returns result of last hook installed. Helps implement hooks overriding by
+ Returns last non-null result returned from modules method. Helps implement hooks overriding by
extensions installed later.
-
*/
function hook_invoke_last($method, &$data, $opts=null)
{
global $Hooks;
- $found = false;
- foreach($Hooks as $ext => $hook) {
+ $result = null;
+ $Reverse = array_reverse($Hooks);
+ foreach($Reverse as $ext => $hook) {
if (method_exists($hook, $method)) {
- $found = $ext;
+ set_ext_domain('modules/'.$ext);
+ $result = $hook->$method($data, $opts);
+ if (isset($result))
+ break;
}
}
- $ret = null;
- if ($found) {
- set_ext_domain('modules/'.$found);
- $ret = $Hooks[$found]->$method($data, $opts);
- set_ext_domain();
- }
- return $ret;
+ set_ext_domain();
+ return $result;
}
//------------------------------------------------------------------------------------------
// Database transaction hooks.
}
return false;
}
+//
+// Third party authentication modules.
+// Returns true after successfull authentication, false otherwise, null if no login hook is defined.
+//
+function hook_authenticate($login, $password)
+{
+ return hook_invoke_last('authenticate', $login, $password);
+}
login_timeout();
+ install_hooks();
+
if (!$_SESSION["wa_current_user"]->logged_in())
{
// Show login screen
$succeed = isset($db_connections[$_POST["company_login_name"]]) &&
$_SESSION["wa_current_user"]->login($_POST["company_login_name"],
- $_POST["user_name_entry_field"], md5($_POST["password"]));
+ $_POST["user_name_entry_field"], $_POST["password"]);
// select full vs fallback ui mode on login
$_SESSION["wa_current_user"]->ui_mode = $_POST['ui_mode'];
if (!$succeed)
if (!$_SESSION["wa_current_user"]->old_db)
include_once($path_to_root . '/company/'.user_company().'/installed_extensions.php');
- install_hooks();
-
if (!isset($_SESSION["App"])) {
$_SESSION["App"] = new front_accounting();
$_SESSION["App"]->init();