From: Nik Okuntseff Date: Wed, 21 Mar 2018 17:18:39 +0000 (+0000) Subject: Started to work on ttRegistrator class to encapsulate restration related tasks. X-Git-Tag: timetracker_1.19-1~985 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=2ccee198591bc2ad5d80b5e1076246449d9232c1;p=timetracker.git Started to work on ttRegistrator class to encapsulate restration related tasks. --- diff --git a/WEB-INF/lib/ttExportHelper.class.php b/WEB-INF/lib/ttExportHelper.class.php index 77b2db1f..375de2f3 100644 --- a/WEB-INF/lib/ttExportHelper.class.php +++ b/WEB-INF/lib/ttExportHelper.class.php @@ -360,16 +360,14 @@ class ttExportHelper { /* * Note about the utility functions below. - * We have roughly 3 groups of operations: + * We have roughly 4 groups of operations: * 1) Regular system usage for tracking time, etc. - * 2) Admin usage - used infrequently. - * 3) Export - used infrequently. - * - * TODO: we also have user registration process without initialized user. - * Perhaps we need a separate helper class for this. Think about it. + * 2) Registration process - used infrequently. + * 3) Admin usage - used infrequently. + * 4) Export - used infrequently. * * It is tempting to have a generic function to get things done for - * all situations. However, as export and admin access are one-off + * all situations. However, as registration, export and admin access are one-off * operations, while regular system usage is daily and must be efficient, * the current approach is to have SEPARATE functions for each mode. * diff --git a/WEB-INF/lib/ttRegistrator.class.php b/WEB-INF/lib/ttRegistrator.class.php new file mode 100644 index 00000000..9a650c9c --- /dev/null +++ b/WEB-INF/lib/ttRegistrator.class.php @@ -0,0 +1,83 @@ +user_name = $fields['user_name']; + $this->login = $fields['login']; + $this->password1 = $fields['password1']; + $this->password2 = $fields['password2']; + $this->email = $fields['email']; + $this->group_name = $fields['group_name']; + $this->currency = $fields['currency']; + $this->lang = $fields['lang']; + if (!$thins->lang) $this->lang = 'en'; + $this->err = $err; + + // Validate passed in parameters. + $this->validate(); + } + + function validate() { + global $i18n; + + if (!ttValidString($this->group_name, true)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name')); + if (!ttValidString($this->currency, true)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.currency')); + if (!ttValidString($this->user_name)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_name')); + if (!ttValidString($this->login)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_login')); + if (!ttValidString($this->password1)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); + if (!ttValidString($this->password2)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); + if ($this->password1 !== $this->password2) + $this->err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); + if (!ttValidEmail($this->email, true)) + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + } + + // The register function registers a user in Time Tracker. + function register() { + // TODO: work in progress. Not implemented. + } +} diff --git a/register.php b/register.php index 92e97be6..a34a78fb 100644 --- a/register.php +++ b/register.php @@ -85,16 +85,21 @@ $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_email', $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit'))); if ($request->isPost()) { - // Validate user input. - if (!ttValidString($cl_team_name, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.team_name')); - if (!ttValidString($cl_currency, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.currency')); - if (!ttValidString($cl_manager_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_name')); - if (!ttValidString($cl_manager_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.manager_login')); - if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); - if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); - if ($cl_password1 !== $cl_password2) - $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); - if (!ttValidEmail($cl_manager_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + // Create fields array for ttRegistrator instance. + $fields = array( + 'user_name' => $cl_manager_name, + 'login' => $cl_manager_login, + 'password1' => $cl_password1, + 'password2' => $cl_password2, + 'email' => $cl_manager_email, + 'group_name' => $cl_team_name, + 'currency' => $cl_currency, + 'lang' => $cl_lang); + + // Create an instance of ttRegistrator class. + import('ttRegistrator'); + $registrator = new ttRegistrator($fields, $err); + // Validation of user input occurs in ttRegistrator constructor above. if ($err->no()) { if (!ttUserHelper::getUserByLogin($cl_manager_login)) {