public function authenticate(array $credentials) { $login = $credentials['username']; $password = $this->phash($credentials['password']); $super_admin = Environment::getVariable('admin'); if ($login == $super_admin['login']) { if ($password == $super_admin['password']) { $super_admin['roles'] = array('super admin'); $super_admin['id'] = 0; $row = new DibiRow($super_admin); MokujiServiceLocator::addService('UserAuthorizator', new Admin_UserModel()); } else { throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL); } } else { try { $login_manager = Environment::getService('UserAuthenticator'); $row = $login_manager->authenticate($credentials); } catch (InvalidStateException $e) { throw new AuthenticationException("Login and password combination failed.", self::INVALID_CREDENTIAL); } } $identity = new Identity($row->id, $row->roles, $row); $identity->id = $row->id; return $identity; }
public function authenticate(array $credentials) { $login = $credentials['username']; $password = $credentials['password']; $row = db::select('*')->from('[:table:]')->where('login = %s', $login)->fetch(); if (!$row) { throw new AuthenticationException("Login and password combination failed.", self::IDENTITY_NOT_FOUND); } if ($row->password !== $password) { throw new AuthenticationException("Login and password combination failed.", self::INVALID_CREDENTIAL); } $row->roles = array($row->group); $allowed = $this->getAllowedActions($row->group); $permissions = array(); foreach ($allowed as $record) { $permissions[$record->privilege][] = $record->resource; } $row->permissions = $permissions; MokujiServiceLocator::addService('UserAuthorizator', new UsersModuleModel()); return $row; }