summaryrefslogtreecommitdiffstats
path: root/apps/admin/lib/myLoginValidator.php
blob: 03890aaee74059b004fc7fa9f4c3b3be04116818 (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
<?php

class myLoginValidator extends sfValidator
{
	public function initialize($context, $parameters = null)
	{
		// initialize parent
		parent::initialize($context);

		// set defaults
		$this->setParameter('login_error', 'Invalid input');

		$this->getParameterHolder()->add($parameters);

		return true;
	}
	
	public function execute(&$value, &$error)
	{
		$password_param = $this->getParameter('password');
		$password = $this->getContext()->getRequest()->getParameter($password_param);

		$login = $value;

		$c = new Criteria();
		$c->add(UserPeer::NICKNAME, $login);
		$user = UserPeer::doSelectOne($c);

		// nickname exists?
		if ($user)
		{
			// password is OK?
			if (sha1($user->getSalt().$password) == $user->getSha1Password())
			{
				$this->getContext()->getUser()->signIn($user);
				return true;
			}
		}

		$error = $this->getParameter('login_error');
		return false;
	}
}

?>