| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Session; |
|
|
| use Exception; |
| use Piwik\Access; |
| use Piwik\Auth as AuthInterface; |
| use Piwik\AuthResult; |
| use Piwik\Piwik; |
| use Piwik\Session; |
|
|
| |
| |
| |
| class SessionInitializer |
| { |
| |
| |
| |
| |
| |
| |
| public function initSession(AuthInterface $auth) |
| { |
| $this->regenerateSessionId(); |
|
|
| $authResult = $this->doAuthenticateSession($auth); |
|
|
| if (!$authResult->wasAuthenticationSuccessful()) { |
| Piwik::postEvent('Login.authenticate.failed', array($auth->getLogin())); |
|
|
| $this->processFailedSession(); |
| } else { |
| Piwik::postEvent('Login.authenticate.successful', array($auth->getLogin())); |
|
|
| $this->processSuccessfulSession($authResult); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| protected function doAuthenticateSession(AuthInterface $auth) |
| { |
| Piwik::postEvent( |
| 'Login.authenticate', |
| array( |
| $auth->getLogin(), |
| ) |
| ); |
|
|
| return $auth->authenticate(); |
| } |
|
|
| |
| |
| |
| |
| |
| protected function processFailedSession() |
| { |
| throw new Exception(Piwik::translate('Login_LoginPasswordNotCorrect')); |
| } |
|
|
| |
| |
| |
| |
| |
| protected function processSuccessfulSession(AuthResult $authResult) |
| { |
| $sessionIdentifier = new SessionFingerprint(); |
| $sessionIdentifier->initialize($authResult->getIdentity(), $authResult->getTokenAuth(), $this->isRemembered()); |
|
|
| |
| Access::getInstance()->reloadAccess(); |
|
|
| |
| |
| |
| Piwik::postEvent('Login.authenticate.processSuccessfulSession.end', array($authResult->getIdentity())); |
| } |
|
|
| protected function regenerateSessionId() |
| { |
| Session::regenerateId(); |
| } |
|
|
| private function isRemembered() |
| { |
| $cookieParams = session_get_cookie_params(); |
| return $cookieParams['lifetime'] > 0; |
| } |
| } |
|
|