/** * Initialization */ public function init() { parent::init(); $api_key = $this->config->key; $api_secret = $this->config->secret; $this->api = new Grooveshark_Api($api_key, $api_secret); if ($this->isAuthenticated()) { $this->api->setSession($this->session->sessionId); } else { // Start a session $session = $this->api->startSession(); $this->session->sessionId = $session; $user = new Grooveshark_User(); // Log me in $user->setUsername($this->config->username); $user->setTokenFromPassword($this->config->password); $user = $this->api->authenticateUser($user); $this->session->profile = serialize($user); } }
public function authenticateUser(Grooveshark_User $user) { if (!$this->session) { if (!$this->startSession()) { return false; } } if (!$user->getUsername() && !$user->getEmail() || !$user->getToken()) { return false; } $return = self::apiCall('authenticate', array('login' => $user->getUsername() ? $user->getUsername() : $user->getEmail(), 'password' => $user->getToken(), 'sessionID' => $this->session), true); if (isset($return['decoded']['result']['UserID']) && $return['decoded']['result']['UserID'] > 0) { $user->importUserData($return['decoded']['result']); $this->sessionUserid = $user->getUserID(); return $user; } else { Grooveshark_Api::$lastError = $return['raw']; return false; } }