public function indexAjax() { $input = Input::requireParams('username'); $username = $input->username; $id = (int) $this->getUser('id'); $validator = Validator::create(array('username' => "required|unique:\\User,username,{$id},id", 'first_name' => 'max:80', 'last_name' => 'max:160', 'password' => 'min:5|max:32', 'password2' => 'identical:password', 'timezone' => 'required|max:80')); if ($validator->failed()) { return BootstrapUI::formResponse()->failedOn($validator); } $input = $validator->getParamsObj(); $user = User::fetchOne($this->getUser('id')); $userSessionData = Session::get('user'); $refresh = $user->timezone != $input->timezone; $user->username = $input->username; $user->first_name = $input->first_name; $user->last_name = $input->last_name; $user->timezone = $input->timezone; if ($input->password !== null && strlen($input->password) >= 5) { $user->pass = md5($input->password); } $user->save(); foreach ($user->getData() as $key => $value) { $userSessionData[$key] = $value; } Session::set('user', $userSessionData); if ($refresh) { return BootstrapUI::formResponse()->refresh(); } else { return BootstrapUI::formResponse(); } }
public function indexAjax() { $input = Input::requireParams('username', 'pass', 'r'); if (($user = User::auth($input->username, $input->pass)) !== false) { $sessionData = $user->getData(); $sessionData['previous_login'] = $user->last_login; $user->updateLoginStats(); $sessionData['last_login'] = gmdate('Y-m-d H:i:s'); Cookie::set('username', $input->username, time() + 3600 * 24 * 30); Log::info("User {$input->username} logged in with " . Request::userAgent()); // some stats $sessionData['stats'] = array('new_stack_traces' => \Stack\Trace::getNewCount($sessionData['previous_login'])); Session::set('user', $sessionData); return BootstrapUI::formResponse()->redirect(base64_decode($input->r)); } else { Log::info("Invalid auth for '{$input->username}' with '{$input->pass}'"); return BootstrapUI::formResponse()->failed('Wrong username or password'); } }
/** * Update user settings if needed */ public function editUserAjax() { // TODO: Finish this $params = Input::requireParams('id'); $id = (int) $params->id; $user = User::fetchOne($id); if ($user === false) { return BootstrapUI::formResponse()->failed('Invalid user'); } $validator = Validator::create(array('id' => 'required|integer', 'username' => "required|min:2|max:32|unique:\\User,username,{$id},id", 'first_name' => 'max:255', 'last_name' => 'max:255', 'pass' => 'min:5|max:255', 'pass2' => 'identical:pass', 'account_type' => 'required', 'timezone' => 'required')); if ($validator->failed()) { return BootstrapUI::formResponse()->failedOn($validator); } $params = $validator->getParamsObj(); $data = $validator->getParams(); unset($data['id'], $data['pass'], $data['pass2']); if ($params->pass !== null && strlen($params->pass) >= 5) { $data['pass'] = md5($params->pass); } if ($user->save($data)) { Log::info("Updated user #{$id} {$params->username}"); } return BootstrapUI::formResponse(); }
public function getStackTraceAjax() { $params = Input::requireParams('id'); $id = (int) $params->id; if ($id <= 0) { throw new Exception('Invalid ID'); } $submit = Crash\Submit::fetchOne('id', $id); if ($submit === false) { throw new Exception('Can not find stack trace'); } return Json::create(array('success' => true, 'stack_trace' => $submit->stack_trace)); }
/** * Handle the request * @return \Bootstrap\Response\TableRemote */ public function handle() { $this->params = Input::requireParams('page', 'limit', 'field', 'dir'); $page = (int) $this->params->page; if ($page < 1) { $page = 1; } $limitPerPage = (int) $this->params->limit; $field = (string) trim($this->params->field); $this->resultSet->page($page, $limitPerPage)->orderBy($field, $this->params->dir); // check if this is request with search $search = trim((string) \Koldy\Input::post('search')); if ($search != '') { $fields = $this->searchFields !== null ? $this->searchFields : $this->columns; foreach ($fields as $field) { $this->resultSet->orWhere($field, "%{$search}%", null, 'LIKE'); } } \Log::debug($this->resultSet); // get the rows of data $this->data = $this->resultSet->fetch(); if (is_array($this->data)) { $this->tbody = array(); foreach ($this->data as $row) { $this->tbody[] = "<tr data-id=\"{$row[$this->primaryKey]}\">"; foreach ($this->columns as $column) { $value = isset($row[$column]) ? $row[$column] : null; if (isset($this->columnValueModifier[$column])) { $fn = $this->columnValueModifier[$column]; $fnResult = $fn($value, $row); $this->tbody[] = "<td>{$fnResult}</td>"; } else { $value = strip_tags(stripslashes($value)); $this->tbody[] = "<td>{$value}</td>"; } } $this->tbody[] = '</tr>'; } $this->tbody = implode("\n", $this->tbody); } // get the totals $total = (int) $this->resultSet->count(); // get the info if ($total > 0) { $start = ($this->params->page - 1) * $this->params->limit + 1; $end = $start + $this->params->limit; if ($end > $total) { $end = $total; } /*$this->info = __('table.records.info', 'Showing {from} - {to} of {total}', 'The info below remote table about how many rows are visible. Variables are {from}, {to} and {total}', array('from' => $start, 'to' => $end, 'total' => $total) );*/ $this->info = "Showing {$start} - {$end} of {$total}"; } else { $this->info = 'No results'; } // create pagination $this->pagination = new \Koldy\Pagination($this->params->page, $total); $this->pagination->setItemsPerPage(10)->setCssDefault('btn btn-primary btn-xs')->setCssSelected('btn-info'); return $this; }