public function load($key) { $data = $this->redis->get($key); if (\cx\application\main_functions::is_serialized($data) === true) { $data = cx\app\main_functions::safe_unserialize($data); } return $data; }
public function load($key) { $files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\\._-]/i', '', $key) . '.*'); if ($files) { $handle = fopen($files[0], 'r'); flock($handle, LOCK_SH); $data = fread($handle, filesize($files[0])); flock($handle, LOCK_UN); fclose($handle); return cx\app\main_functions::safe_unserialize($data); } return false; }
public function main() { $this->set_title_and_header('Main Page'); $index = $this->get_url('app/home', 'index'); $this->breadcrumb = array($index => "Index"); $this->active_crumb = "Main"; $id = $this->session->get_int(CX_LOGIN . 'id'); /** * @todo add api check / auth */ if ($this->request->is_not_valid_id($id)) { cx_redirect_url($this->get_url('/app/' . DEFAULT_PROJECT, 'login')); } $page['fname'] = $this->session->session_var(CX_LOGIN . 'fname'); $page['lname'] = $this->session->session_var(CX_LOGIN . 'lname'); $rights = $this->session->session_var(CX_LOGIN . 'rights'); $page['rights'] = cx\app\main_functions::is_serialized($rights) === true ? cx\app\main_functions::safe_unserialize($rights) : $rights; $this->load_view('app' . DS . 'main', $page); }
public function edit_user() { $id = cx\app\static_request::init('get', 'id'); if ($id->is_not_set()) { echo "Invalid id!"; exit; } if ($id->to_int() !== $this->session->get_int(CX_LOGIN . 'id')) { $this->auth(array('user' => 'admin_check')); $lock_rights_controls = false; // Admin } elseif ($this->auth(array('user' => 'is_admin')) === true) { $lock_rights_controls = false; // Admin can modify self, as they can create any user... } else { $lock_rights_controls = true; // User must not be able to grant self more rights! } $this->load_model(); $db_options = array('table' => 'users', 'key' => 'id'); $edit_user = new cx\database\model($db_options); if ($id->is_not_valid_id()) { // no existing data $model = array(); $model['new'] = true; } else { $edit_user->load($id->to_int()); $model = $edit_user->get_members(); if ($model == array()) { echo "Invalid id!"; exit; } $s_pwd = $model['password']; // Save Pwd unset($model['password']); // Remove scrambled DB password, so user does not see it! $model['new'] = false; } $model['lock_rights_controls'] = $lock_rights_controls; $model['rights_statuses'] = array('admin' => 'Administrator', 'staff' => 'Staff', 'cus' => 'Customer', 'api' => 'API client'); if (cx\app\static_request::init('post', 'save')->is_set()) { $edit_user->auto_set_members(); // Set all post vars to DB $confirm = $this->request->post_var('confirm'); $pwd = $this->request->post_var('password'); if (cx\app\static_request::init('post', 'username')->is_empty() || cx\app\static_request::init('post', 'fname')->is_empty() || cx\app\static_request::init('post', 'lname')->is_empty()) { cx\app\main_functions::set_message('First/Last name or username is missing.'); $saveme = false; } elseif ($model['new'] === false && $this->request->is_empty($confirm) && $this->request->is_empty($pwd)) { $edit_user->set_member('password', $s_pwd); // Keep current password! $saveme = true; } elseif ($this->request->is_not_empty($confirm) && $pwd === $confirm && strlen($pwd) > 6) { $this->load_model('users' . DS . 'users'); $db_options = array('api' => false); $users = new cx\model\users($db_options); $edit_user->set_member('password', $users->get_pwd_hash($pwd)); // Assign new pwd $saveme = true; } else { cx\app\main_functions::set_message('Password not strong/does not match.'); $saveme = false; } if ($saveme === true) { $success = $edit_user->save(); $id = $edit_user->get_member('id'); if ($success === true && $id > 0) { cx_redirect_url($this->get_url('/app/users', 'edit_user', 'id=' . $id)); } } } $frm = $this->load_class('cx\\form\\form', array('name' => 'edit_user', 'defaults' => array('readonly' => false))); $frm->grab_form('app' . DS . 'users' . DS . 'edit_user', $model); $frm->end_form(); $this->add_js('./assets/pwd-meter.min.js'); $this->add_css('./assets/login.css'); $index = $this->get_url('app/users', 'index'); $this->breadcrumb = array($index => "List Users"); $this->active_crumb = "Edit User"; $this->do_view($frm->get_html()); }