小编Ken*_*Ken的帖子

如何使用PHP正确添加CSRF令牌

我正在尝试为我网站上的表单添加一些安全性.其中一种形式使用AJAX,另一种形式是直接的"联系我们"形式.我正在尝试添加CSRF令牌.我遇到的问题是令牌只在某些时候出现在HTML"值"中.剩下的时间,值是空的.这是我在AJAX表单上使用的代码:

PHP:

if (!isset($_SESSION)) {
    session_start();
$_SESSION['formStarted'] = true;
}
if (!isset($_SESSION['token']))
{$token = md5(uniqid(rand(), TRUE));
$_SESSION['token'] = $token;

}
Run Code Online (Sandbox Code Playgroud)

HTML

 <form>
//...
<input type="hidden" name="token" value="<?php echo $token; ?>" />
//...
</form>
Run Code Online (Sandbox Code Playgroud)

有什么建议?

php security session csrf

81
推荐指数
2
解决办法
10万
查看次数

如何在Angular 2中解析xml

我使用的是使用XML而不是JSON的API.有关如何将以下XML转换为JSON或如何在ngFor指令中正确使用数据的任何建议?

此外,观察是否适合这里?

<case-file>
  <serial-number>123456789</serial-number>
    <transaction-date>20150101</transaction-date>
      <case-file-header>
       <filing-date>20140101</filing-date>
      </case-file-header>
 // ...
   <classifications>
  <classification>
   <international-code-total-no>1</international-code-total-no>
   <primary-code>025</primary-code>
  </classification>
 </classifications>
 </case-file>
 <case-file>
     <serial-number>234567890</serial-number>
    <transaction-date>20160401</transaction-date>
      <case-file-header>
       <filing-date>20160401</filing-date>
      </case-file-header>
//...
   <classifications>
  <classification>
   <international-code-total-no>1</international-code-total-no>
   <primary-code>042</primary-code>
  </classification>
 </classifications>
</case-file>
Run Code Online (Sandbox Code Playgroud)
export class apiService {
   constructor (private http: Http) {}

   private _apiUrl = 'app/api';  

   getCaseFile () {
     return this.http.get(this._apiUrl)
//conversion to JSON here?
                    .map(res => <CaseFile[]> res.json().data)
                     .catch(this.handleError);
   }
    private handleError (error: Response) {

     console.error(error);
    return Observable.throw(error.json().error || 'Server error');
   }
 }

<div *ngFor="#cf of case-file">{{case-file.serial-number}}</div>
Run Code Online (Sandbox Code Playgroud)

xml observable typescript angular

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

如何使用Node从URL解析XML

我使用node-xml2js来解析XML.我在从URL解析XML时遇到问题.我用这个SO答案作为模型.但是当我使用下面的代码时,我得到null了结果.对我做错了什么的想法?

更新:我已将xml的url更新为使用的实际站点.

var eyes = require('eyes');
var https = require('https');
var fs = require('fs');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();

parser.addListener('end', function(result) {
  eyes.inspect(result);
  console.log('Done.');
});

https.get('https://tsdrapi.uspto.gov/ts/cd/casestatus/sn78787878/info.xml', function(result) {
  result.on('data', function (data) {
    parser.parseString(data);
    });
  }).on('error', function(e) {
  console.log('Got error: ' + e.message);
});
Run Code Online (Sandbox Code Playgroud)

xml node.js xml-parsing express

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

如何在不使用提交按钮的情况下触发验证

我正在使用jQuery Validation插件并尝试使用备用按钮触发验证/提交.我想创建一个jquery函数,它将改变css,然后运行validate函数.我查看了之前已回答的问题,但没有找到任何解决此问题的Validation插件和submitHandler函数.有什么建议?

更新到问题:我想要使用的按钮放在表单之外.使用位于该表单之外的按钮提交和验证表单的最佳方法是什么?

这是代码:

$("#edit-button").click(function(event) {

$('#postAccordion2').css('padding-bottom', '0px');
$('#edit-button').css('display','none');
$("#applicant-form").validate({
    submitHandler: function(form) {
            $(form).ajaxSubmit({                  
                type: "POST",
                data: {
                    "firstName" : $('#firstName').val(),
                    "lastName" : $('#lastName').val()
                    },
                dataType: 'json',
                url: './includes/ajaxtest.php',
                error: function() {alert("doh!");},
                success: function() {alert("yippee!");},

    }    

  });

return false;   
   },
        errorPlacement: function(error,element) {
                        return true;
                },
        rules: {
            "firstName": {
                required: true,
                minlength: 1
                },  
            "lastName": {
                required: true
                }
        }


});
   });
Run Code Online (Sandbox Code Playgroud)

validation ajax jquery plugins

14
推荐指数
2
解决办法
3万
查看次数

如何在Lodash中遍历数组中的对象

我正在尝试在HTML模板中使用lodash来获取Node.js中的电子邮件.我有一个包含多个对象的数组.我想迭代每个对象并列出所有重复值.当我使用下面的代码时,我收到一个错误,指出该值未定义(例如,ReferenceError: firstName is not defined).HTML模板位于单独的文件中.

对我做错了什么的想法?

使用Javascript:

var template = fs.readFileSync('server/views/email-template.html').toString();
var htmlAll = _.template(template)(orderInfo);
Run Code Online (Sandbox Code Playgroud)

HTML:

<% _.forEach(function(firstName) { %><%- firstName %></td><% }); %> <% _.forEach(function(lastName) { %><%- lastName %></td><% }); %>
<% _.forEach(function(address) { %><%- address %></td><% });%>
<% _.forEach(function(city) { %><%- city %><% }); %>, <% _.forEach(function(state.code) { %><%- state.code %><% });
%> <% _.forEach(function(zip) { %><%- zip %><% }); %>

<% _.forEach(function(item) { %><td><%- item %></td><% }); %>
<% _.forEach(function(cost) { %><td><%- cost %></td><% }); …
Run Code Online (Sandbox Code Playgroud)

node.js underscore.js lodash

14
推荐指数
2
解决办法
3万
查看次数

将大型XML文件转换为关系数据库

我正在努力找出实现以下目标的最佳方法:

  1. 每天从第三方网站下载大型XML(1GB)文件
  2. 将该XML文件转换为我的服务器上的关系数据库
  3. 添加搜索数据库的功能

对于第一部分,这是需要手动完成的事情,还是可以用cron完成?

与XML和关系数据库相关的大多数问题和答案都是指Python或PHP.这可以用javascript/nodejs完成吗?

如果这个问题更适合不同的StackExchange论坛,请告诉我,我会把它移到那里.

下面是xml代码的示例:

<case-file>
  <serial-number>123456789</serial-number>
    <transaction-date>20150101</transaction-date>
      <case-file-header>
       <filing-date>20140101</filing-date>
      </case-file-header>
      <case-file-statements>
       <case-file-statement>
        <code>AQ123</code>
        <text>Case file statement text</text>
       </case-file-statement>
       <case-file-statement>
        <code>BC345</code>
        <text>Case file statement text</text>
       </case-file-statement>
     </case-file-statements>
   <classifications>
  <classification>
   <international-code-total-no>1</international-code-total-no>
   <primary-code>025</primary-code>
  </classification>
 </classifications>
</case-file>
Run Code Online (Sandbox Code Playgroud)

以下是有关如何使用这些文件的更多信息:

所有XML文件都采用相同的格式.每条记录中可能有几十个元素.这些文件每天由第三方更新(并在第三方网站上以压缩文件的形式提供).每天的文件代表新的案例文件以及更新的案例文件.

目标是允许用户搜索信息并在页面上(或在生成的pdf/excel文件中)组织这些搜索结果.例如,用户可能希望查看包含<text>元素内特定单词的所有案例文件.或者用户可能希望查看包含主代码025(<primary-code>元素)的所有案例文件以及在特定日期(<filing-date>元素)之后提交的案例文件.

输入数据库的唯一数据来自XML文件 - 用户不会将任何自己的信息添加到数据库中.

javascript python xml relational-database node.js

11
推荐指数
2
解决办法
1195
查看次数

如何在Firebase中会话到期时使用UI路由器重定向

我正在使用Angular和Firebase以及UI路由器.我正在使用匿名身份验证.当会话到期时,我希望将未经身份验证的用户重定向到主页.我使用了Yeoman Angularfire Generator作为模型.但是当我使用下面的代码时,当用户已经在该页面上并且会话到期时,经过身份验证的页面不会重定向.

.config(['$urlRouterProvider', 'SECURED_ROUTES', function($urlRouterProvider, SECURED_ROUTES) {
    $urlRouterProvider.whenAuthenticated = function(path, route) {
        route.resolve = route.resolve || {};
        route.resolve.user = ['Auth', function(Auth) {
            return Auth.$requireAuth();
        }];
        $urlRouterProvider.when(path, route);
        SECURED_ROUTES[path] = true;
        return $urlRouterProvider;
    };
}])
.run(['$rootScope', '$location', 'Auth', 'SECURED_ROUTES', '$state',
    function($rootScope, $location, Auth, SECURED_ROUTES, $state) {

        Auth.$onAuth(check);

        $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {

            if (error === 'AUTH_REQUIRED') {
                $state.go('home');
            }
            else {
                console.log('authenticated');
            }
        });

        function check(user) {

            if (!user && authRequired($location.path())) {

                $state.go('home');
            }
        }

        function authRequired(path) …
Run Code Online (Sandbox Code Playgroud)

angularjs firebase firebase-security angularfire angular-ui-router

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

如何验证Selenium IDE中属性中是否存在特定文本

我想验证href属性中的URL是否包含某些文本.例如,如果URL包含"foo",则测试应该继续.如果它不包含"foo",则测试应该停止.我不清楚我是应该使用assertAttribute还是assertText,还是其他东西.我也不清楚确切的语法是什么.

<a href="www.example.com/foo">Link 1</a>
<a href="www.example.com/questions">Link 2</a>
Run Code Online (Sandbox Code Playgroud)

任何有关这方面的指导都将非常感激.

html testing selenium

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

如何在成功提交其他表格后提交第二份表格

我正在使用Angular与UI路由器和Firebase.在一个页面上有两种形式的两种形式:联系表格和信用卡表格.

当用户点击提交时,信用卡信息将提交给Stripe.然后,只有在信用卡交易成功完成后,才会将联系表单提交给Firebase.以下代码适用于开发.但是当代码缩小时,联系表单永远不会被提交.

对我做错了什么的想法?

联系表格控制器:

.controller('ContactFormCtrl', ['$scope', 'Contacts', 'serviceB',  function ($scope, Contacts, serviceB) {
  var contactForm = this;
  var stripeDone = serviceB.get();
  contactForm.contact = {};
  contactForm.contacts = Contacts;

  $scope.$watch(serviceB.get, function(stripeDone) {
    if (stripeDone === 'yes') {
      console.log(contactForm.contact);
      Contacts.$add(contactForm.contact)
 } else {
      console.log('Card not charged');
       }
 }])
Run Code Online (Sandbox Code Playgroud)

信用卡表格控制器:

.controller('PaymentFormCtrl', ['$scope', '$http', 'serviceB', function ($scope, $http, serviceB) {

    $scope.handleStripe = function (status, response) {

    var stripeDone='yes';

        return $http.post(http://localhost:9000/api/payments, JSON.stringify(response))
       .then(function() {
         serviceB.set(stripeDone);console.log('serviceB set now',stripeDone);})
       .then(function() {$scope.payment={};
       })
       .then(function() {$state.go('thankyou');})
}]);
Run Code Online (Sandbox Code Playgroud)

ServiceB服务:

(function() { …
Run Code Online (Sandbox Code Playgroud)

angularjs firebase angularfire angular-ui-router

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

如何更新会话变量

我正在使用Ajax创建一个多步骤表单,并希望根据表单字段的值更改显示的文本.我认为这样做的好方法是使用会话变量.如何使用新字段值告知会话更新?目前,会话似乎只存储初始值,但不存储任何更新.因此,如果用户输入"John"作为名字,然后又返回并将其更改为"Frank",则"John"是存储的名称.

if (!isset($_SESSION)) {
session_start();
$_SESSION['formStarted'] = true;
$_SESSION['timestamp'] = date("M d Y H:i:s");
$_SESSION[$key] = $value;

<p>Your name begins with the letter <?php if ($_SESSION['name'] =='Frank') 
  {echo 'F';}?><p>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#form").validate({
   //...
   submitHandler: function(form) {

   //... 
   $(form).ajaxSubmit({               
     type: "POST",
     data: {
       name : $('#name').val(),
//...
     },
     dataType: 'json',
     url: '../ajaxtest.php',
     error: function() {alert("There was an error processing this page.");},
     success: 
       function(data) {
         $('#output1').html(data.message.join(' ')).show(500);
         $('#ouput1').append(data);
//...
Run Code Online (Sandbox Code Playgroud)

ajaxtest.php:

session_start();

$expected = array( 
'name'=>'string', 
//...
);

//...

$return['message']=array();
if(!empty($_POST['name'])){
   $return['message'][] = '' …
Run Code Online (Sandbox Code Playgroud)

php ajax multipartform-data session-variables

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