public function beforeFind($queryData) { $res = parent::beforeFind($queryData); /* if(AuthComponent::user('id') == 1) { return $queryData; } */ App::import('Model', 'CakeSession'); $session = new CakeSession(); $userAvailableTags = $session->read('Rights.UserAvailablesTags'); $userForbiddenTags = $session->read('Rights.UserForbiddenTags'); $userAvailableAlbums = $session->read('Rights.UserAvailablesAlbums'); $userForbiddenAlbums = $session->read('Rights.UserForbiddenAlbums'); if (count($userForbiddenAlbums) != 0) { // $queryData['conditions']['Image.album'] = 'not in ('.implode(',', $userForbiddenAlbums).')'; } /* App::import('Model', 'ImageTag'); $imageTag = new ImageTag(); $subSqlQuery = $imageTag->find('sql', array('fields'=>'imageid','conditions'=>'tagid not in ('.implode(',', $userForbiddenTags).')')); */ if (count($userForbiddenTags) != 0) { // $subSqlQuery = 'SELECT imageid from ImageTags where tagid not in ('.implode(',', $userForbiddenTags).')'; // $queryData['conditions']['Image.id'] = 'not in ('.$subSqlQuery.')'; } // debug($queryData); return $queryData; }
/** * Checks to see if there is already a logged in session */ public function __construct() { if (CakeSession::check('auth') && CakeSession::read('auth') == TRUE) { $this->status = TRUE; $this->admin_user = CakeSession::read('admin_user'); } }
/** * */ public function order() { $countries = array("Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Barbuda", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Trty.", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Caicos Islands", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Futuna Islands", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard", "Herzegovina", "Holy See", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Jan Mayen Islands", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea", "Korea (Democratic)", "Kuwait", "Kyrgyzstan", "Lao", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "McDonald Islands", "Mexico", "Micronesia", "Miquelon", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "Nevis", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Principe", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre", "Saint Vincent", "Samoa", "San Marino", "Sao Tome", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia", "South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Grenadines", "Timor-Leste", "Tobago", "Togo", "Tokelau", "Tonga", "Trinidad", "Tunisia", "Turkey", "Turkmenistan", "Turks Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "US Minor Outlying Islands", "Uzbekistan", "Vanuatu", "Vatican City State", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (US)", "Wallis", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"); $captcha = $this->Session->read('captcha_code'); if ($this->request->is('post')) { if (!empty($this->request->data['Order'])) { if ($captcha == $this->request->data['Order']['captcha']) { $order_details = $this->request->data['Order']; $order_details['order_item_count'] = $this->Cart->getCount(); $order_details['total'] = CakeSession::read('total'); $order_details['user_id'] = $this->Auth->user('id'); $order_details['country'] = $countries[$order_details['country']]; if (!$this->Order->save($order_details)) { $this->Session->setFlash('Something went wrong, please try again!'); } $foreign_key = $this->Order->getLastInsertID(); $this->OrderItem->updateAll(array('OrderItem.order_id' => $foreign_key), array('OrderItem.session_id' => CakeSession::id())); $order = $this->OrderItem->find('all', array('conditions' => array('OrderItem.session_id' => CakeSession::id()))); $this->Session->write('order', $order); $filename = date('Y-m-d H.i.s'); $this->createPdf($filename); $email = $order_details['email']; $this->sendBill($order, $email, $filename); //ez töröl mindent, de nekem csak a kosarat kell, a user cuccokat nem (ne jelentkeztessen ki) CakeSession::destroy(); $this->view = 'success'; } else { $this->Session->setFlash(__('Captcha code does not match')); $this->redirect(array('action' => 'checkOut')); } } } }
function add() { $marketing_adv = $this->AdvertisingLink->find('list', array('fields' => 'id,description', 'conditions' => array('AdvertisingLink.marketing_channels_id' => (int) Configure::read('Settings.Company.DefaultChannel'), 'AdvertisingLink.history_status' => 1), 'recursive' => -1, 'permissionable' => false)); $this->set('files', array()); $this->set('advertisingLinks', $marketing_adv); $this->set('affiliates', $this->Affiliate->find('list', array('fields' => 'id,name', 'joins' => array(array('table' => 'users_groups', 'alias' => 'UsersGroup', 'type' => 'LEFT', 'conditions' => array('UsersGroup.user_id = Affiliate.id'))), 'conditions' => array('UsersGroup.group_id' => (int) Configure::read('Settings.Company.AffiliateGroupId'), 'Affiliate.active' => 1)))); if ($this->request->is('post') || $this->request->is('put')) { $this->request->data['Enquiry']['enq_date'] = sqlFormatDate($this->request->data['Enquiry']['enq_date']); $this->request->data['Enquiry']['enquiry_time'] = gmdate('Y-m-d H:i:s'); $this->Captcha = $this->Components->load('Captcha'); $this->Enquiry->setCaptcha($this->Captcha->getVerCode()); if (isset($this->request->data['Enquiry']['files'])) { $dataImage = $this->request->data['Enquiry']['files']; $this->request->data['Enquiry']['file_list'] = json_encode($dataImage); } else { $this->request->data['Enquiry']['file_list'] = null; } $this->Enquiry->create(); $this->request->data['Enquiry']['agent_id'] = CakeSession::read("Auth.User.id"); //print_r( $this->request->data );die; if ($this->Enquiry->save($this->request->data)) { $this->Session->setFlash(__('Enquiry has been saved')); return $this->redirect(array('action' => 'index')); } } $this->render('edit'); }
protected function _getSite($siteId = null) { $Site = ClassRegistry::init('Sites.Site'); $SiteDomain = $Site->SiteDomain; $SiteMeta = $Site->SiteMeta; $siteDomainTable = $SiteDomain->getDataSource()->fullTableName($SiteDomain, true, true); $siteMetaTable = $Site->SiteMeta->getDataSource()->fullTableName($SiteMeta, true, true); $options = array('recursive' => false, 'fields' => array('Site.id', 'Site.title', 'Site.tagline', 'Site.theme', 'Site.timezone', 'Site.locale', 'Site.status', 'SiteMeta.robots', 'SiteMeta.keywords', 'SiteMeta.description'), 'joins' => array(array('table' => $siteDomainTable, 'alias' => 'SiteDomain', 'conditions' => array('SiteDomain.site_id = Site.id'))), array('table' => $siteMetaTable, 'alias' => 'SiteMeta', 'conditions' => array('SiteMeta.site_id = Site.id'))); $host = env('HTTP_HOST'); if (empty($siteId)) { $options['joins'][0]['conditions']['SiteDomain.domain LIKE'] = '%' . $host; $options['cache'] = array('name' => 'sites_' . $host, 'config' => 'sites'); } else { $options['conditions'] = array('Site.id' => $siteId); $options['cache'] = array('name' => 'sites_' . $siteId, 'config' => 'sites'); } $site = $Site->find('first', $options); if (empty($site)) { $site = $Site->find('first', array('recursive' => false, 'fields' => array('id', 'title', 'tagline', 'theme', 'timezone', 'locale', 'status'), 'joins' => array(array('table' => $siteDomainTable, 'alias' => 'SiteDomain', 'conditions' => array('SiteDomain.site_id = Site.id'))), array('table' => $siteMetaTable, 'alias' => 'SiteMeta', 'conditions' => array('SiteMeta.site_id = Site.id')), 'conditions' => array('Site.default' => 1))); } if ($siteId === null && CakeSession::check(self::$_sessionKey) && ($active = CakeSession::read(self::$_sessionKey))) { $found = $SiteDomain->find('count', array('cache' => array('name' => 'sites_count_' . $host, 'config' => 'sites'), 'conditions' => array('SiteDomain.domain' => $host))); if ($found == 0) { $site = $active; } } return $site; }
public function beforeSave($options = array()) { // hash the password if (isset($this->data[$this->alias]['password'])) { $passwordHasher = new BlowfishPasswordHasher(); $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']); } // initially generate the url // generate default url if user_level_id is 10 or 20 in data if (isset($this->data[$this->alias]['email'])) { $this->data[$this->alias]['url'] = md5($this->data[$this->alias]['email']); } else { if (isset($this->data[$this->alias]['user_level_id']) && ($this->data[$this->alias]['user_level_id'] == 10 || $this->data[$this->alias]['user_level_id'] == 20)) { $this->data[$this->alias]['url'] = md5(AuthComponent::user('email')); } } //check if user has pre-url, prepend pre-url to url if (isset($this->data[$this->alias]['pre_url'])) { $this->data[$this->alias]['url'] = $this->data[$this->alias]['pre_url'] . "" . $this->data[$this->alias]['url']; } // check/set referral for user App::uses('CakeSession', 'Model/Datasource'); $referral_id = CakeSession::read('referral'); if (!empty($referral_id)) { $this->data[$this->alias]['referral_id'] = $referral_id; CakeSession::delete('referral'); } return true; }
/** * view * * @return void * @throws Exception */ public function view() { if (!Current::read('Block.id')) { $this->autoRender = false; return; } $isAccessed = 'block_key_' . Current::read('Block.key'); //AccessCounterFrameSettingデータ取得 $counterFrameSetting = $this->AccessCounterFrameSetting->getAccessCounterFrameSetting(true); $this->set('accessCounterFrameSetting', $counterFrameSetting['AccessCounterFrameSetting']); //AccessCounterデータ取得 $accessCounter = $this->AccessCounter->getAccessCounter(true); // カウントアップ処理 if (!$this->Session->read($isAccessed)) { try { $this->AccessCounter->updateCountUp($accessCounter); $accessCounter['AccessCounter']['count']++; // アクセス情報を記録 $this->Session->write($isAccessed, CakeSession::read('Config.userAgent')); } catch (Exception $ex) { CakeLog::error($ex); throw $ex; } } $this->set('accessCounter', $accessCounter['AccessCounter']); }
/** * retrives access token * * @param CakeRequest $request * @return mixed Either false on failure, or string the access_token facebook. */ private function _retrive_access_token(CakeRequest $request) { if ($this->access_token) { return $this->access_token; } $session_name = $this->settings['session']; if ($user = CakeSession::read($session_name)) { $this->access_token = $user->access_token; return $this->access_token; } if (!isset($request->query['code'])) { return false; } $code = $request->query['code']; $access_token = false; $url = 'https://accounts.google.com/o/oauth2/token'; $query = implode('&', array('code=' . $code, 'client_id=' . $this->settings['client_id'], 'client_secret=' . $this->settings['client_secret'], 'redirect_uri=' . urlencode($this->settings['redirect_uri']), 'grant_type=authorization_code')); $headers = array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($query)); $context = array('http' => array("method" => "POST", "header" => implode("\r\n", $headers), "content" => $query)); if ($res = @file_get_contents($url, false, stream_context_create($context))) { $params = json_decode($res); $access_token = $params->access_token; } return $access_token; }
public function afterSave($created, $options = array()) { // We need to add Activities to corresponding Feeds // -> The User who liked // -> The receiving Object $Feed = ClassRegistry::init('Social.Feed'); $user_id = CakeSession::read("Auth.User.id"); if ($created) { $feeds = array(); // We need to get if the Object's feed. $ObjectFeed = $Feed->find('first', array('conditions' => array('Feed.object_id' => $this->data['Comment']['object_id'], 'Feed.object' => $this->data['Comment']['object']))); $feeds[] = array('feed_id' => $ObjectFeed['Feed']['id']); $UserFeed = $Feed->find('first', array('conditions' => array('Feed.object_id' => $this->data['Comment']['user_id'], 'Feed.object' => 'User'))); $feeds[] = array('feed_id' => $UserFeed['Feed']['id']); // Let's add Activities to all the feeds $Activity = ClassRegistry::init('Social.Activity'); $Activity->create(); $Activity->saveAll(array('Activity' => array('object_id' => $this->data['Comment']['object_id'], 'object' => $this->data['Comment']['object'], 'subject_id' => $this->data['Comment']['user_id'], 'verb' => 'commented', 'text' => 'a commenté ', 'type' => 'comment', 'pole_id' => $this->data['Comment']['pole_id'], 'data' => json_encode(array('text' => $this->data['Comment']['content']))), 'Feed' => $feeds)); // We need to Subscribe the Author of the comment to the Object's Feed if he isn't already $Subscription = ClassRegistry::init('Social.Subscription'); $_subscription = $Subscription->find('first', array('conditions' => array('Subscription.feed_id' => $ObjectFeed['Feed']['id'], 'Subscription.user_id' => $this->data['Comment']['user_id']))); if (!count($_subscription)) { $Subscription->create(); $Subscription->save(array('Subscription' => array('feed_id' => $ObjectFeed['Feed']['id'], 'user_id' => $this->data['Comment']['user_id'], 'reason' => 'commentor'))); } } }
protected function _getCurrentUser() { App::uses('CakeSession', 'Model/Datasource'); $Session = new CakeSession(); $user_id = $Session->read('Auth.User.User.id'); return $user_id; }
protected function _fileManager() { if (CakeSession::read('Auth.User') && defined('WWW_ROOT')) { } else { return null; } }
/** * Check user is login or not and also setup user and other necessary veriable * * @param null * @return null */ private function validateLoginStatus() { $useridentity = CakeSession::read('User.identity'); if ($this->params['controller'] != 'admin_dashbords' && !in_array($this->params['action'], array('login'))) { if (empty($useridentity['User'])) { if (substr($this->params['controller'], 0, 6) == 'admin_') { $this->redirect('/admin/'); } else { //$this->redirect('/'); } } } $hasIdentity = !empty($useridentity['User']) ? true : false; $this->set('hasIdentity', $hasIdentity); $username = NULL; if (!$hasIdentity && ($this->params['controller'] != 'admin_dashbords' && $this->params['action'] != 'login')) { if (substr($this->params['controller'], 0, 6) == 'admin_') { $this->redirect('/admin/'); } else { //$this->redirect('/'); } } else { $username = ucfirst($useridentity['User']['user']); $this->set('username', $username); } if (!empty($useridentity)) { $this->useridentity->id = $useridentity['User']['id']; $this->useridentity->user = $useridentity['User']['user']; $this->useridentity->email = $useridentity['User']['email']; $this->useridentity->role_id = $useridentity['User']['role_id']; } }
/** * MISC **/ private function getUploadPath(Model $model, $path, $extension) { $path = trim($path, '/'); $replace = array(':id1000' => ceil($model->id / 1000), ':id100' => ceil($model->id / 100), ':id' => $model->id, ':y' => date('Y'), ':m' => date('m'), ':uid' => CakeSession::read('Auth.User.id'), ':md5' => md5(rand() . uniqid() . time())); $path = strtr($path, $replace) . '.' . $extension; return $path; }
private function getUserSession() { App::uses('CakeSession', 'Model/Datasource'); $Session = new CakeSession(); $user = $Session->read('UserAuth'); return $user; }
/** * This happens after a find happens. * * @param object $Model Model about to be saved. * @return boolean true if save should proceed, false otherwise * @access public */ public function afterFind($Model, $data) { // skip finds with more than one result. $skip = $Model->findQueryType == 'neighbors' || $Model->findQueryType == 'count' || empty($data) || isset($data[0][0]['count']) || isset($data[0]) && count($data) > 1 || !isset($data[0][$Model->alias][$Model->primaryKey]); if ($skip) { return $data; } if (isset($this->__settings[$Model->alias]['session_tracking']) && $this->__settings[$Model->alias]['session_tracking']) { $this->__session[$Model->alias] = CakeSession::read('Viewable.' . $Model->alias); } $user_id = AuthComponent::user('id'); $view['ViewCount'] = array('user_id' => $user_id > 0 ? $user_id : 0, 'model' => Inflector::camelize($Model->plugin) . '.' . $Model->name, 'foreign_key' => $data[0][$Model->alias][$Model->primaryKey], 'referer' => str_replace(InfinitasRouter::url('/'), '/', $Model->__referer)); $location = EventCore::trigger($this, 'GeoLocation.getLocation'); $location = current($location['getLocation']); foreach ($location as $k => $v) { $view['ViewCount'][$k] = $v; } $view['ViewCount']['year'] = date('Y'); $view['ViewCount']['month'] = date('m'); $view['ViewCount']['day'] = date('j'); $view['ViewCount']['day_of_year'] = date('z'); $view['ViewCount']['week_of_year'] = date('W'); $view['ViewCount']['hour'] = date('G'); // no leading 0 $view['ViewCount']['city'] = $view['ViewCount']['city'] ? $view['ViewCount']['city'] : 'Unknown'; /** * http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_dayofweek * sunday is 1, php uses 0 */ $view['ViewCount']['day_of_week'] = date('w') + 1; $Model->ViewCount->unBindModel(array('belongsTo' => array('GlobalCategory'))); $Model->ViewCount->create(); $Model->ViewCount->save($view); return $data; }
/** * Saves a new product credit * * @param int $market_id * @param int $presenter_sequence_id The presenter sequence id * @param int $credit_type * @param decimal $amount * @param int $user_id * @return boolean */ public function saveCredit($market_id, $presenter_sequence_id, $credit_type, $amount, $user_id) { $entry_type_id = 2; $status_type_id = 2; $ref = CakeSession::read('admin_user')->id; $entry_user = '******'; //convert presenter sequence id to primary key id require_once APPLICATION_PATH . MODEL_DIR . '/Presenter.php'; $presenter = new Presenter(); $presenter_id = $presenter->getIdBySequenceId($presenter_sequence_id); $sql = "INSERT INTO {$this->_table_name} " . "(market_id, user_id, presenter_id, product_credit_type_id, product_credit_entry_type_id, product_credit_status_type_id, entry_user, created, reference_id, amount) " . "VALUES (:market, :user, :presenter, :type, :entry, :status, :entry_user, NOW(), :ref, :amt)"; $query = $this->_db->prepare($sql); $query->bindParam(':market', $market_id); $query->bindParam(':user', $user_id); $query->bindParam(':presenter', $presenter_id); $query->bindParam(':type', $credit_type); $query->bindParam(':entry', $entry_type_id); $query->bindParam(':status', $status_type_id); $query->bindParam(':ref', $ref); $query->bindParam(':entry_user', $entry_user); $query->bindParam(':amt', $amount); if ($query->execute()) { return TRUE; } }
/** * Locking rows. * * After a row has been pulled from the database this will record the locked * state with the user that locked it. if a user reads a row that they * locked the date will be updated. if a different user tries to read this * row nothing will be retured and the component will take over displaying * an error message * * @var object $Model the current model * @var array $results the data that was found * @var bool $primary is it the main model doing the find */ public function afterFind($Model, $results, $primary) { $this->userId = class_exists('CakeSession') ? CakeSession::read('Auth.User.id') : null; if (!$this->userId || $Model->findQueryType != 'first' || !$primary || empty($results)) { if (!$this->userId || $Model->findQueryType != 'all') { return $results; } foreach ($results as $k => &$result) { $result['Lock']['Locker'] = $result['LockLocker']; unset($result['LockLocker']); } return $results; } if (isset($results[0][$Model->alias][$Model->primaryKey])) { $Lock = ClassRegistry::init('Locks.Lock'); $lock = $Lock->find('all', array('conditions' => array('Lock.foreign_key' => $results[0][$Model->alias][$Model->primaryKey], 'Lock.class' => $Model->fullModelName()), 'contain' => array('Locker'))); if (isset($lock[0]['Lock']['user_id']) && $this->userId == $lock[0]['Lock']['user_id']) { $Lock->delete($lock[0]['Lock']['id']); $lock = array(); } if (!empty($lock)) { return $lock; } $lock['Lock'] = array('foreign_key' => $results[0][$Model->alias][$Model->primaryKey], 'class' => $Model->fullModelName(), 'user_id' => $this->userId); $Lock->create(); $Lock->save($lock); } return $results; }
public function flash($key = 'flash', $attrs = array()) { $out = false; if (CakeSession::check('Message.' . $key)) { $flash = CakeSession::read('Message.' . $key); $message = $flash['message']; unset($flash['message']); if (!empty($attrs)) { $flash = array_merge($flash, $attrs); } if ($flash['element'] === 'default') { $class = 'success'; if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } $out = '<div id="' . $key . 'Message" class="alert alert-' . $class . '"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' . $message . '</div>'; } elseif (!$flash['element']) { $out = $message; } else { $options = array(); if (isset($flash['params']['plugin'])) { $options['plugin'] = $flash['params']['plugin']; } $tmpVars = $flash['params']; $tmpVars['message'] = $message; $out = $this->_View->element($flash['element'], $tmpVars, $options); } CakeSession::delete('Message.' . $key); } return $out; }
public function admin_index() { $user = CakeSession::read('admin_user'); $this->set('user', $user[0]['Admin']); $attributes = $this->Attribute->find('all'); pr($attributes); }
public function currentUser() { App::uses('CakeSession', 'Model/Datasource'); $Session = new CakeSession(); $user = $Session->read('Auth.User'); return array('id' => $user['User']['username']); }
public function login() { if (isset($this->Controller->request->query['code'])) { $code = $this->Controller->request->query['code']; } if (isset($this->Controller->request->query['state'])) { $state_request = $this->Controller->request->query['state']; } if (empty($code)) { CakeSession::write('state', md5(uniqid(rand(), TRUE))); $state_session = CakeSession::read('state'); // CSRF protection $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . $this->app_id . "&redirect_uri=" . urlencode($this->my_url) . "&state=" . $state_session . "&scope=email"; $this->__redirectFunc($dialog_url); } if (CakeSession::read('state') && CakeSession::read('state') === $state_request) { $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $this->app_id . "&redirect_uri=" . urlencode($this->my_url) . "&client_secret=" . $this->app_secret . "&code=" . $code; $response = file_get_contents($token_url); parse_str($response, $params); CakeSession::write('access_token', $params['access_token']); $graph_url = "https://graph.facebook.com/me?access_token=" . CakeSession::read('access_token'); $user = json_decode(file_get_contents($graph_url)); return $user; } else { echo "The state does not match. You may be a victim of CSRF."; } }
/** * Check Auth is user is admin */ public function setup(Model $model, $settings = array()) { parent::setup($model, $settings); if (CakeSession::check('Auth')) { $this->_isAdmin = CakeSession::read('Auth.User.is_admin') ? true : false; } }
/** * faved * * @return Mixed $id or false */ public function faved($key, $modelId) { if (empty($key) || empty($modelId)) { throw new FavException(__('Fav: Invalid Fav.keys.')); } $keys = Configure::read('Fav.keys'); if (!array_key_exists($key, $keys) || !array_key_exists('model', $keys[$key]) || !array_key_exists('type', $keys[$key])) { throw new FavException(__('Fav: Invalid Fav.keys.')); } $sessionKey = 'Auth.User.id'; if (array_key_exists('userIdSessionKey', $keys[$key])) { $sessionKey = $keys[$key]['userIdSessionKey']; } $userId = CakeSession::read($sessionKey); if (empty($userId)) { throw new FavException(__('Fav: User not found')); } $userModel = 'User'; if (array_key_exists('userModel', $keys[$key])) { $userModel = $keys[$key]['userModel']; } $type = $keys[$key]['type']; $model = $keys[$key]['model']; $data = array('type' => $type, 'user_model' => $userModel, 'user_id' => $userId, 'model' => $model, 'model_id' => $modelId); $fav = $this->find('first', array('conditions' => $data)); if (empty($fav)) { return false; } return $fav['Fav']['id']; }
public function flash($key = 'flash', $attrs = array()) { $out = false; if (CakeSession::check('Message.' . $key)) { $flash = CakeSession::read('Message.' . $key); if (is_array($flash)) { foreach ($flash as $fkey => $msg) { $message = $msg['message']; // unset($flash[$fkey]['message']); if (!empty($attrs)) { $msg = array_merge($msg, $attrs); } if ($msg['element'] === 'default') { $class = 'message'; if (!empty($msg['params']['class'])) { $class = $msg['params']['class']; } $out .= '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; } elseif (!$msg['element']) { $out .= $message; } else { $options = array(); if (isset($msg['params']['plugin'])) { $options['plugin'] = $msg['params']['plugin']; } $tmpVars = $msg['params']; $tmpVars['message'] = $message; $out .= $this->_View->element($msg['element'], $tmpVars, $options); } CakeSession::delete('Message.' . $key . '.' . $fkey); } } else { $message = $flash['message']; unset($flash['message']); if (!empty($attrs)) { $flash = array_merge($flash, $attrs); } if ($flash['element'] === 'default') { $class = 'message'; if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; } elseif (!$flash['element']) { $out = $message; } else { $options = array(); if (isset($flash['params']['plugin'])) { $options['plugin'] = $flash['params']['plugin']; } $tmpVars = $flash['params']; $tmpVars['message'] = $message; $out = $this->_View->element($flash['element'], $tmpVars, $options); } CakeSession::delete('Message.' . $key); } } return $out; }
public function goBack($title, $options, $state = 0) { $history = CakeSession::read('History'); $history = is_array($history) ? $history : array(); $target = array_slice($history, $state - 1, 1); $target = count($target) > 0 ? $target[0] : $this->webroot; return $this->Html->link($title, $this->fixTarget($target), $options); }
public function order() { // Call invoice_id from CakeSession $invoiceId = CakeSession::read('invoice_id'); $invoiceModel = new Invoice(); $invoices = $invoiceModel->find('first', array('conditions' => array('Invoice.id' => $invoiceId))); $this->set(compact('invoices')); }
public function admin_index() { $user = CakeSession::read('admin_user'); $this->set('user', $user[0]['Admin']); $this->layout = 'admin_small'; $exercises = $this->Exercise->find('all'); $this->set('exercises', $exercises); }
public function getCurrentUser() { // for CakePHP 2.x: App::uses('CakeSession', 'Model/Datasource'); $Session = new CakeSession(); $user = $Session->read('Auth.User'); return $user; }
public function admin_index() { $user = CakeSession::read('admin_user'); $this->set('user', $user[0]['Admin']); $conditions = array('joins' => array(array('alias' => 'MemberSubscription', 'table' => 'member_subscriptions', 'foreignKey' => false, 'conditions' => array('MemberSubscription.member_id = Member.id'))), 'conditions' => array('MemberSubscription.active' => 1)); $active_member_count = $this->Member->find('count', $conditions); $this->set('active_members', $active_member_count); }
/** * ログアウトのテスト * * @return void */ public function testLogout() { //ログイン状態と判定させるMock生成 $this->_mockLoggedIn(); $this->assertTrue($this->controller->Auth->loggedIn()); $this->testAction('/auth_general/auth_general/logout', array('data' => array())); $this->assertEqual(null, CakeSession::read('Auth.User')); }