public function save(Application_Model_User $user) { $password = sha1($user->getPassword()); $data = array('confirmed' => $user->getConfirmed(), 'created' => $user->getCreated(), 'email' => $user->getEmail(), 'id' => $user->getId(), 'name' => $user->getName(), 'password' => $password); if (null === ($id = $user->getId())) { unset($data['id']); return $this->getDbTable()->insert($data); } else { $this->getDbTable()->update($data, array('id = ?' => $id)); } }
/** * Still playing around with how I want to handle permissions. * This is a method that can be called before each action to * see if the user can do what they are asking to. * * @access public * @return void */ protected function userCan() { // User can edit themselves if ($this->id == $this->user->getId()) { return true; } // TODO: Need to expand upon this? Probably... // we can add in what the user is trying to do, and check perms // on top of just ownership. This will do for now. if ($this->id) { if ($this->user->isParentOf($this->id) || $this->user->isSuperAdmin()) { return true; } } else { // If there was no id already set, we are probably adding a folder. // TODO: Need to handle perms somehow here. return true; } // Set this entity to not valid so we do not give anything away // TODO: Maybe make a default() method that we can reset a built entity to it's defaults. // defaults could be set from the entity profile. $this->valid = false; $this->error = 'User does not have permission to execute the request.'; //$this->error = 'ID does not exist for this user.'; return false; }
/** * Checks whether this contest ready to be saved. * * @access protected * @return boolean */ protected function _isValid() { if ($this->_user instanceof Application_Model_User) { if ($this->_user->getId()) { if ($this->_user->canCreateContest()) { if ($this->name) { if ($this->startdate && $this->enddate || $this->type == 3) { if ($this->type) { if ($this->already_played_msg && $this->before_contest_msg && $this->after_contest_msg) { return true; } else { $this->setError('A contest requires a messages for before the contest, after the contest and already played subscibers.'); } } else { $this->setError('A contest type must be selected.'); } } else { $this->setError('You must enter a start and end date for this contest to run.'); } } else { $this->setError('You must name the contest.'); } } else { $this->setError('User can not create Contests, upgrade to a Premium user for this feature.'); } } else { $this->setError('Invalid user'); } } else { $this->setError('A user must be supplied to create a contest'); } return false; }
public function loginAction() { if (Zend_Auth::getInstance()->hasIdentity()) { return $this->_redirect('/'); } // process the form $form = new Application_Form_Login(); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { // check if the user exists $user_mapper = new Application_Model_UserMapper(); $qry = "\n SElECT *\n FROM user\n WHERE username = :credential\n OR email = :credential"; $params = array('credential' => $form->getValue('credential')); $user = $user_mapper->query($qry, $params); if ($user) { $user = new Application_Model_User($user[0]); // if the account is not active, prompt the user to activate the account if (!$user->getActive()) { $this->_helper->FlashMessenger('User Not Activated'); return $this->_redirect('/registration/confirm/id/' . $user->getId()); } // authenticate the user $db = Zend_Registry::get('db_default'); $credential_choice = $params['credential'] == $user->getUsername() ? 'username' : 'email'; $adapter = new Zend_Auth_Adapter_DbTable($db, 'user', $credential_choice, 'password_hash'); $adapter->setIdentity($form->getValue('credential')); $adapter->setCredential(hash('sha256', $user->getPassword_salt() . $form->getValue('password'))); $zend_auth = Zend_Auth::getInstance(); $result = $zend_auth->authenticate($adapter); if ($result->isValid()) { // store session information in database $session_mapper = new Application_Model_SessionMapper(); $session = new Application_Model_Session(array('user_id' => $user->getId(), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'login_timestamp' => date('Y-m-d H:i:s'))); $session_mapper->save($session); // store user information in session variable $session = new Zend_Session_Namespace('user'); $session->user = $user->get_array(); $this->_helper->FlashMessenger('Successful Login'); return $this->_redirect('/'); } else { echo "Authentication failed."; } } else { echo "Invalid username/email"; } } $this->view->form = $form; }
public function save(Application_Model_User $user) { $data = array('password' => $user->getPassword(), 'username' => $user->getUserName()); if (null === ($id = $user->getId())) { unset($data['id']); $this->getDbTable()->insert($data); } else { $this->getDbTable()->update($data, array('id = ?' => $id)); } }
/** * Saves the session * * @access public * @return boolean True on success */ public function save() { // Serialize the session data array $datastore = serialize($this->sessiondata); $userid = $this->user ? $this->user->getId() : '-1'; $sql = "call session_update('{$this->id}', '{$this->requestip}', " . $userid . ", {$this->requesttime}, '{$this->requestpage}', '{$this->requestaction}', '{$datastore}')"; $rs = $this->query($sql); if (!$this->error) { if (isset($rs->fields['success']) && $rs->fields['success'] == 1) { return true; } $this->error = 'Could not save the new session.'; } $this->error = 'There was a general error saving this session.'; return false; }
private function getValidationLink(Application_Model_User &$user) { if (getenv('APPLICATION_ENV') == 'development') { return 'http://localhost' . $this->view->baseUrl() . '/auth/confirm/id/' . $user->getId(); } else { return 'http://winsandwants.com' . $this->view->baseUrl() . '/auth/confirm/id/' . $user->getId(); } }
/** * Checks whether this keyword is a valid keyword or not... useful for * saving edits * * REQUIRED ELEMENTS: * - Keyword * - Folder id that user is parent of * - Reply body * * @access protected * @return boolean */ protected function _isValid() { if ($this->folderid) { if ($this->_user instanceof Application_Model_User && $this->_user->getId() && $this->_user->isParentOf($this->folderid)) { if ($this->replybody) { return true; } else { $this->setError('A keyword requires a auto response message'); } } else { $this->setError('Permission denied'); } } else { $this->setError('A keyword must be added to a folder'); } return false; }
public function contextMenuAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); //playlist||timeline $screen = $this->_getParam('screen'); $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); $menu = array(); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); //Open a jPlayer window and play the audio clip. $menu["play"] = array("name" => "Preview", "icon" => "play", "disabled" => false); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME); if ($type === "audioclip") { $file = Application_Model_StoredFile::Recall($id); $menu["play"]["mime"] = $file->getPropelOrm()->getDbMime(); if (isset($obj_sess->id) && $screen == "playlist") { // if the user is not admin or pm, check the creator and see if this person owns the playlist or Block if ($obj_sess->type == 'playlist') { $obj = new Application_Model_Playlist($obj_sess->id); } elseif ($obj_sess->type == 'block') { $obj = new Application_Model_Block($obj_sess->id); } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); } elseif ($obj_sess->type === "block") { $menu["pl_add"] = array("name" => "Add to Smart Block", "icon" => "add-playlist", "icon" => "copy"); } } } if ($isAdminOrPM) { $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete"); $menu["edit"] = array("name" => "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); } $url = $file->getRelativeFileUrl($baseUrl) . '/download/true'; $menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url); } elseif ($type === "playlist" || $type === "block") { if ($type === 'playlist') { $obj = new Application_Model_Playlist($id); } elseif ($type === 'block') { $obj = new Application_Model_Block($id); if (!$obj->isStatic()) { unset($menu["play"]); } if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); } } } if ($obj_sess->id !== $id && $screen == "playlist") { if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { $menu["edit"] = array("name" => "Edit", "icon" => "edit"); } } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete"); } } elseif ($type == "stream") { $webstream = CcWebstreamQuery::create()->findPK($id); $obj = new Application_Model_Webstream($webstream); if (isset($obj_sess->id) && $screen == "playlist") { if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($obj_sess->type === "playlist") { $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); } } } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($screen == "playlist") { $menu["edit"] = array("name" => "Edit", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); } $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete"); } } //SOUNDCLOUD MENU OPTIONS if ($type === "audioclip" && Application_Model_Preference::GetUploadToSoundcloudOption()) { //create a menu separator $menu["sep1"] = "-----------"; //create a sub menu for Soundcloud actions. $menu["soundcloud"] = array("name" => "Soundcloud", "icon" => "soundcloud", "items" => array()); $scid = $file->getSoundCloudId(); if ($scid > 0) { $url = $file->getSoundCloudLinkToFile(); $menu["soundcloud"]["items"]["view"] = array("name" => "View on Soundcloud", "icon" => "soundcloud", "url" => $url); } if (!is_null($scid)) { $text = "Re-upload to SoundCloud"; } else { $text = "Upload to SoundCloud"; } $menu["soundcloud"]["items"]["upload"] = array("name" => $text, "icon" => "soundcloud", "url" => "/library/upload-file-soundcloud/id/{$id}"); } if (empty($menu)) { $menu["noaction"] = array("name" => "No action available"); } $this->view->items = $menu; }
/** * Delete stored virtual file * * @param boolean $p_deleteFile * */ public function delete() { $filepath = $this->getFilePath(); // Check if the file is scheduled to be played in the future if (Application_Model_Schedule::IsFileScheduledInTheFuture($this->getId())) { throw new DeleteScheduledFileException(); } $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new Application_Model_User($userInfo->id); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); if (!$isAdminOrPM && $this->getFileOwnerId() != $user->getId()) { throw new FileNoPermissionException(); } $music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory()); $type = $music_dir->getType(); if (file_exists($filepath) && $type == "stor") { $data = array("filepath" => $filepath, "delete" => 1); try { Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data); } catch (Exception $e) { Logging::error($e->getMessage()); return; } } // set hidden flag to true $this->_file->setDbHidden(true); $this->_file->save(); // need to explicitly update any playlist's and block's length // that contains the file getting deleted $fileId = $this->_file->getDbId(); $plRows = CcPlaylistcontentsQuery::create()->filterByDbFileId()->find(); foreach ($plRows as $row) { $pl = CcPlaylistQuery::create()->filterByDbId($row->getDbPlaylistId($fileId))->findOne(); $pl->setDbLength($pl->computeDbLength(Propel::getConnection(CcPlaylistPeer::DATABASE_NAME))); $pl->save(); } $blRows = CcBlockcontentsQuery::create()->filterByDbFileId($fileId)->find(); foreach ($blRows as $row) { $bl = CcBlockQuery::create()->filterByDbId($row->getDbBlockId())->findOne(); $bl->setDbLength($bl->computeDbLength(Propel::getConnection(CcBlockPeer::DATABASE_NAME))); $bl->save(); } }