public function delete($id) { $msg = MessageModel::id($id); if (!empty($msg->report)) { @unlink(path($msg->report)); } Response::json(MessageModel::delete('id = ?', [$id])); }
function refresh($after = 0) { Response::refresh($after); }
public function update() { $user = User::getData(); $name = Request::getParam('name'); $email = Request::getParam('email'); $newpass = Request::getParam('newpass'); $tel = Request::getParam('tel'); $address = Request::getParam('address'); $mobile = Request::getParam('mobile'); $gender = Request::getParam('gender'); $avatar = ''; if (Request::hasFile('avatar')) { $avatar = 'images/' . Request::getFile('avatar')->name; } if (empty($newpass)) { $newpass = Request::getParam('pass'); } if (empty($avatar)) { $avatar = $user->avatar; } if (empty($address)) { $address = $user->address; } $user_columns = ['name' => $name, 'email' => $email, 'pass' => Hash::make($newpass), 'mobile' => $mobile, 'tel' => $tel, 'gender' => $gender, 'address' => $address, 'avatar' => $avatar, 'updated_at' => Carbon::now()]; if (UserModel::update($user_columns, "id = ?", [User::getData()->id])) { goBack(); } else { Response::error(401); } }
public function facebook() { $fb = new FacebookModel(); $fb->setLoginHelper(); if ($fb->updateUserInformation()) { $u = new User($fb->getUserRememberMe()); $u->login(); redirect(route('user', ['slug' => $fb->getUserSlug()])); return; } Response::error(401); }
public function run() { try { if (isset($_SERVER['REQUEST_METHOD'])) { $request_method = $_SERVER['REQUEST_METHOD']; $request_method = Request::isAjax() ? 'AJAX' : $request_method; $inputFlag = Request::hasParam('_token'); // check the request method if PUT, DELETE or POST if ($request_method == 'POST') { if (isset($_POST['_method'])) { $request_method = $_POST['_method']; } } // check if the request method not supported if (!in_array($request_method, ['POST', 'GET', 'PUT', 'AJAX', 'DELETE'])) { throw new BadRequestException('Unauthorized: Access is denied, REQUEST_METHOD not found'); } $res = null; // if any routes are set with the request method if (isset($this->routes[$request_method])) { foreach ($this->routes[$request_method] as $route) { // find the route that matches the requested url if ($route->equals($this->url)) { // if the token field is set check the token if ($route->token) { $tokenFlag = Token::match(Request::getParam('_token')); if (!$inputFlag || $inputFlag && !$tokenFlag) { throw new TokenMissMatchException('Unauthorized: Access is denied, Token Miss Match!'); die('Token missmatch!'); } } // executes the requested route $res = $route->exec(); if (is_string($res)) { echo $res; } else { if (!is_null($res)) { dd($res); } } return; } } } Response::error(404); } else { throw new BadRequestException('Unauthorized: Access is denied, REQUEST_METHOD not found'); } } catch (Exception $exc) { die($exc->getMessage() . ' please go <a href="' . Request::getPrevUrl() . '">back.</a>'); } }
public function delete($id) { $current = User::getData(); $admin = PermissionModel::findBy(['user_id' => $current->id, 'permission' => 'admin']); $userFlag = $perFlag = $msgFlag = $compFlag = FALSE; if ($current->id != $id && $admin) { $avatar = UserModel::id($id)->avatar; if (!empty($avatar)) { @unlink(Url::resource($avatar)); } $userFlag = UserModel::delete('id = ?', [$id]); $perFlag = PermissionModel::delete('user_id = ?', [$id]); $msgFlag = MessageModel::delete('user_id = ?', [$id]); $compFlag = ComplainModel::delete('user_id = ?', [$id]); } Response::json(['status' => $userFlag && $perFlag && $msgFlag && $compFlag]); }