Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Controller.php « Login « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10c22914346b0262802aca242f34b6e33567ed70 (plain)
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
<?php
/**
 * Piwik - Open source web analytics
 * 
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
 * @version $Id$
 * 
 * @package Piwik_Login
 */

require_once "UsersManager/API.php";
require_once "Login/Form.php";
require_once "View.php";


/**
 * 
 * @package Piwik_Login
 */
class Piwik_Login_Controller extends Piwik_Controller
{
	function getDefaultAction()
	{
		return 'login';
	}
	
	function login( $messageNoAccess = null )
	{
		$form = new Piwik_Login_Form;
		$AccessErrorString = false;
		
		if($form->validate())
		{
			// value submitted in form
			$login = $form->getSubmitValue('form_login');
			$password = $form->getSubmitValue('form_password');
			$password = md5($password);
			
			$baseUrl = Piwik_Url::getCurrentUrlWithoutQueryString(); 
			$currentUrl = Piwik_Url::getCurrentUrl();		
			$urlToRedirect = Piwik_Common::getRequestVar('form_url', $currentUrl, 'string', $_POST);
			
			$urlToRedirect = htmlspecialchars_decode($urlToRedirect);
			
			$tokenAuth = Piwik_UsersManager_API::getTokenAuth($login, $password);
	
			Piwik_Login::prepareAuthObject($login, $tokenAuth);
			
			$auth = Zend_Registry::get('auth');
			
			if($auth->authenticate()->isValid())
			{
				$authCookieName = 'piwik-auth';
				$authCookieExpiry = time() + 3600;
				$cookie = new Piwik_Cookie($authCookieName, $authCookieExpiry);
				$cookie->set('login', $login);
				$tokenAuth = $auth->getTokenAuth();
				$cookie->set('token_auth', $tokenAuth);
				$cookie->save();
				
				Piwik_Url::redirectToUrl($urlToRedirect);
			}
			else
			{
				$messageNoAccess = _('Login_LoginPasswordNotCorrect');
			}
		}
		$view = new Piwik_View('Login/templates/login.tpl');	
		$view->AccessErrorString = $messageNoAccess;
		$view->addForm( $form );
		$view->subTemplate = 'genericForm.tpl';
		echo $view->render();
	}
	
	function logout()
	{		
		$authCookieName = 'piwik-auth';
		$cookie = new Piwik_Cookie($authCookieName);
		$cookie->delete();
		
		// after logout we redirect to the Homepage instead of the referer
		Piwik::redirectToModule('Home');
	}
	
}