Skip to content

Commit

Permalink
added refactored login form controller
Browse files Browse the repository at this point in the history
added check for data in ofc clas before trying to redner forms
  • Loading branch information
padams committed Jan 8, 2009
1 parent b119594 commit cb9aa48
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 127 deletions.
70 changes: 39 additions & 31 deletions modules/base/classes/ofc.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,36 +145,40 @@ function bar() {
}

function areaBar($chartData) {

if ($chartData->checkForSeries()) {

///bar
$bar = $this->getBarPlot();
$bar->set_values($this->convertArrayToInts($chartData->getSeriesData('bar')));
$bar->set_key( $chartData->getSeriesLabel('bar'), 12 );
// Make our area chart:
$area = $this->getAreaPlot();
// need to force a conversion of strings to ints for the arrea to render properly.
$numArray = $this->convertArrayToInts($chartData->getSeriesData('area'));
//$area->set_values($chartData->getSeriesData('area'));
$area->set_values($numArray);
$area->set_key( $chartData->getSeriesLabel('area'), 12 );
$this->y_axis->set_range(round($chartData->getMin('area')), round($chartData->getMax('area', 'bar')));
$this->y_axis->set_offset( false );
$this->y_axis->set_steps( round($chartData->getMax('area', 'bar') / 4) );

///bar
$bar = $this->getBarPlot();
$bar->set_values($this->convertArrayToInts($chartData->getSeriesData('bar')));
$bar->set_key( $chartData->getSeriesLabel('bar'), 12 );
// Make our area chart:
$area = $this->getAreaPlot();
// need to force a conversion of strings to ints for the arrea to render properly.
$numArray = $this->convertArrayToInts($chartData->getSeriesData('area'));
//$area->set_values($chartData->getSeriesData('area'));
$area->set_values($numArray);
$area->set_key( $chartData->getSeriesLabel('area'), 12 );
$this->y_axis->set_range(round($chartData->getMin('area')), round($chartData->getMax('area', 'bar')));
$this->y_axis->set_offset( false );
$this->y_axis->set_steps( round($chartData->getMax('area', 'bar') / 4) );

$x_labels = new x_axis_labels();
$x_labels->set_steps( 2 );
$x_labels->set_labels($chartData->getSeriesData('x'));
// Add the X Axis Labels to the X Axis
$this->x_axis->set_labels( $x_labels );

// assemble chart
$this->chart->add_y_axis($this->y_axis);
$this->chart->x_axis = $this->x_axis;
$this->chart->add_element($bar);
$this->chart->add_element($area);

return $this->chart->toPrettyString();

$x_labels = new x_axis_labels();
$x_labels->set_steps( 2 );
$x_labels->set_labels($chartData->getSeriesData('x'));
// Add the X Axis Labels to the X Axis
$this->x_axis->set_labels( $x_labels );

// assemble chart
$this->chart->add_y_axis($this->y_axis);
$this->chart->x_axis = $this->x_axis;
$this->chart->add_element($bar);
$this->chart->add_element($area);

return $this->chart->toPrettyString();
} else {
return;
}
}

function getPiePlot() {
Expand Down Expand Up @@ -228,8 +232,12 @@ function pie($chartData, $label_length = 50) {
}

function convertArrayToInts($array) {

return array_map(create_function('$value', 'return (int)$value;'),$array);
if (!empty($array)) {
return array_map(create_function('$value', 'return (int)$value;'),$array);
} else {
return false;
}

}

}
Expand Down
2 changes: 1 addition & 1 deletion modules/base/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function construct($data) {
$this->t->set('page_title', 'Error');

// Set Page headline
$this->body->set('error_msg', $data['error_msg']);
//$this->body->set('error_msg', $data['error_msg']);

if($this->is_subview == true):

Expand Down
92 changes: 32 additions & 60 deletions modules/base/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,84 +16,56 @@
// $Id$
//

require_once(OWA_BASE_DIR.'/owa_view.php');
require_once(OWA_BASE_DIR.'/owa_controller.php');
require_once(OWA_BASE_DIR.'/owa_auth.php');

/**
* Login View
*
* @author Peter Adams <[email protected]>
* @copyright Copyright &copy; 2006 Peter Adams <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GPL v2.0
* @category owa
* @package owa
* @version $Revision$
* @since owa 1.0.0
*/

class owa_loginView extends owa_view {

function owa_loginView() {

$this->owa_view();
$this->priviledge_level = 'guest';

return;
}

function construct($data) {

$this->body->set_template('login_form.tpl');// This is the inner template
$this->body->set('headline', 'Please login using the from below');
$this->body->set('user_id', $data['user_id']);
$this->body->set('go', $data['go']);

}
}

class owa_loginController extends owa_controller {

function owa_loginController($params) {
$this->owa_controller($params);
$this->priviledge_level = 'guest';

return owa_loginController::__construct($params);
}

return;
function __construct($params) {

return parent::__construct($params);
}

function action() {

$auth = &owa_auth::get_instance();
$status = $auth->authenticateNewBrowser($this->params['user_id'], $this->params['password']);
$data = array();

$status = $auth->authenticateNewBrowser($this->getParam('user_id'), $this->getParam('password'));
$go = $this->getParam('go');
// if authentication is successfull
if ($status['auth_status'] == true):
if ($status['auth_status'] == true) {

// redirect to url if present
if (!empty($this->params['go'])):
$url = urldecode($this->params['go']);

if (!empty($go)) {
// redirect to url if present
$url = urldecode($go);
$this->e->debug("redirecting browser to...:". $url);
owa_lib::redirectBrowser($url);
//else redirect to home page
else:
$data['view_method'] = 'redirect';
$data['do'] = $this->config['start_page'];
endif;
// return error view
else:

$data['view_method'] = 'delegate';
$data['view'] = 'base.login';
$data['go'] = urldecode($this->params['go']);
$data['go'] = urlencode($this->params['go']);
$data['error_msg'] = $this->getMsg(2002);
$data['user_id'] = $this->params['user_id'];

} else {
//else redirect to home page

// these need to be unset as they were set previously by the doAction method.
// need to refactor this out.
$this->set('auth_status', '');
$this->set('params', '');
$this->set('site_id', '');
$this->setRedirectAction($this->config['start_page']);
}

} else {
// return login form with error msg
$this->setView('base.loginForm');
$this->set('go', $go);
$this->set('error_code', 2002);
$this->set('user_id', $this->getParam('user_id'));

endif;
}

return $data;
return;
}


Expand Down
99 changes: 99 additions & 0 deletions modules/base/loginForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

//
// Open Web Analytics - An Open Source Web Analytics Framework
//
// Copyright 2006 Peter Adams. All rights reserved.
//
// Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// $Id$
//

require_once(OWA_BASE_DIR.'/owa_view.php');
require_once(OWA_BASE_DIR.'/owa_controller.php');
require_once(OWA_BASE_DIR.'/owa_auth.php');

/**
* Login Form Controller
*
* @author Peter Adams <[email protected]>
* @copyright Copyright &copy; 2006 Peter Adams <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GPL v2.0
* @category owa
* @package owa
* @version $Revision$
* @since owa 1.0.0
*/
class owa_loginFormController extends owa_controller {

function owa_loginFormController($params) {


return owa_loginFormController::__construct($params);
}

function __construct($params) {

return parent::__construct($params);
}

function action() {

$auth = &owa_auth::get_instance();
$this->set('go', $this->getParam('go'));
$this->set('user_id', $this->getParam('u'));
$this->setView('base.loginForm');

return;
}


}

/**
* Login Form View
*
* @author Peter Adams <[email protected]>
* @copyright Copyright &copy; 2006 Peter Adams <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GPL v2.0
* @category owa
* @package owa
* @version $Revision$
* @since owa 1.0.0
*/

class owa_loginFormView extends owa_view {

function owa_loginFormView() {

return owa_loginFormView::__construct();
}

function __construct() {

return parent::__construct();
}

function construct($data) {

$this->t->set_template('wrapper_public.tpl');
$this->body->set_template('login_form.tpl');// This is the inner template
$this->body->set('headline', 'Please login using the from below');
$this->body->set('user_id', $this->get('user_id'));
$this->body->set('go', $this->get('go'));

return;

}
}



?>
19 changes: 9 additions & 10 deletions modules/base/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// $Id$
//

require_once(OWA_BASE_DIR.'/owa_view.php');
require_once(OWA_BASE_DIR.'/owa_controller.php');
require_once(OWA_BASE_DIR.'/owa_auth.php');

Expand All @@ -35,23 +34,23 @@
class owa_logoutController extends owa_controller {

function owa_loginController($params) {
$this->owa_controller($params);
$this->priviledge_level = 'guest';

return owa_loginController::__construct($params);
}

return;
function __construct($params) {

return parent::__construct();
}

function action() {

$auth = &owa_auth::get_instance();
$auth->deleteCredentials();
$this->setRedirectAction('base.loginForm');
//$this->set('status_code', 2010);

$data = array();
$data['view_method'] = 'redirect';
$data['view'] = 'base.login';
$data['status_code'] = $this->getMsg(2010);

return $data;
return;
}


Expand Down
1 change: 0 additions & 1 deletion modules/base/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// $Id$
//

require_once(OWA_BASE_DIR.'/owa_lib.php');
require_once(OWA_BASE_DIR.'/owa_view.php');

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/base/templates/generic_error.tpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="error"><?=$error_msg;?></div>
<div class=""><?=$error_msg;?></div>
6 changes: 3 additions & 3 deletions modules/base/templates/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<LI><a href="http://trac.openwebanalytics.com">Report a Bug</a></LI>
<? if ($this->config['is_embedded'] == false):?>
<LI>
<? if ($authStatus == true):?>
<a href="<?=$this->makeLink(array('action' => 'base.logout'));?>">Logout</a>
<? if (owa_coreAPI::isCurrentUserAuthenticated()):?>
<a href="<?=$this->makeLink(array('do' => 'base.logout'), false);?>">Logout</a>
<?php else:?>
<a href="<?=$this->makeLink(array('view' => 'base.login'));?>">Login</a>
<a href="<?=$this->makeLink(array('do' => 'base.loginForm'), false);?>">Login</a>
<?php endif;?>
</LI>
<?php endif;?>
Expand Down
2 changes: 1 addition & 1 deletion modules/base/templates/login_form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<TR>
<TD></TD>
<TD>
<BR><span class="info_text"><a href="<?=$this->makeLink(array('view' => 'base.passwordResetRequest'))?>">Forgot your password?</a></span>
<BR><span class="info_text"><a href="<?=$this->makeLink(array('do' => 'base.passwordResetRequest'))?>">Forgot your password?</a></span>
</TD>
</TR>

Expand Down
2 changes: 1 addition & 1 deletion modules/base/templates/wrapper_public.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</TD>

<TD align="right">
<i>Open Source Web Analytics Framework.</i>
<i>Open Source Web Analytics</i>
</TD>
</TR>
</table>
Expand Down
Loading

0 comments on commit cb9aa48

Please sign in to comment.