小编sno*_*lly的帖子

Slim PHP:只捕获带有中间件的有效路由

我正在用Slim编写REST API.我编写了一个小型中间件来保护资源,因此只有经过身份验证的用户才能访问它们:

<?php
class SecurityMiddleware extends \Slim\Middleware
{
    protected $resource;
    public function __construct($resource)
    {
        $this->resource = $resource;
    }
    public function call()
    {
        //get a reference to application
        $app = $this->app;
        //skip routes that are exceptionally allowed without an access token:
        $publicRoutes = ["/","/login","/about"];
        if (in_array($app->request()->getPathInfo(),publicRoutes)){
            $this->next->call(); //let go
        } else {
            //Validate:
            if ($this->resource->isValid()){
                $this->next->call(); //validation passed, let go
            } else {
                $app->response->setStatus('403'); //validation failed
                $app->response->body(json_encode(array("Error"=>"Access token problem")));
                return;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是有效的,但不希望的副作用是中间件不区分现有路由和不存在的路由.例如,如果用户尝试请求/dfghdfgh不存在的路由,而不是获得404的HTTP状态代码,则他将得到403表示没有访问令牌.我想在中间件类上添加类似于以下检查的实现:

if ($app->hasRoute($app->request->getPathInfo()){
    $this->next->call(); //let …
Run Code Online (Sandbox Code Playgroud)

php slim

7
推荐指数
2
解决办法
8384
查看次数

如何在 JIRA 中搜索文本字段中的多个可能值

根据 Atlassian 文档,您可以搜索文本字段中包含的单词,如下所示:

description ~ term
Run Code Online (Sandbox Code Playgroud)

它还表明您可以对术语进行分组,如下所示:

description ~ (term OR "different thing")
Run Code Online (Sandbox Code Playgroud)

但当我尝试这样做时,它表明语法是错误的。

我想这样做,但要进行分组(因为我将有两个以上的术语,并且我希望使查询易于阅读且简短):

description ~ term OR description ~ "different thing"
Run Code Online (Sandbox Code Playgroud)

jql

6
推荐指数
1
解决办法
2万
查看次数

无法弄清楚如何使用async请求使用yield

我对节点有些新意,而且我对koa完全不熟悉.我正在尝试使用生成器来对API执行异步Web请求,但我无法弄清楚如何将所有部分放在一起.

作为一个注释,我使用蓝鸟,因为我看到一些例子这样做,这似乎是一个好主意.如果有一种更简单的方法来做我想要的没有蓝鸟,那也是完全没问题.

在我的模块中:

plugin.searchForItem = function * (name) {
  Promise = require('bluebird');
  request = Promise.promisifyAll(require('request'));
  console.log("making request");
  yield request.getAsync('http://apisitegoeshere.com/apicall').then(function * (result) {
    var response = result[0];
    var body = result[1];
    console.log(response.statusCode);
    yield response;
  });
};
Run Code Online (Sandbox Code Playgroud)

而我这样称呼它:

search.searchForShow = function (name) {
  data = this.plugins[0].searchForItem(name);
  console.log("search returned: " + data);
  console.log("search returned2: " + JSON.stringify(data.next()));
  console.log("search returned3: " + JSON.stringify(data.next()));
  return data;
};
Run Code Online (Sandbox Code Playgroud)

当我查看我的控制台时,我看到:

search returned: [object Generator]
making request
search returned2: {"value":{"isFulfilled":false,"isRejected":false},"done":false}
search returned3: {"done":true}
Run Code Online (Sandbox Code Playgroud)

我知道我的代码到处都是,但我已经工作了几个小时,我仍然没有更接近修复它.

谢谢!

javascript generator node.js bluebird koa

5
推荐指数
1
解决办法
2936
查看次数

在数组中取消设置索引会将其转换为对象

所以我有一个JSON文档,我将其存储在CouchDB中.这是它的重要部分:

"games": {
   "creator": [
       "cf86d68b24c1bbf22702356572027642",
       "cf86d68b24c1bbf22702356572027dd8",
       "cf86d68b24c1bbf22702356572028b77"
   ],
   "solver": {
   }
}
Run Code Online (Sandbox Code Playgroud)

我试图从数组中删除一个项目,让我们说索引1:

error_log("pre unset: " . json_encode($user->games));
unset($user->games->creator[1]);
error_log("post unset: " . json_encode($user->games));
Run Code Online (Sandbox Code Playgroud)

问题是,它不断将我的数组转换为一个对象,如下所示:

pre unset: {"creator":["cf86d68b24c1bbf22702356572027642","cf86d68b24c1bbf22702356572027dd8","cf86d68b24c1bbf22702356572028b77"],"solver":{}}
post unset: {"creator":{"0":"cf86d68b24c1bbf22702356572027642","2":"cf86d68b24c1bbf22702356572028b77"},"solver":{}}
Run Code Online (Sandbox Code Playgroud)

发生了什么,我该如何解决?

php arrays json unset

3
推荐指数
1
解决办法
515
查看次数

雄辩的收集归还了json

怎么可能?Le's说在控制器中我们有类似的东西:

 $something = Something:all();
Run Code Online (Sandbox Code Playgroud)

如果我只返回$ something,则返回一个包含table内容的json对象 {id:1, title :'etc'}

但是,如果我死了转储dd($something),我可以看到$something整个集合.

所以返回不返回集合,返回json对象......?

json laravel eloquent laravel-4

3
推荐指数
1
解决办法
3214
查看次数

express:命令未找到,之前有效吗?

我正在研究OSX 10.10.4,我曾经使用过node.js并在此计算机上进行过表达.但是现在当我想要启动一个新的应用程序时,计算机将不再识别该命令express.

我尝试使用所有这些命令安装它:

- npm install express
 - npm install -g express
 - npm install express -g
 - sudo npm install -g express
 - sudo npm install express -g
 - npm install express-generator
 - npm install -g express-generator
 - npm install express-generator -g
 - sudo npm install -g express-generator
 - sudo install express-generator -g
 - sudo npm install -g express-generator@3
 - sudo npm install -g express-generator@4
Run Code Online (Sandbox Code Playgroud)

但它仍然无法识别命令 express

这是我没有安装时的输出 -g

npm install express
express@4.13.3 node_modules/express
??? escape-html@1.0.2
??? …
Run Code Online (Sandbox Code Playgroud)

macos terminal node.js express

2
推荐指数
1
解决办法
5034
查看次数

无法使用jQuery更改选择值

我有一个非常简单的选择定义如下:

<select name='typedoc' id ='typedoc' size=1>
    <option>1</option>
    <option>2</option>
</select>
Run Code Online (Sandbox Code Playgroud)

有2个值,12.显示没问题.我无法使用jQuery更改该值.我试过了 :

$('[name=typedoc]').val('2');
Run Code Online (Sandbox Code Playgroud)

$('#typedoc').val('2');
Run Code Online (Sandbox Code Playgroud)

但是ddl仍然是第一选择.之前的行被执行,所以我确定该函数被调用.可能有什么不对?

html jquery dom

1
推荐指数
1
解决办法
7166
查看次数

标签 统计

json ×2

node.js ×2

php ×2

arrays ×1

bluebird ×1

dom ×1

eloquent ×1

express ×1

generator ×1

html ×1

javascript ×1

jql ×1

jquery ×1

koa ×1

laravel ×1

laravel-4 ×1

macos ×1

slim ×1

terminal ×1

unset ×1