/** * @param string $string - Language strings. * @return bool if authentication was successful */ function do_authentication($string) { $this->success = false; $this->debug[] = 'Starting authentication'; $preauthobj = new stdClass(); if (isset($this->callbackregister['preauth'])) { foreach ($this->callbackregister['preauth'] as $number => $callback) { $preauthobj = call_user_func_array($callback, array($preauthobj)); $objid = key($this->callbackregisterdata['preauth'][$number]); $this->append_auth_object_debug($objid); } } $authobj = new authobjreturn(); if (isset($this->callbackregister['auth'])) { foreach ($this->callbackregister['auth'] as $number => $callback) { $authobj = call_user_func_array($callback, array($authobj)); $objid = key($this->callbackregisterdata['auth'][$number]); $this->append_auth_object_debug($objid); if ($authobj->returned === ROGO_AUTH_OBJ_SUCCESS) { $this->success = true; $this->userid = $authobj->rogoid; if (isset($authobj->username) and $authobj->username != '') { $this->username = $authobj->username; } $this->debug[] = '******* Rogo ID is:: ' . $this->userid . " from object {$objid}:" . $this->callbackregisterdata['auth'][$number][$objid] . ' *******'; $this->successfullauthmodule[] = $objid; } elseif ($authobj->returned === ROGO_AUTH_OBJ_LOOKUPONLY) { $this->debug[] = '* User authenticated but no matching rogo id found, attempting to lookup the user with info supplied from module *'; //lookupuser $lookup = Lookup::get_instance($this->configObj, $this->db); //$authobj->data contains lookup info; $data = new stdClass(); $data->lookupdata = clone $authobj->data; $info = $lookup->userlookup($data); $lookupdebug = $lookup->debug_as_array(); foreach ($lookupdebug as $line) { $this->debug[] = 'Lookup Debug: ' . $line; } //minimum fields to create an new user username $createuser = true; $authentication_fields_required_to_create_user = $this->configObj->get('authentication_fields_required_to_create_user'); if (!is_null($authentication_fields_required_to_create_user)) { foreach ($authentication_fields_required_to_create_user as $value) { if (!isset($info->lookupdata->{$value}) or isset($info->lookupdata->{$value}) and $info->lookupdata->{$value} == '') { $createuser = false; $this->debug[] = 'Not creating user as the ' . $value . ' field is missing'; } } } if (isset($info->lookupdata->disabled) and $info->lookupdata->disabled == true) { $createuser = false; } if (isset($info->lookupdata->multiple) and $info->lookupdata->multiple == true) { $createuser = false; } if ($createuser == true) { $this->debug[] = 'Going to try and create new user'; $arraycheck = array('username', 'title', 'firstname', 'surname', 'email', 'coursecode', 'gender', 'yearofstudy', 'role', 'studentID', 'school', 'coursetitle', 'initials'); foreach ($arraycheck as $itemcheck) { if (!isset($info->lookupdata->{$itemcheck})) { $info->lookupdata->{$itemcheck} = ''; } } $newuserid = UserUtils::create_extended_user($info->lookupdata->username, $info->lookupdata->title, $info->lookupdata->firstname, $info->lookupdata->surname, $info->lookupdata->email, $info->lookupdata->coursecode, $info->lookupdata->gender, $info->lookupdata->yearofstudy, $info->lookupdata->role, $info->lookupdata->studentID, $this->db, $info->lookupdata->school, $info->lookupdata->coursetitle, $info->lookupdata->initials, $this->form['std']->password); if ($newuserid !== false) { //new account created $authobj->success($objid, $newuserid); $this->success = true; $this->userid = $authobj->rogoid; $this->debug[] = '******* Rogo ID is:: ' . $this->userid . " after a user lookup from object {$objid}:" . $this->callbackregisterdata['auth'][$number][$objid] . ' *******'; } } else { // Log not creating user and why $username = '******'; if (isset($this->form['std']->username)) { $username = $this->form['std']->username; } $userid = 0; $errfile = 'Authentication'; $errline = 0; $errstr = 'Couldnt create user see variables for more info'; $variables = array('lookup' => &$lookup, 'info' => &$info, 'authentication' => &$this); log_error($userid, $username, 'Application Warning', $errstr, $errfile, $errline, '', null, $variables, null); } } if ($this->success and ($this->authPluginObj[$objid]->get_settings('dont_break_on_success') === false or $this->authPluginObj[$objid]->get_settings('dont_break_on_success') !== false and !$this->authPluginObj[$objid]->get_settings('dont_break_on_success'))) { break; } } } $postauthobj = new stdClass(); $postauthobj->authobj = $authobj; if (isset($this->callbackregister['postauth'])) { foreach ($this->callbackregister['postauth'] as $number => $callback) { $postauthobj = call_user_func_array($callback, array($postauthobj)); $objid = key($this->callbackregisterdata['postauth'][$number]); $this->append_auth_object_debug($objid); } } if ($this->success === false) { //failed $postauthfailobj = new postauthfailreturn(); $postauthfailobj->authobj = $authobj; $postauthfailobj->postauthobj = $postauthobj; $this->session['authenticationObj']['attempt']++; if (isset($this->callbackregister['postauthfail'])) { foreach ($this->callbackregister['postauthfail'] as $number => $callback) { $postauthfailobj = call_user_func_array($callback, array($postauthfailobj)); $objid = key($this->callbackregisterdata['postauthfail'][$number]); $this->append_auth_object_debug($objid); $this->debug[] = 'parameters after running ' . var_export($this->postauthfailobj, true); if (isset($postauthfailobj->callback)) { $postauthfailobj = call_user_func_array($postauthfailobj->callback, array($postauthfailobj)); if ($postauthfailobj->exit === true) { $notice = UserNotices::get_instance(); $notice->exit_php(); return false; //just in case and needed for testing } } if ($postauthfailobj->form == 'err') { $this->display_error_form(); if (!is_null($this->configObj->get('display_auth_debug')) and $this->configObj->get('display_auth_debug') == true) { $this->display_debug(); } if ($postauthfailobj->exit === true) { $notice = UserNotices::get_instance(); $notice->exit_php(); return false; //just in case and needed for testing } } if ($postauthfailobj->form == 'std') { $this->display_std_form($string); if (!is_null($this->configObj->get('display_auth_debug')) and $this->configObj->get('display_auth_debug') == true) { $this->display_debug(); } if ($postauthfailobj->exit === true) { $notice = UserNotices::get_instance(); $notice->exit_php(); return false; //just in case and needed for testing } } if (isset($postauthfailobj->url)) { header("Location: {$postauthfailobj->url}"); if ($postauthfailobj->exit === true) { $notice = UserNotices::get_instance(); $notice->exit_php(); return false; //just in case and needed for testing } } if ($postauthfailobj->stop === true) { break; } } //failed but no callbacks or callbacks finished $notice = UserNotices::get_instance(); if (!is_null($this->configObj->get('display_auth_debug')) and $this->configObj->get('display_auth_debug') == true) { $msg = $string['Authentication_issue2']; $reason = $string['Authentication_issue2']; } else { $msg = $string['Authentication_issue2nodebug']; $reason = $string['Authentication_issue2nodebug']; } $notice->display_notice_and_exit($this->db, $string['Authentication_issue1'], sprintf($msg, $this->configObj->get('support_email'), $this->configObj->get('support_email'), $this->configObj->get('support_email'), $this->debug_to_string()), sprintf($reason, $this->configObj->get('support_email'), $this->configObj->get('support_email'), $this->configObj->get('support_email'), $this->debug_to_string()), '/artwork/fingerprint_48.png', '#C00000', true, true); } } if ($this->success !== true) { $this->debug[] = 'Success is not TRUE or FALSE'; //something went very wrong; return false; } // the auth has succeeded as above will stop it if its not true $postauthsuccessobj = new stdClass(); $postauthsuccessobj->authobj = $authobj; $postauthsuccessobj->postauthobj = $postauthobj; $postauthsuccessobj->userid =& $this->userid; if (isset($this->callbackregister['postauthsuccess'])) { foreach ($this->callbackregister['postauthsuccess'] as $number => $callback) { $this->debug[] = 'run authsuccess callback ' . get_class($callback[0]) . ':' . $callback[1]; $postauthsuccessobj = call_user_func_array($callback, array($postauthsuccessobj)); $objid = key($this->callbackregisterdata['postauthsuccess'][$number]); $this->append_auth_object_debug($objid); } } // need to save some data for allready logged in authentication $this->store_data_in_session(); }