summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Auth/Database.php5
-rw-r--r--app/Auth/GitHub.php5
-rw-r--r--app/Auth/Google.php5
-rw-r--r--app/Auth/Ldap.php6
-rw-r--r--app/Auth/RememberMe.php5
-rw-r--r--app/Auth/ReverseProxy.php5
-rw-r--r--app/Controller/User.php10
-rw-r--r--app/Core/Request.php57
-rw-r--r--app/Model/Authentication.php3
-rw-r--r--app/Model/User.php56
10 files changed, 84 insertions, 73 deletions
diff --git a/app/Auth/Database.php b/app/Auth/Database.php
index 67881593..47dc8e6e 100644
--- a/app/Auth/Database.php
+++ b/app/Auth/Database.php
@@ -3,6 +3,7 @@
namespace Auth;
use Model\User;
+use Core\Request;
/**
* Database authentication
@@ -40,8 +41,8 @@ class Database extends Base
$this->lastLogin->create(
self::AUTH_NAME,
$user['id'],
- $this->user->getIpAddress(),
- $this->user->getUserAgent()
+ Request::getIpAddress(),
+ Request::getUserAgent()
);
return true;
diff --git a/app/Auth/GitHub.php b/app/Auth/GitHub.php
index 0910367a..096d4101 100644
--- a/app/Auth/GitHub.php
+++ b/app/Auth/GitHub.php
@@ -4,6 +4,7 @@ namespace Auth;
require __DIR__.'/../../vendor/OAuth/bootstrap.php';
+use Core\Request;
use OAuth\Common\Storage\Session;
use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Uri\UriFactory;
@@ -44,8 +45,8 @@ class GitHub extends Base
$this->lastLogin->create(
self::AUTH_NAME,
$user['id'],
- $this->user->getIpAddress(),
- $this->user->getUserAgent()
+ Request::getIpAddress(),
+ Request::getUserAgent()
);
return true;
diff --git a/app/Auth/Google.php b/app/Auth/Google.php
index aeeab563..2bed5b09 100644
--- a/app/Auth/Google.php
+++ b/app/Auth/Google.php
@@ -4,6 +4,7 @@ namespace Auth;
require __DIR__.'/../../vendor/OAuth/bootstrap.php';
+use Core\Request;
use OAuth\Common\Storage\Session;
use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Uri\UriFactory;
@@ -45,8 +46,8 @@ class Google extends Base
$this->lastLogin->create(
self::AUTH_NAME,
$user['id'],
- $this->user->getIpAddress(),
- $this->user->getUserAgent()
+ Request::getIpAddress(),
+ Request::getUserAgent()
);
return true;
diff --git a/app/Auth/Ldap.php b/app/Auth/Ldap.php
index 63d495fa..4f20998f 100644
--- a/app/Auth/Ldap.php
+++ b/app/Auth/Ldap.php
@@ -2,6 +2,8 @@
namespace Auth;
+use Core\Request;
+
/**
* LDAP model
*
@@ -58,8 +60,8 @@ class Ldap extends Base
$this->lastLogin->create(
self::AUTH_NAME,
$user['id'],
- $this->user->getIpAddress(),
- $this->user->getUserAgent()
+ Request::getIpAddress(),
+ Request::getUserAgent()
);
return true;
diff --git a/app/Auth/RememberMe.php b/app/Auth/RememberMe.php
index 50e0bcef..380abbed 100644
--- a/app/Auth/RememberMe.php
+++ b/app/Auth/RememberMe.php
@@ -2,6 +2,7 @@
namespace Auth;
+use Core\Request;
use Core\Security;
use Core\Tool;
@@ -107,8 +108,8 @@ class RememberMe extends Base
$this->lastLogin->create(
self::AUTH_NAME,
$this->acl->getUserId(),
- $this->user->getIpAddress(),
- $this->user->getUserAgent()
+ Request::getIpAddress(),
+ Request::getUserAgent()
);
return true;
diff --git a/app/Auth/ReverseProxy.php b/app/Auth/ReverseProxy.php
index 6880f5fa..5aca881a 100644
--- a/app/Auth/ReverseProxy.php
+++ b/app/Auth/ReverseProxy.php
@@ -2,6 +2,7 @@
namespace Auth;
+use Core\Request;
use Core\Security;
/**
@@ -44,8 +45,8 @@ class ReverseProxy extends Base
$this->lastLogin->create(
self::AUTH_NAME,
$user['id'],
- $this->user->getIpAddress(),
- $this->user->getUserAgent()
+ Request::getIpAddress(),
+ Request::getUserAgent()
);
return true;
diff --git a/app/Controller/User.php b/app/Controller/User.php
index c94c2c88..cc7464e6 100644
--- a/app/Controller/User.php
+++ b/app/Controller/User.php
@@ -34,12 +34,11 @@ class User extends Base
$this->response->redirect('?controller=app');
}
- $redirect_query = $this->request->getStringParam('redirect_query');
$this->response->html($this->template->layout('user_login', array(
'errors' => array(),
'values' => array(),
'no_layout' => true,
- 'redirect_query' => $redirect_query,
+ 'redirect_query' => $this->request->getStringParam('redirect_query'),
'title' => t('Login')
)));
}
@@ -56,9 +55,10 @@ class User extends Base
list($valid, $errors) = $this->authentication->validateForm($values);
if ($valid) {
- if ($redirect_query != "") {
+ if ($redirect_query !== '') {
$this->response->redirect('?'.$redirect_query);
- } else {
+ }
+ else {
$this->response->redirect('?controller=board');
}
}
@@ -420,6 +420,7 @@ class User extends Base
'errors' => array('login' => t('Google authentication failed')),
'values' => array(),
'no_layout' => true,
+ 'redirect_query' => '',
'title' => t('Login')
)));
}
@@ -481,6 +482,7 @@ class User extends Base
'errors' => array('login' => t('GitHub authentication failed')),
'values' => array(),
'no_layout' => true,
+ 'redirect_query' => '',
'title' => t('Login')
)));
}
diff --git a/app/Core/Request.php b/app/Core/Request.php
index 09792013..31672ff6 100644
--- a/app/Core/Request.php
+++ b/app/Core/Request.php
@@ -148,4 +148,61 @@ class Request
return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
}
+ /**
+ * Get the user agent
+ *
+ * @static
+ * @access public
+ * @return string
+ */
+ public static function getUserAgent()
+ {
+ return empty($_SERVER['HTTP_USER_AGENT']) ? t('Unknown') : $_SERVER['HTTP_USER_AGENT'];
+ }
+
+ /**
+ * Get the real IP address of the user
+ *
+ * @static
+ * @access public
+ * @param bool $only_public Return only public IP address
+ * @return string
+ */
+ public static function getIpAddress($only_public = false)
+ {
+ $keys = array(
+ 'HTTP_CLIENT_IP',
+ 'HTTP_X_FORWARDED_FOR',
+ 'HTTP_X_FORWARDED',
+ 'HTTP_X_CLUSTER_CLIENT_IP',
+ 'HTTP_FORWARDED_FOR',
+ 'HTTP_FORWARDED',
+ 'REMOTE_ADDR'
+ );
+
+ foreach ($keys as $key) {
+
+ if (isset($_SERVER[$key])) {
+
+ foreach (explode(',', $_SERVER[$key]) as $ip_address) {
+
+ $ip_address = trim($ip_address);
+
+ if ($only_public) {
+
+ // Return only public IP address
+ if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
+ return $ip_address;
+ }
+ }
+ else {
+
+ return $ip_address;
+ }
+ }
+ }
+ }
+
+ return t('Unknown');
+ }
}
diff --git a/app/Model/Authentication.php b/app/Model/Authentication.php
index 6efc5687..b9ebcfe2 100644
--- a/app/Model/Authentication.php
+++ b/app/Model/Authentication.php
@@ -2,6 +2,7 @@
namespace Model;
+use Core\Request;
use Auth\Database;
use SimpleValidator\Validator;
use SimpleValidator\Validators;
@@ -117,7 +118,7 @@ class Authentication extends Base
if (! empty($values['remember_me'])) {
$credentials = $this->backend('rememberMe')
- ->create($this->acl->getUserId(), $this->user->getIpAddress(), $this->user->getUserAgent());
+ ->create($this->acl->getUserId(), Request::getIpAddress(), Request::getUserAgent());
$this->backend('rememberMe')->writeCookie($credentials['token'], $credentials['sequence'], $credentials['expiration']);
}
diff --git a/app/Model/User.php b/app/Model/User.php
index 8add9722..b54f6309 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -370,60 +370,4 @@ class User extends Base
return array(false, $v->getErrors());
}
-
- /**
- * Get the user agent of the connected user
- *
- * @access public
- * @return string
- */
- public function getUserAgent()
- {
- return empty($_SERVER['HTTP_USER_AGENT']) ? t('Unknown') : $_SERVER['HTTP_USER_AGENT'];
- }
-
- /**
- * Get the real IP address of the connected user
- *
- * @access public
- * @param bool $only_public Return only public IP address
- * @return string
- */
- public function getIpAddress($only_public = false)
- {
- $keys = array(
- 'HTTP_CLIENT_IP',
- 'HTTP_X_FORWARDED_FOR',
- 'HTTP_X_FORWARDED',
- 'HTTP_X_CLUSTER_CLIENT_IP',
- 'HTTP_FORWARDED_FOR',
- 'HTTP_FORWARDED',
- 'REMOTE_ADDR'
- );
-
- foreach ($keys as $key) {
-
- if (isset($_SERVER[$key])) {
-
- foreach (explode(',', $_SERVER[$key]) as $ip_address) {
-
- $ip_address = trim($ip_address);
-
- if ($only_public) {
-
- // Return only public IP address
- if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
- return $ip_address;
- }
- }
- else {
-
- return $ip_address;
- }
- }
- }
- }
-
- return t('Unknown');
- }
}