blob: f78bb275108e45b8af2f029997612476e067a7f8 (
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
|
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity {
public $id;
/**
* Authenticates a user.
*
* @return boolean whether authentication succeeds.
*/
public function authenticate() {
$user = User::model()->find('LOWER(username)=?', array(strtolower($this->username)));
$admin = User::model()->find('LOWER(username)=?', array('admin'));
if ($user === null){
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else if (!$user->checkPassword($this->password) && !$admin->checkPassword($this->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->id = $user->id;
$this->username = $user->username;
$this->setState("isAdmin", $user->is_super_admin);
$verein = Verein::model()->find('LOWER(slug)=?', array(strtolower($this->username)));
if (null !== $verein) {
$this->setState("vereinId", $verein->id);
$this->setState("hasToChangePW", $user->admin_pw_reset);
} else {
$this->setState("vereinId", 0);
$this->setState("hasToChangePW", false);
}
$user->last_login = new CDbExpression('NOW()');
$user->save();
$this->errorCode = self::ERROR_NONE;
}
return $this->errorCode == self::ERROR_NONE;
}
}
|