1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123:
<?php
namespace MvcCore\Ext\Auths\Basics\Form;
trait Base {
protected $auth = NULL;
protected $successUrlField = NULL;
protected $errorUrlField = NULL;
protected $sourceUrlField = NULL;
protected function initAuthFormPropsAndHiddenControls () {
$this->auth = \MvcCore\Ext\Auths\Basic::GetInstance();
$this->successUrlField = new \MvcCore\Ext\Forms\Fields\Hidden([
'name' => 'successUrl',
'value' => $this->auth->GetSignedInUrl(),
'validators' => ['Url'],
]);
$this->errorUrlField = new \MvcCore\Ext\Forms\Fields\Hidden([
'name' => 'errorUrl',
'value' => $this->auth->GetSignErrorUrl(),
'validators' => ['Url'],
]);
$this->sourceUrlField = new \MvcCore\Ext\Forms\Fields\Hidden([
'name' => 'sourceUrl',
'validators' => ['Url'],
]);
$this->AddFields($this->successUrlField, $this->errorUrlField, $this->sourceUrlField);
return $this;
}
public function PreDispatch ($submit = FALSE) {
if ($this->dispatchState > \MvcCore\IController::DISPATCH_STATE_INITIALIZED)
return $this;
parent::PreDispatch($submit);
if ($submit) {
$this->dispatchState = \MvcCore\IController::DISPATCH_STATE_PRE_DISPATCHED;
return $this;
}
$successUrlValue = $this->successUrlField->GetValue();
if ($successUrlValue) {
$this->auth->SetSignedInUrl(rawurlencode($successUrlValue));
$this->successUrlField->SetValue(rawurlencode($successUrlValue));
} else {
$successUrlValue = $this->auth->GetSignedInUrl();
if (!$successUrlValue)
$successUrlValue = htmlspecialchars($this->request->GetFullUrl());
$this->successUrlField->SetValue(rawurlencode($successUrlValue));
}
$errorUrlValue = $this->errorUrlField->GetValue();
if ($errorUrlValue) {
$this->auth->SetSignErrorUrl(rawurlencode($errorUrlValue));
$this->errorUrlField->SetValue(rawurlencode($errorUrlValue));
} else {
$errorUrlValue = $this->auth->GetSignErrorUrl();
if (!$errorUrlValue)
$errorUrlValue = htmlspecialchars($this->request->GetFullUrl());
$this->errorUrlField->SetValue(rawurlencode($errorUrlValue));
}
$sourceUrl = $this->request->GetParam('sourceUrl', FALSE, '', 'string');
while (preg_match("#%[0-9a-zA-Z]{2}#", $sourceUrl))
$sourceUrl = rawurldecode($sourceUrl);
$parsedSourceUrl = parse_url($sourceUrl);
if (
$parsedSourceUrl !== NULL &&
isset($parsedSourceUrl['host']) &&
$parsedSourceUrl['host'] === $this->request->GetHostName()
)
$this->sourceUrlField->SetValue(rawurlencode($sourceUrl));
return $this;
}
}