I've had a look at the other questions relating to this topic but none have been useful.
Expected Outcome
From a homepage with links to different web apps, the user clicks to access a web app. The user is redirected to the login page. I've tried to override the login function to auto-login network users based on a lookup on their IP address. Their machine name is stored as their username in the database and all the passwords are the same. This is validated and the user is automatically logged in and redirected to the web apps home page, with no need to see a login form.
Note: this auto-login works when accessing the web address directly, but this problem started when I added in the "dashboard" of web apps. However, this is required so there is only one shortcut on the users desktop.
routes.php Code
Rou开发者_如何学Pythonter::connect('/', array('controller' => 'cns', 'action' => 'view'));
app_controller.php Code
function beforeFilter() {
$this->Auth->allow('display');
# Users need authorised before viewing these pages
$this->Auth->deny('index','view', 'add','edit','delete');
$this->Auth->loginRedirect = array( 'controller'=>'cns', 'action'=>'view');
$this->Auth->logoutRedirect = array( 'controller'=>'pages', 'action'=>'logged_out');
}
users_controller.php Code
function beforeFilter() {
$this->Auth->autoRedirect = false;
}
function login () {
# Automatic login based on computer name
$this->data['User']['password'] = $this->Auth->password('qwerty');
# Result: x-xxxxxx.domain.local (function declared below)
$full_host = gethostbyaddr($this->get_user_IP_address());
# Result: x-xxxxxx[.domain.local]
$position_of_split = strrpos($full_host, ".gmi.local");
# Result: x-xxxxxx
$computer_name = substr($full_host,0,$position_of_split);
# If username is not been provided, use the computer name discovered by auto-login
(!isset($this->data['User']['username']) ? $this->data['User']['username'] = $computer_name : null);
# If login is successful, redirect to view. Otherwise, echo error message.
if($this->Auth->login($this->data)){
$this->redirect(array('controller' => 'cns', 'action' => 'view'));
} else {
echo "Unable to log you in. Please advise IT."; die;
}
}
function get_user_IP_address() {
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
if (isset($_SERVER["HTTP_CLIENT_IP"]))
return $_SERVER["HTTP_CLIENT_IP"];
return $_SERVER["REMOTE_ADDR"];
}
if (getenv('HTTP_X_FORWARDED_FOR'))
return getenv('HTTP_X_FORWARDED_FOR');
if (getenv('HTTP_CLIENT_IP'))
return getenv('HTTP_CLIENT_IP');
return getenv('REMOTE_ADDR');
}
If you need further code or explanation, just ask in the comments.
Thanks in advance. :)
I don't know if you found the solution to your problem but I had the same problem and found the following article which describes the cause and provides workaround.
Infinite loop login redirect
精彩评论