commit 7f0df8f0bd48439052f40787fd69a958b6d23194
parent 964d2118f1ec159a1c9ca088b182ad651703a521
Author: Jan Dankert <develop@jandankert.de>
Date: Thu, 11 Mar 2021 00:01:47 +0100
Refactoring: Cleaned the Request params.
Diffstat:
4 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/modules/cms/Dispatcher.class.php b/modules/cms/Dispatcher.class.php
@@ -404,8 +404,8 @@ class Dispatcher
$possibleDbIds = [];
- if ( $this->request->has('dbid') )
- $possibleDbIds[] = $this->request->getAlphanum('dbid' );
+ if ( $this->request->has(RequestParams::PARAM_DATABASE_ID ) )
+ $possibleDbIds[] = $this->request->getDatabaseId();
if ( Session::getDatabaseId() )
$possibleDbIds[] = Session::getDatabaseId();
diff --git a/modules/cms/action/RequestParams.class.php b/modules/cms/action/RequestParams.class.php
@@ -4,6 +4,7 @@ namespace cms\action;
use util\exception\ValidationException;
use util\json\JSON;
+use util\Mail;
use util\Text;
use util\XML;
@@ -129,11 +130,19 @@ class RequestParams
/**
* Gets a mail adress out of the request.
*
+ * Throws a ValidationException if the mail adress is not valid.
+ *
* @param $varName
* @return String
*/
- public function getMail($varName ) {
- return Text::clean( $this->getValue($varName), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-+@' );
+ public function getValidMail($varName ) {
+
+ $adress = Text::clean( $this->getValue($varName), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-+@' );
+
+ if ( ! Mail::checkAddress( $adress ) )
+ throw new ValidationException( $varName );
+
+ return $adress;
}
@@ -222,7 +231,6 @@ class RequestParams
}
-
/**
* Ermittelt die aktuelle Id aus dem Request.<br>
* Um welche ID es sich handelt, ist abh�ngig von der Action.
@@ -239,7 +247,6 @@ class RequestParams
}
-
/**
* Checks if the parameter value is true.
*
@@ -269,9 +276,6 @@ class RequestParams
}
-
-
-
public function hasLanguageId()
{
return $this->has(self::PARAM_LANGUAGE_ID);
@@ -282,6 +286,7 @@ class RequestParams
return $this->getNumber(self::PARAM_LANGUAGE_ID);
}
+
public function hasModelId()
{
return $this->has(self::PARAM_MODEL_ID);
@@ -291,18 +296,26 @@ class RequestParams
{
return $this->getNumber(self::PARAM_MODEL_ID );
}
+
+
public function getProjectId()
{
return $this->getNumber(self::PARAM_PROJECT_ID );
}
+
+ public function getDatabaseId()
+ {
+ return $this->getAlphanum(self::PARAM_DATABASE_ID );
+ }
+
+
public function getToken()
{
return $this->getAlphanum(self::PARAM_TOKEN );
}
-
public function __toString() {
return 'Request '.$this->action.'/'.$this->method.'/'.$this->id;
}
diff --git a/modules/cms/action/login/LoginRegisterAction.class.php b/modules/cms/action/login/LoginRegisterAction.class.php
@@ -19,10 +19,7 @@ class LoginRegisterAction extends LoginAction implements Method {
public function post() {
- $email_address = $this->request->getMail('mail');
-
- if ( ! Mail::checkAddress($email_address) )
- throw new ValidationException('mail');
+ $email_address = $this->request->getValidMail('mail');
Session::set( Session::KEY_REGISTER_MAIL,$email_address );
diff --git a/modules/cms/action/project/ProjectCopyAction.class.php b/modules/cms/action/project/ProjectCopyAction.class.php
@@ -27,7 +27,7 @@ class ProjectCopyAction extends ProjectAction implements Method {
if ( $this->request->has('ok') )
{
- $this->project->export( $this->request->getNumber('dbid') );
+ $this->project->export( $this->request->getDatabaseId() );
$this->addNoticeFor($this->project,Messages::DONE);
}