Permalink
Browse files

Readability improvements

  • Loading branch information...
flack committed Oct 22, 2017
1 parent 77e754b commit 6dfa0147020e85764dd069e8aa79b46e0f529076
Showing with 26 additions and 33 deletions.
  1. +26 −33 lib/midcom/services/auth/main.php
@@ -138,43 +138,35 @@ public function __construct()
*/
public function check_for_login_session(Request $request)
{
$credentials = $this->_auth_frontend->read_login_data($request);
if (!$credentials) {
// No new login detected, so we check if there is a running session.
if ($user = $this->_auth_backend->check_for_active_login_session($request)) {
$this->set_user($user);
// Try to start up a new session, this will authenticate as well.
if ($credentials = $this->_auth_frontend->read_login_data($request)) {
if (!$this->login($credentials['username'], $credentials['password'], $request->getClientIp())) {
return;
}
return;
}
debug_add('Authentication was successful, we have a new login session now. Updating timestamps');
// Try to start up a new session, this will authenticate as well.
if (!$user = $this->_auth_backend->login($credentials['username'], $credentials['password'], $request->getClientIp())) {
debug_add('The login information passed to the system was invalid.', MIDCOM_LOG_ERROR);
debug_add("Username was {$credentials['username']}");
// No password logging for security reasons.
return;
}
$person_class = midcom::get()->config->get('person_class');
$person = new $person_class($this->user->guid);
if ( midcom::get()->config->get('auth_save_prev_login')
&& $person->get_parameter('midcom', 'last_login')) {
$person->set_parameter('midcom', 'prev_login', $person->get_parameter('midcom', 'last_login'));
}
debug_add('Authentication was successful, we have a new login session now. Updating timestamps');
$this->set_user($user);
$person->set_parameter('midcom', 'last_login', time());
$person_class = midcom::get()->config->get('person_class');
$person = new $person_class($this->user->guid);
if ( midcom::get()->config->get('auth_save_prev_login')
&& $person->get_parameter('midcom', 'last_login')) {
$person->set_parameter('midcom', 'prev_login', $person->get_parameter('midcom', 'last_login'));
}
$person->set_parameter('midcom', 'last_login', time());
if (!$person->get_parameter('midcom', 'first_login')) {
$person->set_parameter('midcom', 'first_login', time());
}
if (!$person->get_parameter('midcom', 'first_login')) {
$person->set_parameter('midcom', 'first_login', time());
// Now we check whether there is a success-relocate URL given somewhere.
if ($request->query->has('midcom_services_auth_login_success_url')) {
midcom::get()->relocate($request->query->get('midcom_services_auth_login_success_url'));
// This will exit.
}
}
// Now we check whether there is a success-relocate URL given somewhere.
if ($request->query->has('midcom_services_auth_login_success_url')) {
midcom::get()->relocate($request->query->get('midcom_services_auth_login_success_url'));
// This will exit.
// No new login detected, so we check if there is a running session.
elseif ($user = $this->_auth_backend->check_for_active_login_session($request)) {
$this->set_user($user);
}
}
@@ -703,12 +695,13 @@ public function get_group($id)
/**
* This call tells the backend to log in.
*/
public function login($username, $password)
public function login($username, $password, $clientip = null)
{
if ($user = $this->_auth_backend->login($username, $password)) {
if ($user = $this->_auth_backend->login($username, $password, $clientip)) {
$this->set_user($user);
return true;
}
debug_add('The login information for ' . $username . ' was invalid.', MIDCOM_LOG_WARN);
return false;
}

0 comments on commit 6dfa014

Please sign in to comment.