-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RTM] Allow to disable input encoding for a whole dca #708
Changes from 2 commits
bed0d26
68116ce
fd2ef3f
5098055
31732f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
namespace Contao; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy; | ||
|
||
|
||
|
@@ -320,6 +321,8 @@ public function authenticate() | |
*/ | ||
public function login() | ||
{ | ||
/** @var Request $request */ | ||
$request = System::getContainer()->get('request_stack')->getCurrentRequest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a behavior change, shouldn't we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's almost always wrong to take the master request. The use cases are only very, very limited. So no: the current request is the way to go. |
||
\System::loadLanguageFile('default'); | ||
|
||
// Do not continue if username or password are missing | ||
|
@@ -339,7 +342,7 @@ public function login() | |
foreach ($GLOBALS['TL_HOOKS']['importUser'] as $callback) | ||
{ | ||
$this->import($callback[0], 'objImport', true); | ||
$blnLoaded = $this->objImport->{$callback[1]}(\Input::post('username', true), \Input::postUnsafeRaw('password'), $this->strTable); | ||
$blnLoaded = $this->objImport->{$callback[1]}(\Input::post('username', true), $request->request->get('password'), $this->strTable); | ||
|
||
// Load successfull | ||
if ($blnLoaded === true) | ||
|
@@ -399,17 +402,17 @@ public function login() | |
// The password has been generated with crypt() | ||
if (\Encryption::test($this->password)) | ||
{ | ||
$blnAuthenticated = \Encryption::verify(\Input::postUnsafeRaw('password'), $this->password); | ||
$blnAuthenticated = \Encryption::verify($request->request->get('password'), $this->password); | ||
} | ||
else | ||
{ | ||
list($strPassword, $strSalt) = explode(':', $this->password); | ||
$blnAuthenticated = ($strSalt == '') ? ($strPassword === sha1(\Input::postUnsafeRaw('password'))) : ($strPassword === sha1($strSalt . \Input::postUnsafeRaw('password'))); | ||
$blnAuthenticated = ($strSalt == '') ? ($strPassword === sha1($request->request->get('password'))) : ($strPassword === sha1($strSalt . $request->request->get('password'))); | ||
|
||
// Store a SHA-512 encrpyted version of the password | ||
if ($blnAuthenticated) | ||
{ | ||
$this->password = \Encryption::hash(\Input::postUnsafeRaw('password')); | ||
$this->password = \Encryption::hash($request->request->get('password')); | ||
} | ||
} | ||
|
||
|
@@ -419,7 +422,7 @@ public function login() | |
foreach ($GLOBALS['TL_HOOKS']['checkCredentials'] as $callback) | ||
{ | ||
$this->import($callback[0], 'objAuth', true); | ||
$blnAuthenticated = $this->objAuth->{$callback[1]}(\Input::post('username', true), \Input::postUnsafeRaw('password'), $this); | ||
$blnAuthenticated = $this->objAuth->{$callback[1]}(\Input::post('username', true), $request->request->get('password'), $this); | ||
|
||
// Authentication successfull | ||
if ($blnAuthenticated === true) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
use Doctrine\DBAL\Types\Type; | ||
use Patchwork\Utf8; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
|
||
/** | ||
|
@@ -83,6 +84,7 @@ | |
* @property string $slabel The submit button label | ||
* @property boolean $preserveTags Preserve HTML tags | ||
* @property boolean $decodeEntities Decode HTML entities | ||
* @property boolean useRawRequestData Use the raw request data from the Symfony request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jop! Added in 31732f9. |
||
* @property integer $minlength The minimum length | ||
* @property integer $maxlength The maximum length | ||
* @property integer $minval The minimum value | ||
|
@@ -263,6 +265,22 @@ public function __set($strKey, $varValue) | |
$this->strPrefix = $varValue; | ||
break; | ||
|
||
case 'useRawRequestData': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you have declared the property as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah not all attributes do unfortunately. So it's inconsistent already anyway but I added it. |
||
if ($varValue === true) | ||
{ | ||
/** @var Request $request */ | ||
$request = \System::getContainer()->get('request_stack')->getCurrentRequest(); | ||
$this->setInputCallback(function() use ($request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could (but don't have to) simplify this: $this->setInputCallback(function () {
return \System::getContainer()->get('request_stack')->getCurrentRequest()->request->get($this->name);
}); |
||
return $request->request->get($this->name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. If you want the raw request data you need to handle the array yourself if you need to, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea where this array syntax is needed, maybe @aschempp can help us here? See Widget.php:781 |
||
}); | ||
} | ||
else | ||
{ | ||
$this->setInputCallback(null); | ||
} | ||
|
||
break; | ||
|
||
case 'template': | ||
$this->strTemplate = $varValue; | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a
!isset($arrData['eval']['useRawRequestData'])
check here too? This would make it possible to use the raw request for the whole DCA but opt-out of it for single fields.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added in fd2ef3f.