openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 164cef0cf7526d336bdaae03903faaaeee9dfde7
parent e2ccafbad6d7e788fff953ab9598f88d15ec6cfa
Author: Jan Dankert <devnull@localhost>
Date:   Thu, 10 Nov 2011 21:00:44 +0100

Redirect ermöglichen, damit OpenId wieder instand gesetzt :)

Diffstat:
action/Action.class.php | 28+++++++++++++++++++++++++---
action/LoginAction.class.php | 64+++++++++++++++++++++++++++++++++++++++++-----------------------
openid.php | 6+++---
themes/default/js/openrat.js | 19++++++++++++++-----
util/OpenId.class.php | 32++++++++++++++++++++++----------
5 files changed, 105 insertions(+), 44 deletions(-)

diff --git a/action/Action.class.php b/action/Action.class.php @@ -78,13 +78,13 @@ class Action function setStyle( $style ) { - $this->setTemplateVar( "new_style", OR_THEMES_EXT_DIR.'default/css/user/'.$style.'.css' ); + $this->setControlVar( "new_style", OR_THEMES_EXT_DIR.'default/css/user/'.$style.'.css' ); } function nextView( $viewName ) { - $this->setTemplateVar( "next_view", $viewName ); + $this->setControlVar( "next_view", $viewName ); } @@ -104,6 +104,7 @@ class Action $this->templateVars['errors' ] = array(); $this->templateVars['notices'] = array(); + $this->templateVars['control'] = array(); //Html::debug($this); if ( !$this->isEditable() || isset($_COOKIE['or_always_edit']) ) @@ -265,6 +266,18 @@ class Action /** + * Setzt eine Variable f�r die Oberfl�che. + * + * @param String $varName Schl�ssel + * @param Mixed $value + */ + protected function setControlVar( $varName,$value ) + { + $this->templateVars[ 'control' ][ $varName ] = $value; + } + + + /** * Setzt eine Liste von Variablen f�r die Oberfl�che. * * @param Array $varList Assoziatives Array @@ -757,6 +770,15 @@ class Action /** + * Erzeugt einen Redirect auf einen bestimmte URL. + */ + protected function redirect( $url ) + { + $this->setControlVar( 'redirect',$url ); + } + + + /** * Sorgt dafür, dass alle anderen Views aktualisiert werden. * * Diese Methode sollte dann aufgerufen werden, wenn Objekte geändert werden @@ -765,7 +787,7 @@ class Action protected function refresh() { $this->refresh = true; - $this->setTemplateVar('refresh',true); + $this->setControlVar('refresh',true); } diff --git a/action/LoginAction.class.php b/action/LoginAction.class.php @@ -563,35 +563,41 @@ class LoginAction extends Action * Es muss noch beim OpenId-Provider die Best�tigung eingeholt werden, danach ist der * Benutzer angemeldet.<br> */ - function openid() + public function openidView() { global $conf; $openId = Session::get('openid'); if ( !$openId->checkAuthentication() ) { + Http::notAuthorized('OpenId-Login failed' ); + die(); $this->addNotice('user',$openId->user,'LOGIN_OPENID_FAILED',OR_NOTICE_ERROR,array('name'=>$openId->user),array($openId->error) ); - $this->addValidationError('openid_url',''); + $this->addValidationError('openid_url',''); $this->callSubAction('showlogin'); return; - } + } - //Html::debug($openId); + //Html::debug($openId); // Anmeldung wurde mit "is_valid:true" best�tigt. - // Der Benutzer ist jetzt eingeloggt. - $username = $openId->getUserFromIdentiy(); - + // Der Benutzer ist jetzt eingeloggt. + $username = $openId->getUserFromIdentiy(); + + Logger::debug("OpenId-Login successful for $username"); + if ( empty($username) ) { // Es konnte kein Benutzername ermittelt werden. + Http::notAuthorized('no username supplied by openid provider' ); + die(); $this->addNotice('user',$username,'LOGIN_OPENID_FAILED','error',array('name'=>$username) ); $this->addValidationError('openid_url',''); - $this->callSubAction('showlogin'); + $this->callSubAction('showlogin'); return; - } - - $user = User::loadWithName( $username ); + } + + $user = User::loadWithName( $username ); if ( $user->userid <=0) { @@ -601,16 +607,19 @@ class LoginAction extends Action $user->name = $username; $user->add(); - $user->mail = $openId->info['email']; - $user->fullname = $openId->info['fullname']; + $user->mail = @$openId->info['email']; + $user->fullname = @$openId->info['fullname']; $user->save(); // Um E-Mail zu speichern (wird bei add() nicht gemacht) } - else + else { - // Benutzer ist nicht in Benutzertabelle vorhanden (und angelegt werden soll er auch nicht). + Logger::debug("OpenId-Login failed for $username"); + // Benutzer ist nicht in Benutzertabelle vorhanden (und angelegt werden soll er auch nicht). + Http::notAuthorized('user',$username,'LOGIN_OPENID_FAILED','error',array('name'=>$username) ); + die(); + $this->addNotice('user',$username,'LOGIN_OPENID_FAILED','error',array('name'=>$username) ); $this->addValidationError('openid_url',''); - $this->callSubAction('showlogin'); return; } } @@ -619,13 +628,22 @@ class LoginAction extends Action // Benutzer ist bereits vorhanden. if ( @$conf['security']['openid']['update_user']) { - $user->fullname = $openId->info['fullname']; - $user->mail = $openId->info['email']; + $user->fullname = @$openId->info['fullname']; + $user->mail = @$openId->info['email']; $user->save(); } } - - $user->setCurrent(); // Benutzer ist jetzt in der Sitzung. + + Logger::info("User login successful: ".$username); + $user->setCurrent(); // Benutzer ist jetzt in der Sitzung. + + $this->setStyle( $user->style ); + $this->setPerspective('start'); + + $server = Http::getServer(); + Logger::debug("Redirecting to $server"); + header('Location: '.slashify($server) ); + exit(); } @@ -664,9 +682,9 @@ class LoginAction extends Action return; } - Session::set('openid',$openId); - $openId->redirect(); - die('Unreachable Code'); + Session::set('openid',$openId); + $this->redirect( $openId->getRedirectUrl() ); + return; } diff --git a/openid.php b/openid.php @@ -1,8 +1,8 @@ <?php - -$_GET['action'] = 'index'; +exit(); +$_GET['action'] = 'login'; $_GET['subaction'] = 'openid'; -require( 'do.php' ); +require( 'dispcher.php' ); ?> \ No newline at end of file diff --git a/themes/default/js/openrat.js b/themes/default/js/openrat.js @@ -484,14 +484,23 @@ function doResponse(data,status) $('input[name='+value+']').addClass('error'); }); - if ( 'refresh' in data ) + // Jetzt das erhaltene Dokument auswerten. + + // Redirect + if ( data.control.redirect ) + window.location.href = data.control.redirect; + + // Views aktualisieren + if ( data.control.refresh ) refreshAll(); - if ( data.new_style ) - setUserStyle( data.new_style ); + // CSS-Datei setzen + if ( data.control.new_style ) + setUserStyle( data.control.new_style ); - if ( data.next_view ) - startView( $('div.filler').first(),data.next_view ); + // Nächste View aufrufen + if ( data.control.next_view ) + startView( $('div.filler').first(),data.control.next_view ); } diff --git a/util/OpenId.class.php b/util/OpenId.class.php @@ -71,9 +71,9 @@ class OpenId /** - * Stellt fest, ob der Server vertrauensw�rdig ist. + * Stellt fest, ob der Server vertrauenswuerdig ist. * - * @return true, wenn vertrauensw�rdig. + * @return true, wenn vertrauenswuerdig. */ function serverOk() { @@ -151,7 +151,7 @@ class OpenId /** * Erzeugt einen HTTP-Redirect auf den OpenId-Provider. */ - function redirect() + public function getRedirectUrl() { global $conf; @@ -202,8 +202,7 @@ class OpenId //$redirHttp->requestParameter['openid.realm' ] = slashify($server).'openid.'.PHP_EXT; $redirHttp->requestParameter['openid.assoc_handle' ] = $this->handle; - $redirHttp->sendRedirect(); // Browser umleiten. - exit; // Ende. + return $redirHttp->getUrl(); } @@ -213,7 +212,7 @@ class OpenId * * @return unknown */ - function getIdentityFromYadis() + private function getIdentityFromYadis() { $http = new Http($this->user); // $http->url['host'] = $this->user; @@ -275,7 +274,7 @@ class OpenId /** * Ermittelt OpenId-Server und OpenId-Identity aus HTML Meta-Tags.<br> */ - function getIdentityFromHtmlMetaData() + private function getIdentityFromHtmlMetaData() { $http = new Http($this->user); // $http = new Http(); @@ -319,7 +318,7 @@ class OpenId * * @return String */ - function getUserFromIdentiy() + public function getUserFromIdentiy() { if ( $this->provider == 'identity' ) { @@ -345,24 +344,32 @@ class OpenId * Es muss noch beim OpenId-Provider die Best�tigung eingeholt werden, danach ist der * Benutzer angemeldet.<br> */ - function checkAuthentication() + public function checkAuthentication() { $queryVars = $this->getQueryParamList(); if ( $queryVars['openid.invalidate_handle'] != $this->handle ) { + Http::notAuthorized('Association-Handle mismatch.'); + die(); $this->error = 'Association-Handle mismatch.'; return false; } if ( $queryVars['openid.mode'] != 'id_res' ) { + Http::notAuthorized('Open-Id: Unknown mode:'.$queryVars['openid.mode']); + die(); + $this->error ='Open-Id: Unknown mode:'.$queryVars['openid.mode']; return false; } if ( $this->provider=='identity' && $queryVars['openid.identity'] != $this->identity ) { + Http::notAuthorized('Open-Id: Identity mismatch. Wrong identity:'.$queryVars['openid.identity']); + die(); + $this->error ='Open-Id: Identity mismatch. Wrong identity:'.$queryVars['openid.identity']; return false; } @@ -421,6 +428,9 @@ class OpenId if ( !array_key_exists('is_valid',$result) ) { // Zeile nicht gefunden. + Http::notAuthorized('Undefined Open-Id response: "is_valid" expected, but not found'); + die(); + $this->error = 'Undefined Open-Id response: "is_valid" expected, but not found'; return false; } @@ -432,6 +442,8 @@ class OpenId else { // Bestaetigung wurde durch den OpenId-Provider abgelehnt. + Http::notAuthorized('Server refused login.'); + die(); $this->error = 'Server refused login.'; return false; } @@ -446,7 +458,7 @@ class OpenId * * @return Parameter der aktuellen URL */ - function getQueryParamList() + private function getQueryParamList() { // Quelle: php.net $str = $_SERVER['QUERY_STRING'];