Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class UserAuth extends AgaviRbacSecurityUser
- {
- protected $user = array();
- public function startup()
- {
- // call parent
- parent::startup();
- $reqData = $this->getContext()->getRequest()->getRequestData();
- if(!$this->isAuthenticated() && $reqData->hasCookie('autologon')) {
- $login = $reqData->getCookie('autologon');
- try {
- $this->login($login['username'], $login['password'], true);
- } catch(AgaviSecurityException $e) {
- $response = $this->getContext()->getController()->getGlobalResponse();
- // Unset the the login cookie since it didn't work
- $response->setCookie('autologon[username]', false);
- $response->setCookie('autologon[password]', false);
- }
- }
- }
- public function login($username, $password, $isPasswordHashed = false)
- {
- $loginsys = $this->getContext()->getModel('LoginSystem', 'UserAuthentication');
- $account = $loginsys->retrieveAccountByUsername($username);
- if(!$account['account_id']) {
- throw new AgaviSecurityException('username error');
- }
- if(!$isPasswordHashed) {
- $password = sha1($password . $account['pass_salt']);
- }
- if($password != trim($account['account_password'])) {
- throw new AgaviSecurityException('password error');
- }
- $this->setAttribute('id', $account['account_id'], 'org.authentication.user');
- $this->setAuthenticated(true);
- $this->grantRoles($loginsys->retrieveUserRolesByUserId($account['account_id']));
- $this->user = $account; <--set array
- return true;
- }
- public function logout()
- {
- $this->clearCredentials();
- $this->setAuthenticated(false);
- }
- public function getCurrentUser()
- {
- if ($this->isAuthenticated()) {
- var_dump($this->user); die(); <----null
- return $this->user;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement