/** * Initialize component * * @param object $controller Instantiating controller * @access public */ function initialize(&$controller, $settings = array()) { if (!count($controller->uses) || get_parent_class($controller->{$controller->modelClass}) == 'Object') { return; } if (!$controller->{$controller->modelClass}->Behaviors->attached('Logable')) { return; } // Auto-import user data if AuthsomeComponent is in use if (class_exists('Authsome')) { if (!Authsome::get('guest')) { $controller->{$controller->modelClass}->setUserData(Authsome::get()); } } // Auto-import user data if AuthComponent is in use if (!empty($controller->Auth)) { $user = $controller->Auth->user(); if ($user !== null) { $controller->{$controller->modelClass}->setUserData(array('User' => $user)); } } $controller->{$controller->modelClass}->setRequestParameters($controller->params); $controller->{$controller->modelClass}->setUserBrowser($_SERVER['HTTP_USER_AGENT']); $controller->{$controller->modelClass}->setUserIp($_SERVER['REMOTE_ADDR']); }
function _isAuthorized(&$controller) { $action = strtolower($controller->params['action']); $authRequiredActions = array_map('strtolower', $this->settings['auth_required']); $authRequired = $authRequiredActions == array('*') || in_array($action, $authRequiredActions); if ($authRequired and Authsome::get('guest')) { $controller->Session->setFlash('Please login to access this resource'); $controller->redirect(array('controller' => 'users', 'action' => 'login')); } $authDeniedActions = array_map('strtolower', $this->settings['auth_denied']); $authDenied = $authDeniedActions == array('*') || in_array($action, $authDeniedActions); if ($authDenied and !Authsome::get('guest')) { $controller->Session->setFlash('You are already logged in'); $controller->redirect(array('controller' => 'users', 'action' => 'dashboard')); } $adminRequiredActions = array_map('strtolower', $this->settings['admin_required']); $adminRequired = $adminRequiredActions == array('*') || in_array($action, $adminRequiredActions); if ($adminRequired and Authsome::get('group') != 'administrator') { $controller->Session->setFlash('You must be an administrator to access this resource'); $controller->redirect(array('controller' => 'users', 'action' => 'dashboard')); } $deniedActions = array_map('strtolower', $this->settings['denied']); $denied = $deniedActions == array('*') || in_array($action, $deniedActions); if ($denied) { $controller->Session->setFlash('You do not have access to this resource'); $controller->redirect(array('controller' => 'users', 'action' => 'index')); } }
function authsomeLogin($type, $credentials = array()) { switch ($type) { case 'guest': // You can return any non-null value here, if you don't // have a guest account, just return an empty array return array(); case 'credentials': $password = Authsome::hash($credentials['password'], Configure::read('SparkPlug.hash.method'), Configure::read('SparkPlug.hash.salt')); // This is the logic for validating the login $conditions = array('User.username' => $credentials['username'], 'User.password' => $password, 'User.active' => '1'); break; case 'cookie': list($token, $userId) = split(':', $credentials['token']); $duration = $credentials['duration']; $loginToken = $this->LoginToken->find('first', array('conditions' => array('user_id' => $userId, 'token' => $token, 'duration' => $duration, 'used' => false, 'expires <=' => date('Y-m-d H:i:s', strtotime($duration))), 'contain' => false)); if (!$loginToken) { return false; } $loginToken['LoginToken']['used'] = true; $this->LoginToken->save($loginToken); $conditions = array('User.id' => $loginToken['LoginToken']['user_id']); break; default: return null; } return $this->find('first', compact('conditions')); }
function beforeFilter() { $user = Authsome::get(); if ($user == "") { $this->Session->setFlash(__('No esta autenticado.'), 'flash_orange'); return $this->redirect(array('controller' => 'Users', 'action' => 'login')); } if ($user['User']['status'] == Configure::read('STATUS.MODIFIED')) { return $this->redirect(array('controller' => 'Users', 'action' => 'logout')); } switch ($user['User']['rol']) { case Configure::read('ROL.CHIEF'): # code... return $this->redirect(array('controller' => 'Sails', 'action' => 'indexComodoro')); break; case Configure::read('ROL.BOSS'): # code... return $this->redirect(array('controller' => 'Managements')); break; case Configure::read('ROL.PERSON'): # code... return $this->redirect(array('controller' => 'Users', 'action' => 'logout')); break; } }
function beforeFilter() { $user = Authsome::get(); if ($user == "") { $this->Session->setFlash(__('No esta autenticado.'), 'flash_orange'); return $this->redirect(array('controller' => 'Users', 'action' => 'login')); } if ($user['User']['status'] == Configure::read('STATUS.MODIFIED')) { return $this->redirect(array('controller' => 'Users', 'action' => 'logout')); } switch ($user['User']['rol']) { case Configure::read('ROL.BOSS'): # code... return $this->redirect(array('controller' => 'Managements')); break; case Configure::read('ROL.ADMIN'): case Configure::read('ROL.SUB-ADMIN'): # code... return $this->redirect(array('controller' => 'pages')); break; case Configure::read('ROL.PERSON'): # code... return $this->redirect(array('controller' => 'Users', 'action' => 'logout')); break; } $chief = $this->Chief->findByUserId(Authsome::get('User.id')); $this->set('com', $chief['Chief']['last_name'] . ', ' . $chief['Chief']['name']); }
public function logout() { Authsome::logout(); $this->Redirect->flash('logged_out', array( 'controller' => 'dashboards', 'action' => 'index' )); }
/** * Sets the User_id for the created_by and modified_by fields for this model * * @param object $model Model using the behavior * @return void * @author Matt Curry **/ function beforeValidate(&$model) { $settings = $this->settings[$model->alias]; $trackable_id = isset($model->trackable_id) ? $model->trackable_id : Authsome::get('id'); $trackable_id = !$trackable_id ? '0' : $trackable_id; if (empty($model->data[$model->alias][$model->primaryKey])) { $model->data[$model->alias][$settings['created_by_field']] = $trackable_id; } $model->data[$model->alias][$settings['modified_by_field']] = $trackable_id; return true; }
public function beforeSave($options = array()) { # code... if (empty($this->data[$this->alias]['id'])) { //INSERT $this->data[$this->alias]['status'] = Configure::Read('STATUS.INITIAL'); if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = Authsome::hash($this->data[$this->alias]['password']); } } return true; }
/** * List all projects * * @return void * @access public */ function index() { $this->loadModel('Project'); $currentUser = Authsome::get(); $currentUserId = $currentUser['User']['id']; $userGroup = $currentUser['UserGroup']['name']; if ($userGroup === ADMIN_USER_GROUP || $userGroup === INTERNAL_USER_GROUP) { $this->paginate['Project'] = array('contain' => array('Population.id', 'Population.project_id', 'Library.id', 'Library.project_id'), 'order' => 'Project.id'); $this->set('projects', $this->paginate()); } else { $projects = $this->Project->findUserProjects(); $this->set('projects', $projects); $this->render('index_no_pagination'); } }
public function authsomeLogin($type, $credentials = array()) { switch ($type) { case 'guest': // You can return any non-null value here, if you don't // have a guest account, just return an empty array return ""; case 'credentials': $password = Authsome::hash($credentials['password']); // This is the logic for validating the login $conditions = array('User.username' => $credentials['username'], 'User.password' => $password, 'User.rol != ' => Configure::read('ROL.PERSON')); break; default: return null; } return $this->find('first', compact('conditions')); }
function login() { if (empty($this->data)) { return; } $type = strstr($this->data['User']['login'], '@') ? 'credentials' : 'username'; $maintainer = Authsome::login($type, $this->data['User']); if (!$maintainer) { $this->Session->setFlash(__('Unknown user or incorrect Password', true)); return; } $remember = !empty($this->data['Maintainer']['remember']); if ($remember) { Authsome::persist('2 weeks'); } if ($maintainer) { $this->Session->setFlash(__('You have been logged in', true)); $this->redirect(array('controller' => 'users', 'action' => 'dashboard')); } }
function beforeSave(&$model) { if (!isset($model->id)) { return true; } $settings = $this->settings[$model->alias]; $count = count($settings['exception']); $user = Authsome::get(); if (!$user) { return false; } foreach ($settings['exception'] as $key => $value) { if ($user[$model->alias][$key] == $value) { $count--; } } if ($count == 0) { return true; } $rec = $model->find('first', array('conditions' => array("{$model->alias}.{$settings['model_field']}" => $model->id), 'contain' => false)); return $rec[$model->alias][$settings['model_field']] == Authsome::get('authsome_field'); }
public function account() { if ($this->data) { if ($this->data['User']['new_password']) { $this->User->passwordReset(); $this->data['User']['password'] = $this->data['User']['new_password']; } if ($this->User->save($this->data)) { $this->Redirect->flash('account_saved', array('action' => 'index')); } $this->Redirect->flash('input_errors'); } $id = Authsome::get('User.id'); $this->data = $this->User->findById($id); }
private function login($username, $password) { $this->data['User']['username'] = $username; $this->data['User']['password'] = $password; return Authsome::login($this->data['User']); }
function activatePassword($Model, $data) { $user = $Model->read(null, $data['User']['ident']); if ($user) { $password = $user['User']['password']; $salt = Configure::read("Security.salt"); $thekey = md5($password . $salt); if ($thekey == $data['User']['activate']) { $user['User']['password'] = $data['User']['password']; $user['User']['confirm_password'] = $data['User']['confirm_password']; if ($Model->save($user)) { $Model->updateAll(array('password' => "'" . Authsome::hash($user['User']['password'], Configure::read('SparkPlug.hash.method'), Configure::read('SparkPlug.hash.salt')) . "'"), "User.id = '" . $data['User']['ident'] . "'"); return true; } else { return false; } } else { return false; } } else { return false; } }
/** * Returns associative array with datasets as keys (those for which * the logged in user has permissions and associative information * as values * * @param int $datasetType 0 all datasets, 1 only libraries, 2 only populations * @param int $projectId restrict returned datasets to a certain project * @return Array associative array with datasets as keys and associative information * as values * @access public */ public function findUserDatasets($datasetType = POPULATION_AND_LIBRARY_DATASETS, $projectId = null) { $userDatasets = array(); $currentUser = Authsome::get(); $currentUserId = $currentUser['User']['id']; $userGroup = $currentUser['UserGroup']['name']; //check if chached if (($userDatasets = Cache::read($currentUserId . $projectId . 'userDatasets')) === false) { if ($userGroup === ADMIN_USER_GROUP || $userGroup === INTERNAL_USER_GROUP) { if (is_null($projectId)) { if ($datasetType == POPULATION_AND_LIBRARY_DATASETS) { $query = "select datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t\t (SELECT 'population' as type,populations.name as name, populations.description as description, projects.name\n\t\t\t\t\t\t as project,projects.id as project_id from populations INNER JOIN projects ON(projects.id=populations.project_id)\n\t\t\t\t\t\t UNION SELECT 'library' as type,libraries.name as name, libraries.description as description,projects.name as project,\n\t\t\t\t\t\t projects.id as project_id from libraries INNER JOIN projects ON(projects.id=libraries.project_id)) \n\t\t\t\t\t\t as datasets ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == LIBRARY_DATASETS) { $query = "select datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from (SELECT 'library' as type,libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id from libraries INNER JOIN projects ON(projects.id=libraries.project_id)) as datasets ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == POPULATION_DATASETS) { $query = "select datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from (SELECT 'population' as type,populations.name as name, populations.description as description, projects.name as project,projects.id as project_id from populations INNER JOIN projects ON(projects.id=populations.project_id)) as datasets ORDER BY datasets.project ASC, datasets.name ASC"; } } } } else { if ($datasetType == POPULATION_AND_LIBRARY_DATASETS) { $query = "select datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from (SELECT 'population' as type,populations.name as name, populations.description as description, projects.name as project,projects.id as project_id from populations INNER JOIN projects ON(projects.id=populations.project_id) where projects.id={$projectId} UNION SELECT 'library' as type,libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id from libraries INNER JOIN projects ON(projects.id=libraries.project_id) where projects.id={$projectId}) as datasets ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == LIBRARY_DATASETS) { $query = "select datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from (SELECT 'library' as type,libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id from libraries INNER JOIN projects ON(projects.id=libraries.project_id) where projects.id={$projectId}) as datasets ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == POPULATION_DATASETS) { $query = "select datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from (SELECT 'population' as type,populations.name as name, populations.description as description, projects.name as project,projects.id as project_id from populations INNER JOIN projects ON(projects.id=populations.project_id)) as datasets ORDER BY datasets.project ASC, datasets.name ASC"; } } } } } else { if (is_null($projectId)) { if ($datasetType == POPULATION_AND_LIBRARY_DATASETS) { $query = "SELECT datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t \t(SELECT populations.name as name, populations.description as description, projects.name as project,projects.id as project_id,'population' as type from populations\n\t\t\t\t\t \tINNER JOIN projects on(projects.id=populations.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t \twhere projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1 UNION\n\t\t\t\t\t SELECT libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id,'library' as type from libraries\n\t\t\t\t\t INNER JOIN projects on(projects.id=libraries.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t where projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1) as datasets\n\t\t\t\t\t ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == LIBRARY_DATASETS) { $query = "SELECT datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t \t(SELECT libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id,'library' as type from libraries\n\t\t\t\t\t INNER JOIN projects on(projects.id=libraries.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t where projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1) as datasets\n\t\t\t\t\t ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == POPULATION_DATASETS) { $query = "SELECT datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t \t(SELECT populations.name as name, populations.description as description, projects.name as project,projects.id as project_id,'population' as type from populations\n\t\t\t\t\t \tINNER JOIN projects on(projects.id=populations.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t \twhere projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1) as datasets\n\t\t\t\t\t ORDER BY datasets.project ASC, datasets.name ASC"; } } } } else { if ($datasetType == POPULATION_AND_LIBRARY_DATASETS) { $query = "SELECT datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t \t(SELECT populations.name as name, populations.description as description, projects.name as project,projects.id as project_id,'population' as type from populations\n\t\t\t\t\t \tINNER JOIN projects on(projects.id=populations.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t \twhere projects.id={$projectId} AND (projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1) UNION\n\t\t\t\t\t SELECT libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id,'library' as type from libraries\n\t\t\t\t\t INNER JOIN projects on(projects.id=libraries.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t where projects.id={$projectId} AND (projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1)) as datasets\n\t\t\t\t\t ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == LIBRARY_DATASETS) { $query = "SELECT datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t \t(SELECT libraries.name as name, libraries.description as description,projects.name as project,projects.id as project_id,'library' as type from libraries\n\t\t\t\t\t INNER JOIN projects on(projects.id=libraries.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t where projects.id={$projectId} AND (projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1)) as datasets\n\t\t\t\t\t ORDER BY datasets.project ASC, datasets.name ASC"; } else { if ($datasetType == POPULATION_DATASETS) { $query = "SELECT datasets.name,datasets.description,datasets.project,datasets.project_id,datasets.type from\n\t\t\t\t\t \t(SELECT populations.name as name, populations.description as description, projects.name as project,projects.id as project_id, 'population' as type from populations\n\t\t\t\t\t \tINNER JOIN projects on(projects.id=populations.project_id) LEFT JOIN projects_users on(projects_users.project_id=projects.id)\n\t\t\t\t\t \twhere projects.id={$projectId} AND (projects.user_id = {$currentUserId} OR projects_users.user_id = {$currentUserId} OR projects.is_public=1)) as datasets\n\t\t\t\t\t ORDER BY datasets.project ASC, datasets.name ASC"; } } } } } $results = $this->query($query); foreach ($results as $result) { $datasetName = $result['datasets']['name']; $userDatasets[$datasetName] = $result['datasets']; } //cache query results Cache::write($currentUserId . $projectId . 'userDatasets', $userDatasets); } return $userDatasets; }
public function hash($password) { return Authsome::hash($password); }
function authsomeLogin($type, $credentials = array()) { switch ($type) { case 'guest': // You can return any non-null value here, if you don't // have a guest account, just return an empty array return array('guest' => 'guest'); case 'credentials': // This is the logic for validating the login $conditions = array("{$this->alias}.email" => $credentials['login'], "{$this->alias}.password" => Authsome::hash($credentials['password'])); break; case 'username': $conditions = array("{$this->alias}.{$this->displayField}" => $credentials['login'], "{$this->alias}.password" => Authsome::hash($credentials['password'])); break; case 'cookie': list($token, $maintainerId) = split(':', $credentials['token']); $duration = $credentials['duration']; $loginToken = $this->LoginToken->find('first', array('conditions' => array('user_id' => $maintainerId, 'token' => $token, 'duration' => $duration, 'used' => false, 'expires <=' => date('Y-m-d H:i:s', strtotime($duration))), 'contain' => false)); if (!$loginToken) { return false; } $loginToken['LoginToken']['used'] = true; $this->LoginToken->save($loginToken); $conditions = array("{$this->alias}.{$this->primaryKey}" => $loginToken['LoginToken']['user_id']); break; default: return null; } $maintainer = $this->find('first', compact('conditions')); if (!$maintainer) { return false; } $maintainer[$this->alias]['loginType'] = $type; return $maintainer; }
public function _findAccount($state, $query, $results = array()) { if ($state == 'before') { $query['conditions'] = array("{$this->alias}.{$this->primaryKey}" => Authsome::get('id')); $query['fields'] = array('first_name', 'last_name', 'location'); return $query; } elseif ($state == 'after') { if (empty($results[0])) { return false; } return $results[0]; } }
/** * Search all datasets * * @param String $query Lucene query string * @return void * @access public */ public function all($query = "*:*") { $this->loadModel('Project'); //adjust fields to allow search accross all samples including weighted datasets unset($this->searchFields['Search By Blast Statistics']); unset($this->searchFields['Search By Name']['hmm_name']); #unset($this->searchFields['Search By Name']['kegg_name']); unset($this->searchFields['Search By ID']['hmm_id']); #unset($this->searchFields['Search By ID']['kegg_id']); //if a query string has been passed in as a variable if ($query != "*:*") { $this->Session->write('searchField', 1); } else { $query = $this->data['Search']['query']; $field = $this->data['Search']['field']; try { $query = $this->generateLuceneQuery($query, $field); } catch (Exception $e) { $this->set('exception', $e->errorMessage()); $this->Session->write('query', $query); $this->Session->write('numHits', 0); $this->Session->write('searchField', $field); $this->render(); } } asort($this->searchFields['Search By ID']); asort($this->searchFields['Search By Name']); //get user id to make/get user specific cache $currentUser = Authsome::get(); $currentUserId = $currentUser['User']['id']; //try to use cache for default query *:*" if ($query != "*:*" || ($searchAllResults = Cache::read($currentUserId . 'searchAllResults')) === false) { //start search all $totalHits = 0; //returns all datasets the current user has access to $datasets = $this->Project->findUserDatasets(LIBRARY_DATASETS); $facets = array('habitat' => array(), 'location' => array(), 'filter' => array(), 'project' => array(), 'depth' => array()); foreach ($datasets as &$dataset) { $numHits = 0; //get number of hits try { $numHits = $this->Solr->count($dataset['name'], $query); } catch (Exception $e) { $this->set('exception', LUCENE_QUERY_EXCEPTION); break; } $totalHits += $numHits; $dataset['hits'] = $numHits; //get number of overall counts if ($query === '*:*') { $counts = $numHits; } else { $counts = $this->count($dataset['name']); } $dataset['counts'] = $counts; if ($numHits > 0) { $this->loadModel('Library'); $libraryMetadata = $this->Library->find('all', array('fields' => array('sample_habitat', 'sample_filter', 'sample_longitude', 'sample_latitude', 'sample_depth'), 'conditions' => array('Library.name' => $dataset['name']))); $habitat = $libraryMetadata[0]['Library']['sample_habitat']; $filter = $libraryMetadata[0]['Library']['sample_filter']; $depth = $libraryMetadata[0]['Library']['sample_depth']; $location = trim($libraryMetadata[0]['Library']['sample_latitude'] . " " . $libraryMetadata[0]['Library']['sample_longitude']); if (empty($habitat)) { $habitat = 'unassigned'; } if (empty($location)) { $location = 'unassigned'; } if (empty($filter)) { $filter = 'unassigned'; } if (empty($depth)) { $depth = 'unassigned'; } if (empty($dataset['project'])) { $project = 'unassigned'; } else { $project = $dataset['project']; } if (array_key_exists($habitat, $facets['habitat'])) { $facets['habitat'][$habitat] += $numHits; } else { $facets['habitat'][$habitat] = $numHits; } if (array_key_exists($location, $facets['location'])) { $facets['location'][$location] += $numHits; } else { $facets['location'][$location] = $numHits; } if (array_key_exists($depth, $facets['depth'])) { $facets['depth'][$depth] += $numHits; } else { $facets['depth'][$depth] = $numHits; } if (array_key_exists($filter, $facets['filter'])) { $facets['filter'][$filter] += $numHits; } else { $facets['filter'][$filter] = $numHits; } if (array_key_exists($project, $facets['project'])) { $facets['project'][$project] += $numHits; } else { $facets['project'][$project] = $numHits; } } if ($dataset['counts'] > 0) { $percent = round($dataset['hits'] / $dataset['counts'] * 100, 2); } else { $percent = 0; } $dataset['perc'] = $percent; } if ($totalHits > 0) { foreach ($facets as $key => $value) { arsort($facets[$key]); $facets[$key] = array_slice($facets[$key], 0, NUM_TOP_FACET_COUNTS, true); } } //sort results by absolute counts usort($datasets, array('SearchController', 'sortResultsByCounts')); //store everything in the searchAllResults object for caching $searchAllResults['datasets'] = $datasets; $searchAllResults['facets'] = $facets; $searchAllResults['numHits'] = $totalHits; $searchAllResults['query'] = $query; $searchAllResults['numDatasets'] = count($datasets); //cache query results if ($query === '*:*') { Cache::write($currentUserId . 'searchAllResults', $searchAllResults); } } //store data in session for search all view $this->Session->write('searchResults', $searchAllResults['datasets']); $this->Session->write('searchFields', $this->searchFields); $this->Session->write('query', $searchAllResults['query']); $this->Session->write('facets', $searchAllResults['facets']); $this->Session->write('numHits', $searchAllResults['numHits']); $this->Session->write('numDatasets', $searchAllResults['numDatasets']); }
public function login_person() { $data = $this->request->input('json_decode', true); $message = array('message' => 'Error revise sus datos.', 'code' => 400); if ($this->User->hasAny(array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password']), 'User.status' => Configure::Read('STATUS.INITIAL'), 'User.rol' => Configure::Read('ROL.PERSON')))) { $this->User->recursive = -1; $user = $this->User->find('first', array('conditions' => array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password'])))); $user = $user['User']['id']; $this->Person->recursive = -1; $person = $this->Person->findByUserId($user); $message['message'] = $person['Person']['identification'] . '_' . Configure::Read('ROL.PERSON'); $message['code'] = 200; } else { if ($this->User->hasAny(array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password']), 'User.status' => Configure::Read('STATUS.INITIAL'), 'User.rol' => Configure::Read('ROL.CHIEF')))) { $this->User->recursive = -1; $user = $this->User->find('first', array('conditions' => array('User.username' => $data['username'], 'User.password' => Authsome::hash($data['password'])))); $user = $user['User']['id']; $this->Chief->recursive = -1; $chief = $this->Chief->findByUserId($user); $message['message'] = $chief['Chief']['identification'] . '_' . Configure::Read('ROL.CHIEF'); $message['code'] = 200; } } $this->set(array('Message' => $message, '_serialize' => array('Message'))); }
public function isCorrectPassword() { $user = $this->data['User']; return $this->find('first', array( 'conditions' => array( 'User.id' => $user['id'], 'User.password' => Authsome::hash($user['current_password']) ) )); }
/** * Retrieves the user_id for the current model. Can be overriden in model * * This method tries to retrieve the trackable_id in the following order: * * - Model->getTrackableId() * - Model->trackable_id * - AuthComponent::user($user_primaryKey) * - Authsome::get($user_primaryKey) * - User::get($user_primaryKey) * * @param object $Model Model using the behavior * @return mixed user_id integer if available, false otherwise * @access public */ public function getTrackableId(Model $Model) { $trackableId = null; if (method_exists($Model, 'getTrackableId')) { $trackableId = $Model->getTrackableId(); } if (!empty($Model->trackable_id)) { $trackableId = $Model->trackable_id; } if (!$trackableId && class_exists('AuthComponent')) { $trackableId = AuthComponent::user($this->settings[$Model->alias]['user_primaryKey']); } if (!$trackableId && class_exists('Authsome')) { $trackableId = Authsome::get($this->settings[$Model->alias]['user_primaryKey']); } if (!$trackableId) { $className = get_class($Model); if (method_exists($className, 'get')) { $trackableId = $className::get($this->settings[$Model->alias]['user_primaryKey']); } } return $trackableId; }
function login() { if (isset($_GET["ident"])) { if ($this->User->activateAccount($_GET)) { $this->flash("Thank you. Your account is now active.", Configure::read('httpRootUrl') . '/users/login'); } else { $this->flash("Sorry. There were problems in your account activation.", Configure::read('httpRootUrl') . '/users/login'); } } else { if (empty($this->data)) { return; } $user = Authsome::login($this->data['User']); if (!$user) { $this->Session->setFlash('Unknown user or wrong password'); return; } $remember = !empty($this->data['User']['remember']); if ($remember) { Authsome::persist('2 weeks'); } $this->Session->write("User", $user); $this->Session->write("User.id", $user["User"]["id"]); $this->Session->write("UserGroup.id", $user["UserGroup"]["id"]); $this->Session->write("UserGroup.name", $user["UserGroup"]["name"]); $this->Session->write('Company.id', $user['Company']['id']); $this->redirect(Configure::read('SparkPlug.loginRedirect')); } }
function _login() { $this->layout = Configure::read('front_end_layout'); $guest = Authsome::get(); debug($guest); die; if (isset($_GET["ident"])) { if ($this->User->activateAccount($_GET)) { $this->flash("Thank you. Your account is now active.", "login"); } else { $this->flash("Sorry. There were problems in your account activation.", "login"); } } else { if (isset($user['success'])) { $user = $this->User->read(null, $user["User"]["id"]); $this->Session->write("User", $user); $this->Session->write("User.id", $user["User"]["id"]); $this->Session->write("UserGroup.id", $user["UserGroup"]["id"]); $this->Session->write("UserGroup.name", $user["UserGroup"]["name"]); $this->Session->write('Company.id', $user['Company']['id']); $this->redirect("/dashboard"); } elseif (isset($user['error'])) { $this->flash($user['error']['message'], 'login'); } } }
function login() { $this->loadModel('User'); ## account activation if (isset($_GET["ident"])) { #on success if ($this->User->activateAccount($_GET)) { $this->Session->setFlash("Thank you. Your METAREP account has been activated. Please login."); $this->redirect("/dashboard", null, true); } else { $this->Session->setFlash("There was a problem with your account information. Please contact " . METAREP_SUPPORT_EMAIL); $this->redirect("/dashboard", null, true); $this->flash("Sorry. There were problems in your account activation.", Configure::read('httpRootUrl') . '/users/login'); } } else { if (empty($this->data)) { return; } $user = Authsome::login($this->data['User']); //if authentification failed if (!$user) { $this->Session->setFlash('Unknown user or wrong password'); $this->redirect('/dashboard', null, true); } $remember = !empty($this->data['User']['remember']); if ($remember) { Authsome::persist('2 weeks'); } //track user stats $this->loadModel('UserStats'); $this->data = array('UserStats' => array('category' => __FUNCTION__, 'user_id' => $user["User"]["id"])); $this->UserStats->save($this->data); $this->Session->write("User", $user); $this->Session->write("User.id", $user["User"]["id"]); $this->Session->write("UserGroup.id", $user["UserGroup"]["id"]); $this->Session->write("UserGroup.name", $user["UserGroup"]["name"]); if ($user['User']['username'] === 'jamboree') { $this->redirect('/projects/view/1', null, true); } else { $this->redirect('/dashboard', null, true); } } }
function login() { $this->layout = Configure::read('front_end_layout'); if (isset($_GET["ident"])) { if ($this->User->activateAccount($_GET)) { $this->flash("Thank you. Your account is now active.", Configure::read('httpRootUrl') . '/users/login'); } else { $this->flash("Sorry. There were problems in your account activation.", Configure::read('httpRootUrl') . '/users/login'); } } else { //check for facebook connect plugin available if ($this->Session->read('SparkPlug.facebookEnabled')) { // check if there is a facebook account logged in and there is no user logged in if ($this->Connect->me && !$this->Authsome->get()) { // check if there is an user linked to this facebook account $conds = array('external_auth_id' => 'facebook_' . $this->Connect->me['id']); $fbuser = $this->User->find($conds); // if user exists, do login with it if ($fbuser) { //debug('user exists. login'); $this->Session->write('SparkPlug.Users.loggedInByFacebook', true); $this->force_login_as_user($fbuser['User']['id']); } else { //debug('user does not exist. create'); // if the user does not exist, create the user using his email as login and do login $newUser = array(); $newUser['User']['username'] = $this->Connect->me['id']; $newUser['User']['password'] = md5(uniqid()); $newUser['User']['email'] = $this->Connect->me['email']; $newUser['User']['user_group_id'] = Configure::read('SparkPlug.default_group_for_new_facebook_accounts'); $newUser['User']['external_auth_id'] = 'facebook_' . $this->Connect->me['id']; if ($this->User->save($newUser['User'])) { $this->Session->setFlash('New user created and linked with your facebook account'); $this->Session->write('SparkPlug.Users.loggedInByFacebook', true); $this->force_login_as_user($this->User->getLastInsertId()); } else { $this->Session->setFlash('There was an error creating the new user'); } } ///debug($this->Connect->me); } } if (empty($this->data)) { return; } /* if (!empty(Authsome::get()){ $this->Session->setFlash('Already logged in, logout first'); return; } */ $user = Authsome::login($this->data['User']); if (!$user) { $this->Session->setFlash('Unknown user or wrong password'); return; } $remember = !empty($this->data['User']['remember']); if ($remember) { Authsome::persist('2 weeks'); } $this->Session->write("User", $user); $this->Session->write("User.id", $user["User"]["id"]); $this->Session->write("UserGroup.id", $user["UserGroup"]["id"]); $this->Session->write("UserGroup.name", $user["UserGroup"]["name"]); $this->Session->write('Company.id', $user['Company']['id']); // let's redirect to the page that triggered the login attempt $originAfterLogin = $this->Session->read('SparkPlug.OriginAfterLogin'); $this->tinymce_filemanager_init(); if (Configure::read('SparkPlug.redirectOriginAfterLogin') && $originAfterLogin != null) { $this->redirect($originAfterLogin); } else { // redirect to default location $this->redirect(Configure::read('SparkPlug.loginRedirect')); } } }
public function login() { $this->layout = 'admin_no_login'; if (empty($this->data)) { return; } $user = $this->Authsome->login($this->data['User']); if (!$user) { $this->Session->setFlash('Constraseña o nombre de usuario incorrecto', 'flash_orange'); return; } $user = $this->Authsome->get(); //mLucena switch ($user['User']['rol']) { case Configure::read('ROL.CHIEF'): # code... return $this->redirect(array('controller' => 'Sails', 'action' => 'indexComodoro')); break; case Configure::read('ROL.BOSS'): # code... return $this->redirect(array('controller' => 'Managements')); break; case Configure::read('ROL.SUB-ADMIN'): case Configure::read('ROL.ADMIN'): return $this->redirect(array('controller' => 'pages', 'action' => 'index')); break; } Authsome::logout(); return $this->redirect('login'); }
/** * Wrapper around retrieving user data * * Can be overriden in the Model to provide advanced control * * @param array $result single Model record being authenticated against * @param string $key field to retrieve. Leave null to get entire User record * @return mixed User record. or null if no user is logged in. */ public function user(Model $Model, $result, $key = null) { if (method_exists($Model, 'user')) { return $Model->user($key, $result); } if (class_exists('AuthComponent')) { return AuthComponent::user($key); } if (class_exists('Authsome')) { return Authsome::get($key); } if (method_exists($Model, 'get')) { $className = get_class($Model); $ref = new ReflectionMethod($className, 'get'); if ($ref->isStatic()) { return $className::get($key); } } return false; }