diff options
Diffstat (limited to 'protected/components/UserIdentity.php')
| -rw-r--r-- | protected/components/UserIdentity.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/protected/components/UserIdentity.php b/protected/components/UserIdentity.php new file mode 100644 index 0000000..e506ef8 --- /dev/null +++ b/protected/components/UserIdentity.php @@ -0,0 +1,38 @@ +<?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; + public $isAdmin; + /** + * Authenticates a user. + * + * @return boolean whether authentication succeeds. + */ + public function authenticate() + { + $user = User::model()->find('LOWER(username)=?',array(strtolower($this->username))); + if ($user === null){ + $this->errorCode = self::ERROR_USERNAME_INVALID; + } else if (!$user->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); + } else { + $this->setState("vereinId", 0); + } + $this->errorCode = self::ERROR_NONE; + } + return $this->errorCode == self::ERROR_NONE; + } +}
\ No newline at end of file |
