From fbf983ec571563c96c1687e9f0f46f4bc4da31fd Mon Sep 17 00:00:00 2001 From: padams Date: Thu, 8 Jan 2009 07:26:35 +0000 Subject: [PATCH] refactored validation and validator objects to be object oriented and configurable by controllers. added stringMatch and stringLength validations. added password form coontroller. --- modules/base/classes/validation.php | 64 +++++++++++-- modules/base/classes/validator.php | 38 ++++---- modules/base/passwordResetForm.php | 87 ++++++++++++++++++ modules/base/passwordResetRequest.php | 77 +++++----------- modules/base/templates/css.tpl | 59 ++++++++---- modules/base/templates/login_form.tpl | 83 +++++++++-------- .../base/templates/users_change_password.tpl | 69 +++++++------- .../users_password_reset_request.tpl | 74 +++++++++------ .../templates/users_reset_password_email.tpl | 2 +- modules/base/templates/wrapper_public.tpl | 32 +++---- modules/base/usersChangePassword.php | 90 +++++++++--------- modules/base/usersPasswordEntry.php | 1 + modules/base/usersResetPassword.php | 37 ++++---- owa_auth.php | 2 +- owa_controller.php | 22 ++++- owa_coreAPI.php | 15 ++- plugins/validations/required.php | 29 ++++-- plugins/validations/stringLength.php | 92 +++++++++++++++++++ plugins/validations/stringMatch.php | 72 +++++++++++++++ plugins/validations/subStringPosition.php | 52 +++++------ 20 files changed, 675 insertions(+), 322 deletions(-) create mode 100644 modules/base/passwordResetForm.php create mode 100644 plugins/validations/stringLength.php create mode 100644 plugins/validations/stringMatch.php diff --git a/modules/base/classes/validation.php b/modules/base/classes/validation.php index 77d33e22d..fa5d862cd 100644 --- a/modules/base/classes/validation.php +++ b/modules/base/classes/validation.php @@ -28,7 +28,13 @@ * @since owa 1.0.0 */ - class owa_validation extends owa_base { + class owa_validation { + + // hold config + var $conf; + + // hold values to validate + var $values; var $hasError; @@ -36,18 +42,20 @@ class owa_validation extends owa_base { var $errorMsgTemplate; - function owa_validation($conf) { - - $this->owa_base(); - - if (!empty($conf['errorMsgTemplate'])): + function owa_validation($conf = array()) { + + return owa_validation::__construct($conf); + } + + function __construct($conf = array()) { + + if (array_key_exists('errorMsgTemplate', $conf)): $this->errorMsgTemplate = $conf['errorMsgTemplate']; endif; - - return; + } - function validate($value) { + function validate() { return false; } @@ -64,6 +72,7 @@ function setErrorMsgTemplate($string) { return; } + // depricated function setErrorMsg($msg) { $this->errorMsg = $msg; @@ -73,6 +82,10 @@ function setErrorMsg($msg) { } + function setErrorMessage($msg) { + $this->errorMsg = $msg; + } + function isValid() { if ($this->hasError == true): @@ -82,7 +95,40 @@ function isValid() { endif; } + function setConfig($name, $value) { + + $this->conf[$name] = $value; + return; + } + + function setConfigArray($array) { + + $this->conf = $array; + return; + } + + function getConfig($name) { + + return $this->conf[$name]; + } + + function setValues($values) { + + $this->values = $values; + return; + } + function getValues() { + + return $this->values; + + } + + function hasError() { + + $this->hasError = true; + return; + } } diff --git a/modules/base/classes/validator.php b/modules/base/classes/validator.php index 8e7591d11..7009961ea 100644 --- a/modules/base/classes/validator.php +++ b/modules/base/classes/validator.php @@ -76,25 +76,32 @@ function owa_validator() { */ function addValidation($name, $value, $validation, $conf) { - $this->validations[$name] = array('value' => $value, 'validation' => $validation, 'conf' => $conf); + $this->validations[] = $name; + // Construct validatation obj + $this->validators[$name] = $this->validationFactory($validation); + $this->validators[$name]->setValues($value); + $this->validators[$name]->setConfigArray($conf); + return; } + function setValidation($name, $obj) { + + $this->validations[] = $name; + $this->validators[$name] = $obj; + return; + } + /** * Factory method for producing validation objects * * @return Object */ - function validationFactory($class_file, $conf) { - - if (!class_exists('owa_validation')): - require_once(OWA_BASE_CLASS_DIR.'validation.php'); - endif; - - return owa_lib::factory(OWA_PLUGINS_DIR.'/validations', 'owa_', $class_file, $conf, 'Validation'); + function validationFactory($class_file) { + return owa_coreAPI::validationFactory($class_file, $conf); } /** @@ -103,19 +110,16 @@ function validationFactory($class_file, $conf) { */ function doValidations() { - foreach ($this->validations as $k => $v) { - - // Construct validatation obj - $this->validators[$k] = $this->validationFactory($v['validation'], $v['conf']); - - $this->validators[$k]->validate($v['value']); + foreach ($this->validations as $k) { - if ($this->validators[$k]->hasError == true): + $this->validators[$k]->validate(); + if ($this->validators[$k]->hasError === true): + //print_r($this->validators[$k]); $this->hasErrors = true; - $this->errorMsgs[$k] = $this->validators[$k]->errorMsg; + $this->errorMsgs[$k] = $this->validators[$k]->getErrorMsg(); - if ($this->validators[$k]->conf['stopOnError'] == true): + if ($this->validators[$k]->conf['stopOnError'] === true): break; endif; diff --git a/modules/base/passwordResetForm.php b/modules/base/passwordResetForm.php new file mode 100644 index 000000000..1831cddfa --- /dev/null +++ b/modules/base/passwordResetForm.php @@ -0,0 +1,87 @@ + + * @copyright Copyright © 2006 Peter Adams + * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 + * @category owa + * @package owa + * @version $Revision$ + * @since owa 1.0.0 + */ + +class owa_passwordResetFormController extends owa_controller { + + function owa_passwordResetFormController($params) { + + return owa_passwordResetFormController::__construct($params); + } + + function __construct($params) { + + return parent::__construct($params); + } + + function action() { + + $this->setView('base.passwordResetForm'); + + return; + } +} + + +/** + * Password Reset Request View + * + * @author Peter Adams + * @copyright Copyright © 2006 Peter Adams + * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 + * @category owa + * @package owa + * @version $Revision$ + * @since owa 1.0.0 + */ + +class owa_passwordResetFormView extends owa_view { + + function owa_passwordResetFormView() { + + return owa_passwordResetFormView::__construct(); + } + + function __construct() { + + return parent::__construct(); + } + + function render($data) { + $this->t->set_template('wrapper_public.tpl'); + $this->body->set_template('users_password_reset_request.tpl'); + return; + } + +} + +?> \ No newline at end of file diff --git a/modules/base/passwordResetRequest.php b/modules/base/passwordResetRequest.php index e2c8697a2..add3fd36b 100644 --- a/modules/base/passwordResetRequest.php +++ b/modules/base/passwordResetRequest.php @@ -16,41 +16,7 @@ // $Id$ // -require_once(OWA_BASE_DIR.'/owa_view.php'); -require_once(OWA_BASE_DIR.'/owa_adminController.php'); - -/** - * Password Reset Request View - * - * @author Peter Adams - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_passwordResetRequestView extends owa_view { - - function owa_passwordResetRequest($params) { - - $this->owa_view($params); - - return; - } - - function construct($data) { - - $this->body->set_template('users_password_reset_request.tpl');// This is the inner template - $this->body->set('headline', 'Type in the email address that is associated with your user account.'); - $this->body->set('u', $this->params['u']); - - return; - } - -} - +require_once(OWA_BASE_DIR.'/owa_controller.php'); /** * Password Reset Request Controller @@ -64,43 +30,44 @@ function construct($data) { * @since owa 1.0.0 */ -class owa_passwordResetRequestController extends owa_adminController { +class owa_passwordResetRequestController extends owa_controller { function owa_passwordResetRequestController($params) { - $this->owa_adminController($params); - $this->priviledge_level = 'guest'; - return; + return owa_passwordResetRequestController::__construct($params); } - function doAction() { + function __construct($params) { + + return parent::__construct($params); + } + + function action() { // Check to see if this email exists in the db - $u = new owa_user; - $u->getUserByEmail($this->params['email_address']); + // fetch user object from the db + $u = owa_coreAPI::entityFactory('base.user'); + $u->getByColumn('email_address', $this->getParam('email_address')); + $uid = $u->get('user_id'); - $data = array(); - // If user exists then fire event and return view - if (!empty($u->user_id)): + if (!empty($uid)) { // Log password reset request to event queue $eq = &eventQueue::get_instance(); - $eq->log(array('user_id' => $u->user_id), 'base.reset_password'); + $eq->log(array('user_id' => $uid), 'base.reset_password'); // return view - $data['view'] = 'base.passwordResetRequest'; - $data['view_method'] = 'delegate'; - $data['status_msg'] = $this->getMsg(2000, $this->params['email_address']); + $this->setView('base.passwordResetForm'); + $this->set('status_msg', $this->getMsg(2000, $this->getParam('email_address'))); // if user does not exists just return view with error - else: - $data['view'] = 'base.passwordResetRequest'; - $data['view_method'] = 'delegate'; - $data['error_msg'] = $this->getMsg(2001, $this->params['email_address']); - endif; + } else { + $this->setView('base.passwordResetForm'); + $this->set('error_msg', $this->getMsg(2001, $this->getParam('email_address'))); + } - return $data; + return; } } diff --git a/modules/base/templates/css.tpl b/modules/base/templates/css.tpl index 0af99270a..818302b8e 100644 --- a/modules/base/templates/css.tpl +++ b/modules/base/templates/css.tpl @@ -66,7 +66,7 @@ div {margin:0;} .inline_h2_grey {font-size:20px; color:#cccccc;} .inline_h3 {font-size:16px;} .inline_h4 {font-size:14px;} -.headline {font-size:20px; background-color:#E0EEEE;color:;border-color:#000000;padding:6px; font-weight:bold;margin: 0px 0px 0px 0px;} +.headline {font-size:20px; background-color:orange;color:#ffffff;border-color:#000000;padding:6px; font-weight:bold;margin: 0px 0px 0px 0px;} .panel_headline {font-size:18px; background-color:#FFF8DC;padding:10px;font-weight:bold;margin: 0px 0px 20px 0px;border-bottom:solid 1px} .sub-legend {font-size:16px;font-weight:bold; } @@ -82,20 +82,16 @@ div {margin:0;} .subview_content{padding:10px;} .subview_content td {padding:20ps;} #nav_left {width:240px;} -.data {white-space:; width:auto;} -.form {width:;} -.sub-row {padding-left:20px; font-weight:normal;} -#summary_stats {font-size:16px; font-weight: normal;} -/* FORMATING */ +/* FORMATING */ +.owa_largeFormField { font-size:18px;} .active_wizard_step {background-color:#1874CD; color:#ffffff;border:1px solid; padding:5px; font-weight:bold; font-size:16px;} .wizard_step {font-weight:bold; font-size:16px;} .visitor_info_box {width:40px; height:40px; text-align:center; padding:7px;} .owa_visitSummaryLeftCol {width:auto;} .owa_visitSummaryRightCol {padding-left:15px;width:auto; vertical-align: top;} .visit_icon {width:40px;} -.graph {padding:10px; text-align:center;} .comments_info_box { padding:4px 4px 4px 4px; border:solid 0px #999999; @@ -136,19 +132,48 @@ div {margin:0;} .setting .title {font-weight:bold; font-size:16px; padding: 2px 0 2px 0;} .setting .field {padding: 2px 0 2px 0;} - - - - /* LAYOUT */ -#summary_stats {border-collapse: collapse; width:100%;} -#summary_stats td {border:2px solid #CCCCCC; padding:10px; height:65px; width:px; vertical-align:center; margin:0px; min-width:150px;} -#trend_graph {text-align:center;} #admin_nav{font-size:12px;} #keywords{width:400px;} -#login_box {width:390px;} #owa_header {background-color:#FFFFFF; padding:4px; font-weight:bold; clear: both;} -#report_top_level_nav {margin: 5px 0 0 0;} #side_bar {width:auto; color: ; border-right: 0px solid #000000; padding: 5px; background-color: ; font-size: 12px;} -#report_filters {margin:0 0 30px 0;} + +/* ROUNDER CORNERS */ +.spiffy{display:block;} +.spiffy *{ + display:block; + height:1px; + overflow:hidden; + font-size:.01em; + background:#494444} +.spiffy1{ + margin-left:3px; + margin-right:3px; + padding-left:1px; + padding-right:1px; + border-left:1px solid #b0aeae; + border-right:1px solid #b0aeae; + background:#767272} +.spiffy2{ + margin-left:1px; + margin-right:1px; + padding-right:1px; + padding-left:1px; + border-left:1px solid #ececec; + border-right:1px solid #ececec; + background:#6b6767} +.spiffy3{ + margin-left:1px; + margin-right:1px; + border-left:1px solid #6b6767; + border-right:1px solid #6b6767;} +.spiffy4{ + border-left:1px solid #b0aeae; + border-right:1px solid #b0aeae} +.spiffy5{ + border-left:1px solid #767272; + border-right:1px solid #767272} +.spiffyfg{ + background:#494444;} + \ No newline at end of file diff --git a/modules/base/templates/login_form.tpl b/modules/base/templates/login_form.tpl index a9d4e804a..64aa061ee 100644 --- a/modules/base/templates/login_form.tpl +++ b/modules/base/templates/login_form.tpl @@ -1,42 +1,49 @@ - - -

- -
-
- -
- Login - - - - - +
+
Login

-
- - - - - - - - +
+ +
+ + + + + + + + + + + + + + - - - - - -
User Name:
Password:
+
+ + + + + + + +
+ +
+ + + +
User Name:
+

+
Password:
+

-
-
Forgot your password? -
- -
- - - -
\ No newline at end of file +
+ + Forgot your password? + + + + + diff --git a/modules/base/templates/users_change_password.tpl b/modules/base/templates/users_change_password.tpl index 1b72414e6..1367de9b3 100644 --- a/modules/base/templates/users_change_password.tpl +++ b/modules/base/templates/users_change_password.tpl @@ -1,36 +1,35 @@ - - -
- -
-
- -
- Password Setup - - +
+
Password Setup

+
Enter your new password below.

+
+ + + + + + -
- - - - - - - - - - - - - - -
New Password
Re-type your Password
- - -
- -
- -
-
\ No newline at end of file +
+ +
+
+
New Password
+

+
Re-type your Password
+

+ + + +
+
+
+ + + + + + + + + + diff --git a/modules/base/templates/users_password_reset_request.tpl b/modules/base/templates/users_password_reset_request.tpl index 2a1f0c468..f7383adbd 100644 --- a/modules/base/templates/users_password_reset_request.tpl +++ b/modules/base/templates/users_password_reset_request.tpl @@ -1,29 +1,49 @@ +
+
Password Reset

+
Enter the e-mail address associated with your account.

+
+ + + + + + + +
+ +
+
+
E-mail address:
+ + + + + + +

+ + + + + + +
+
+ +
+ + + + + + + +
- -

- -
-
- -
- Password Request Form - - - - - - - - - - -
Your E-mail Address:
- - -
- -
- -
-
\ No newline at end of file +
+ + + +
+ diff --git a/modules/base/templates/users_reset_password_email.tpl b/modules/base/templates/users_reset_password_email.tpl index 7eb5a50f1..8af4f8920 100644 --- a/modules/base/templates/users_reset_password_email.tpl +++ b/modules/base/templates/users_reset_password_email.tpl @@ -3,4 +3,4 @@ Someone, hopefully you, has requested a reset of your Open Web Analytics account If this message was generated in error, please disregard. If not, please click on the link below to complete the process. -makeAbsoluteLink(array('view' => 'base.usersChangePassword', 'k' => $key)); +makeAbsoluteLink(array('do' => 'base.usersPasswordEntry', 'k' => $key)); diff --git a/modules/base/templates/wrapper_public.tpl b/modules/base/templates/wrapper_public.tpl index 19fec8591..d786b0938 100644 --- a/modules/base/templates/wrapper_public.tpl +++ b/modules/base/templates/wrapper_public.tpl @@ -3,39 +3,31 @@ - Open Web Analytics - <?=$page_title;?> + <?=$page_title;?> - Open Web Analytics setTemplate('css.tpl'));?> -