/** * undocumented function * * @return void * @access public */ static function generate($key = array(), $autoRefresh = true) { if (Common::isUuid($key)) { $key = array('user_id' => $key); } elseif (!isset($key['user_id'])) { $key['user_id'] = User::get('id'); } // to support emails, too // Assert::true(Common::isUuid($key['user_id'])); $_this = Common::getModel('AuthKey'); if (!Common::isUuid($key['auth_key_type_id']) && !empty($key['auth_key_type_id'])) { $key['auth_key_type_id'] = $_this->AuthKeyType->lookup($key['auth_key_type_id']); } Assert::true(Common::isUuid($key['auth_key_type_id'])); $recursive = -1; $sameTypeKey = $_this->find('first', array('conditions' => array('user_id' => $key['user_id'], 'auth_key_type_id' => $key['auth_key_type_id']), 'recursive' => -1)); if ($sameTypeKey) { if (!$autoRefresh) { return false; } $key['id'] = $sameTypeKey['AuthKey']['id']; } do { $key['key'] = Security::generateAuthKey(); } while (!$_this->isUnique(array('key' => $key['key']))); Assert::notEmpty($key['key']); $_this->create(); Assert::notEmpty($_this->save($key)); return $key['key']; }
/** * undocumented function * * @param string $id * @return void * @access public */ function edit($id = null, $parentId = null) { $action = 'add'; if ($this->action == 'edit') { $Comment = $this->Comment->find('first', array('conditions' => array('Comment.id' => $id))); Assert::notEmpty($Comment, '404'); Assert::true($this->Comment->isOwn($Comment, 'Comment'), '403'); $action = 'edit'; } else { $Comment = $this->Comment->create(); } $referer = $this->referer(); $parentId = isset($this->params['named']['parent_id']) ? $this->params['named']['parent_id'] : false; $foreignId = isset($this->params['named']['foreign_id']) ? $this->params['named']['foreign_id'] : false; $this->set(compact('action', 'referer', 'parentId', 'foreignId')); $this->action = 'edit'; if ($this->isGet()) { return $this->data = $Comment; } $this->data['Comment']['user_id'] = User::get('id'); $this->Comment->set($this->data); $result = $this->Comment->save(); if ($this->Comment->validationErrors) { $msg = __('There are problems with the form.', true); $this->Message->add($msg, 'error', true, $referer); } Assert::notEmpty($result); $msg = __('Successfully saved!', true); $this->Message->add($msg, 'ok', true, $this->data['Comment']['referer']); }
/** * undocumented function * * @param string $id * @return void * @access public */ function admin_delete($id) { $smiley = $this->Smiley->find('first', array('conditions' => array('Smiley.id' => $id), 'contain' => false, 'fields' => array('id'))); Assert::notEmpty($smiley, '404'); $this->Smiley->del($id); $msg = __('Smiley deleted.', true); $this->Message->add($msg, 'ok', true, $this->referer()); }
/** * undocumented function * * @param string $id * @return void * @access public */ function admin_delete($id) { $filter = $this->Filter->find('first', array('conditions' => array('Filter.id' => $id), 'contain' => false, 'fields' => array('id', 'user_id'))); Assert::notEmpty($filter, '404'); Assert::true(AppModel::isOwn($filter, 'Filter'), '403'); $this->Filter->del($id); $msg = __('Filter deleted.', true); $this->Message->add($msg, 'ok', true, $this->referer()); }
/** * undocumented function * * @return void * @access public */ function admin_delete($id) { $role = $this->Role->findById($id); Assert::notEmpty($role, '404'); Assert::false(in_array($role['Role']['name'], $this->Role->unEditable), '403'); $this->Role->del($id); $msg = __('Role was successfully removed.', true); $this->Message->add($msg, 'ok', true, array('action' => 'admin_index')); }
/** * undocumented function * * @return void * @access public */ function beforeFilter() { if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { Assert::false($this->name == 'App', '404'); Assert::true(!!$this->action, '404'); } $this->Session = $this->AppSession; ClassRegistry::addObject('Component.Session', $this->Session); ClassRegistry::addObject('Component.RequestHandler', $this->RequestHandler); ClassRegistry::addObject('Component.Cookie', $this->Cookie); ClassRegistry::addObject('Component.Email', $this->Email); ClassRegistry::addObject('Component.Pgp', $this->Pgp); $this->_loadPermissions(); $this->_setLanguage(); $this->_loadPluginConfigs(); if ($this->isAdmin()) { $this->layout = 'admin'; } if (defined('CAKEPHP_UNIT_TEST_EXECUTION')) { return; } $this->RequestHandler->setContent('list', 'text/html'); if (empty($this->ignoreUserSession)) { $rules = Configure::read('App.userPermissions.' . User::get('Role.name')); Assert::notEmpty($rules, '500'); $canAccess = Common::requestAllowed($this->name, $this->action, $rules, true); if (!$canAccess) { Assert::true(User::is('guest'), '403'); if ($this->isOkForSessionRedirect()) { $this->Session->write($this->loginRedirectSesskey, $this->here); } $this->Session->write('cant_access', true); return $this->redirect('/admin/auth/login', '403', true); } if (!User::is('guest') && $this->name == 'auth' && $this->action == 'login') { $url = '/admin/home'; if ($this->Session->check($this->loginRedirectSesskey)) { $url = $this->Session->read($this->loginRedirectSesskey); } $this->redirect($url); } } $here = $this->params['url']['url']; if (!empty($here) && $here[0] != '/') { $here = '/' . $here; } $this->setJson('here', $here); $ajax = $isAjax = false; if ($this->isAjax()) { $this->layout = 'ajax'; $ajax = $isAjax = true; } $this->set(compact('ajax', 'isAjax', 'here')); }
/** * undocumented function * * @param unknown $format * @param unknown $timeZone * @param unknown $when * @return void * @access public */ static function date($format, $timeZone, $when = 'now') { try { $DateTimeZone = new DateTimeZone($timeZone); $DateTime = new DateTime($when, $DateTimeZone); $date = $DateTime->format($format); } catch (Exception $Exception) { throw new AppException($Exception->getMessage()); } Assert::notEmpty($date); return $date; }
/** * undocumented function * * @param string $id * @return void * @access public */ function admin_edit($id = null) { $settings = $this->Setting->find('first'); Assert::notEmpty($settings, '404'); if ($this->isGet()) { return $this->data = $settings; } $this->Setting->set($this->data); if (!$this->Setting->save()) { $msg = __('The settings could not be updated.', true); return $this->Message->add($msg, 'error'); } $msg = __('The settings were saved', true); $this->Message->add($msg, 'ok'); }
function updatePassword($uid, $password) { Assert::isId($uid); Assert::notEmpty($password); return query("update user set password = '******', changepw = 1 where uid = {$uid}"); }
/** * delete action * * @param string $id the transaction id * @return void * @access public */ function admin_delete($id = null) { $transaction = $this->Transaction->find('first', array('conditions' => array('Transaction.id' => $id), 'contain' => array('Gift'))); Assert::notEmpty($transaction, '404'); Assert::true(User::allowed($this->name, $this->action, $transaction), '403'); $this->Transaction->set(array('id' => $id, 'archived' => '1')); $this->Transaction->save(); $msg = __('The Transaction has been deleted.', true); $this->Message->add($msg, 'ok', true, array('action' => 'admin_index')); }
/** * undocumented function * * @param string $id * @return void * @access public */ function admin_view($id = null) { $gift = $this->Gift->find('first', array('conditions' => array('Gift.id' => $id), 'contain' => array('Contact.Address.Phone', 'Contact.Address.Country(id, name)', 'Contact.Address.State(id, name)', 'Contact.Address.City(id, name)', 'GiftType(humanized)', 'Office(id, name)', 'Appeal', 'Frequency', 'Currency(iso_code)'))); Assert::notEmpty($gift, '404'); Assert::true(User::allowed($this->name, $this->action, $gift), '403'); $this->paginate['Transaction'] = array('conditions' => array('Transaction.gift_id' => $id), 'contain' => array('Gateway(name)', 'Currency(iso_code)'), 'order' => array('Transaction.created' => 'asc')); $transactions = $this->paginate('Transaction'); $this->Gift = ClassRegistry::init('Gift'); $commentMethod = $this->Gift->hasMany['Comment']['threaded'] ? 'threaded' : 'all'; $comments = $this->Gift->Comment->find($commentMethod, array('conditions' => array('Comment.foreign_id' => $id), 'contain' => array('User(login, id)'))); $this->set(compact('gift', 'comments', 'commentMethod', 'transactions')); }
/** * undocumented function * * @return void * @access public */ static function guestLogin() { $_this = ClassRegistry::init(__CLASS__); $backup = $_this->data; $_this->id = $_this->lookup(array('login' => Configure::read('App.emails.guestAccount')), 'id', false); if (empty($_this->id)) { $_this->create(array('login' => Configure::read('App.emails.guestAccount'), 'level' => 'guest')); Assert::notEmpty($_this->save(), 'no_guest_account'); } User::setActive($_this->id, true); $_this->set($backup); return true; }
/** * delete action * * @param string $id the office id * @return void * @access public */ function admin_delete($id = null, $undelete = false) { $office = $this->Office->find('first', array('conditions' => compact('id'), 'contain' => array('User', 'Gift'))); Assert::notEmpty($office, '404'); $noUsers = empty($office['User']); $noGifts = empty($office['Gift']); $url = array('action' => 'index'); if (!$noGifts || !$noUsers) { $msg = __('Sorry, but there are still users, transactions or gifts related to this office.', true); $this->Message->add($msg, 'error', true, $url); } $this->Office->del($id); $msg = __('The Office has been deleted.', true); $this->Message->add($msg, 'ok', true, $url); }
/** * Admin delete an template action * * @param string $id the template id * @return void * @access public */ function admin_delete($id = null, $undelete = false) { $template = $this->Template->find('first', array('conditions' => compact('id'))); Assert::notEmpty($template, '404'); Assert::true(User::allowed($this->name, $this->action, $template), '403'); $this->Template->del($id); $msg = __('The Template has been deleted.', true); $this->Message->add($msg, 'ok', true, array('action' => 'admin_index')); }
/** * undocumented function * * @param string $segmentId * @param string $foreignId * @return void * @access public */ function admin_delete_item($segmentId, $foreignId) { $segment = $this->Segment->find('first', array('conditions' => array('id' => $segmentId), 'fields' => array('user_id'))); Assert::notEmpty($segment); Assert::true(AppModel::isOwn($segment, 'Segment'), '403'); $this->SegmentItem->deleteAll(array('segment_id' => $segmentId, 'foreign_id' => $foreignId)); $msg = 'The item was successfully removed from segment.'; $this->Message->add($msg, 'ok', true, $this->referer()); }