我想通过生成随机用户名和密码自动生成用户帐户,然后用户自动登录(用户不知道他的用户名/密码,他的浏览器只存储会话cookie).
Passport作为中间件,所以如何验证我刚刚生成的用户?或者,以某种方式重定向到我的app.post('/login')路线并发送这些变量会更好吗?(但不知何故将这些发送到浏览器,只是被发送回服务器似乎不是非常安全或有效).
app.get('/signup', function(req, res) {
if(req.isAuthenticated()) { res.redirect('/'); }
else {
var today = new Date();
var weekDate = new Date();
weekDate.setDate(today.getDate() + 7);
var key1 = Math.random().toString();
var key2 = Math.random().toString();
var hash1 = crypto.createHmac('sha1', key1).update(today.valueOf().toString()).digest('hex');
var hash2 = crypto.createHmac('sha1', key2).update(weekDate.valueOf().toString()).digest('hex');
var newUser = new models.User({
username: hash1,
password: hash2,
signupDate: today,
accountStatus: 0,
expirationDate: weekDate,
});
newUser.save(function(err) {
if(err) {}
console.log("New user created.");
//HOW CAN I PASS USERNAME AND PASSWORD ARGUMENTS???
passport.authenticate('local')();
res.redirect('/login');
})
} …Run Code Online (Sandbox Code Playgroud) 我现在已经把头撞到了墙上一段时间了,我想我在这里错过了一些简单的东西.
我在我的Meteor服务器上运行它:
// --- Collections ---
Projects = new Meteor.Collection('projects');
Team = new Meteor.Collection('team');
// --- Only publish user data for users on my team ---
Meteor.publish('team', function() {
var team = Meteor.users.findOne({_id: this.userId}).profile._team;
console.log(Meteor.users.find({'profile._team': team}, {fields: {_id: 1, profile: 1}}).fetch());
return Meteor.users.find({'profile._team': team}, {fields: {_id: 1, profile: 1}});
});
Run Code Online (Sandbox Code Playgroud)
通过在profile._team属性中与当前登录用户具有相同ID的所有用户文档上运行查询,可以查找位于同一"团队"的所有用户.您将console.log(...);在发布函数中看到(在return语句之前的行),并且它正确地将我期望它的文档记录到终端中.
现在我在我的客户端上运行它:
// --- Data ---
Meteor.subscribe('team');
Team = new Meteor.Collection('team');
Template.team.team = function() {
console.log(Team.findOne());
return Team.find();
};
Run Code Online (Sandbox Code Playgroud)
但是,console.log(Team.findOne())始终记录undefined,Team.find()始终返回一个空数组.我做错了什么是阻止我的文件到达客户端?
更新: 这是模板代码. …
我想使用Peer.js通过 WebRTC 制作一个简单的纯音频流。我在本地运行简单的 PeerServer。
以下内容在 Firefox 30 中运行良好,但我无法在Chrome 35 中运行。我希望 PeerJS 设置有问题,但 Chrome -> Firefox 工作得很好,而 Chrome -> Chrome 似乎发送流,但不会通过扬声器播放。
设置 getUserMedia 注意:取消对下面这些行的注释将让我听到 Chrome 和 Firefox 中的环回。
navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
window.AudioContext = window.AudioContext || window.webkitAudioContext;
if(navigator.getUserMedia) {
navigator.getUserMedia({video: false, audio: true}, getMediaSuccess, getMediaError);
} else {
alert('getUserMedia not supported.');
}
var localMediaStream;
//var audioContext = new AudioContext();
function getMediaSuccess(mediaStream) {
//var microphone = audioContext.createMediaStreamSource(mediaStream);
//microphone.connect(audioContext.destination);
localMediaStream = mediaStream;
}
function …Run Code Online (Sandbox Code Playgroud) 我正在使用Node.js和nginx.我的节点应用程序基于快速构建,并使用护照进行身份验证并使用会话.我的节点应用程序响应所有/apiURL 上的JSON请求,nginx正在从公共目录提供静态文件.
我想nginx的服务index.html在/当用户没有登录,全心全意app.html为/当用户登录.
这是我目前的nginx配置.
upstream app_upstream {
server 127.0.0.1:3000;
keepalive 64;
}
server {
listen 0.0.0.0:80;
server_name app.com default;
access_log /var/log/nginx/app.com.access.log;
error_log /var/log/nginx/app.com.error.log debug;
root /home/app/app/public;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass 1;
proxy_no_cache 1;
expires off;
if_modified_since off;
add_header Last-Modified "";
proxy_pass http://app_upstream;
proxy_redirect off;
}
location / {
access_log off;
expires max;
}
}
Run Code Online (Sandbox Code Playgroud)
如何让nginx确定用户是否登录,然后相应地提供不同的文件?我注意到express创建了一个名为的cookie connect.sid,但是当用户注销时它似乎没有消失.
我的目标是这个效果:(仅水平轮廓线):

我确实找到了这个例子,但它创建了水平和垂直轮廓线.我无法完全理解调用fwidth()生成线的方式.
uniform float gsize;//size of the grid
uniform float gwidth;//grid lines'width in pixels
varying vec3 P;
void main()
{
vec3 f = abs(fract (P * gsize)-0.5);
vec3 df = fwidth(P * gsize);
float mi=max(0.0,gwidth-1.0), ma=max(1.0,gwidth);//should be uniforms
vec3 g=clamp((f-df*mi)/(df*(ma-mi)),max(0.0,1.0-gwidth),1.0);//max(0.0,1.0-gwidth) should also be sent as uniform
float c = g.x * g.y * g.z;
gl_FragColor = vec4(c, c, c, 1.0);
gl_FragColor = gl_FragColor * gl_Color;
}
Run Code Online (Sandbox Code Playgroud)
如何将该示例修改为仅水平线?
有更好的解决方案吗?
更新:
修改后的着色器解决方案.仅使用y值来使用浮点数.
void main() …Run Code Online (Sandbox Code Playgroud) 当我的Node应用程序启动时,它会尝试连接到数据库,如下所示:
var db = mongoose.connect('mongodb://what:ever.com:1234/database', function(err) {
if(err) console.log('MongoDB: connection error -> ' + err);
else console.log('MongoDB: successfully connected');
});
Run Code Online (Sandbox Code Playgroud)
当它失败时,我会得到完全符合我预期的错误,但我的Node应用程序终止.当连接返回错误时,如何让节点应用程序继续运行?
有人能指出我对长期应用程序的Mongoose最佳实践方向吗?我知道默认情况下Mongoose的重试连接标志设置为true,但我还应该做什么?
我想在我的AngularJS应用程序中实现promises,就像你在这个例子中看到的那样:https: //stackoverflow.com/a/12360882/371273
我的应用程序将采用多个数据阵列,在我的服务器上进行多次数据库命中,但我已将我的服务器配置为将所有数据作为一个响应返回,以最大限度地减少请求以保持我的应用程序尽可能高效(数据基本上是除非所有数据都到达客户端,否则无用).所以不要这样做......
MyCtrl.resolve = {
projects : function($q, $http) {
return $http.get('/api/projects'});
},
clients : function($q, $http) {
return $http.get('/api/clients'});
}
};
Run Code Online (Sandbox Code Playgroud)
我希望能够向一个URL 发出一个单一的 $http GET请求/api/allData,然后projects将其设置为等于,并将对此allData.projects的承诺clients设置为allData.clients等等.(allData返回的数据在哪里)我的单一要求).我对承诺还很新,有人能给我一个例子,告诉我如何在里面设立这些承诺MyCtrl.resolve吗?
有人可以告诉我为什么这不起作用?
NSAppleScript* playPause = [[NSAppleScript alloc] initWithSource:
@"\
tell application \"System Events\"\n\
tell application \"Final Cut Pro\" to activate\n\
keystroke \" \"\
end tell"];
Run Code Online (Sandbox Code Playgroud)
我收到错误"预期':'','';' ' ='标记之前的'}'或' attribute '.WTF?
谢谢你的帮助!
node.js ×3
express ×2
passport.js ×2
angularjs ×1
api ×1
applescript ×1
asynchronous ×1
cocoa ×1
firefox ×1
glsl ×1
javascript ×1
meteor ×1
mongodb ×1
mongoose ×1
nginx ×1
objective-c ×1
opengl ×1
peerjs ×1
session ×1
webgl ×1
webrtc ×1