我在我的应用程序中使用Passport进行身份验证,我也在使用Express.总结一下我的问题:我的登录功能最初工作正常,但在任何用户的会话超时后,没有用户能够登录.
我使用标准的本地策略进行身份验证.
我会根据我的设置尽可能包含一个例子:
//-------------
//Set up authentication with Passport
//-------------
var userModel = require('./models/user')(db);
passport.use(new LocalStrategy(
function(username, password, done) {
var errorMessage = 'Incorrect username/password combination.';
userModel.GetUserByUsername(username, function(err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: errorMessage });
}
user.validatePassword(password, function(isPasswordCorrect) {
if (!isPasswordCorrect)
{
return done(null, false, { message: errorMessage });
}
//Update with login date
userModel.UpdateUserWithLogin(username, user.currentLoginTime, function(err){
//if we have an error here, we …
Run Code Online (Sandbox Code Playgroud) 我正在Node.js中使用一个非常基本的注册表单(使用Express),我正在尝试找到提供基本表单验证的最简单方法.我已经选择了"Express-Validator",这似乎做得很好.但是,我的目标是只显示所需的任何验证消息,并保留用户单独输入的值.
似乎请求信息没有回到res.render,我认为这是有意义的.但是,我看到了我能想到的任何地方,我找不到任何讨论如何在显示错误消息后保持表单字段填充的参考.
下面是一个描述我的方法的小片段:
post: function(req, res){
var userName = req.body.username;
var password = req.body.password;
//Validate input
req.assert("username", 'Invalid email address.').isEmail();
req.assert("password", 'Password cannot be empty.').notEmpty();
req.assert("passwordConfirm", 'Passwords entered do not match!').equals(password);
//Make sure we have no validation errors
var pageErrors = req.validationErrors();
if(!pageErrors)
{
userModel.CreateUser(userName, password, function(err){
if(err)
{
//there was a problem inserting new user... probably already exists
//will need to check the error to confirm
var dbErrorMessage = "Could not insert record into database!";
if(err.code === 11000) …
Run Code Online (Sandbox Code Playgroud) 我正在使用Namecheap进行域名注册和DNS,并使用Heroku进行托管。我已经通过Namecheap购买了SSL证书,并使用Heroku对其进行了设置,并使它几乎可以正常工作。
目前,我有一个DNS CNAME记录,其中主机“ www”指向“ [whatever] .herokussl.com。”,一个“ @”主机记录设置为URL重定向(301)到“ http:// www。[domain。 ] .com”。
我的应用程序本身强制所有HTTP通信重定向到HTTPS,因此“ http:// www。[domain] .com”转到“ https:// www。[domain] .com”。
我得到以下结果:
http://www.[domain].com - properly navigates to site as HTTPS
https://www.[domain].com - properly navigates to site as HTTPS
http://[domain].com - properly navigates to site as HTTPS
https://[domain].com - **does not** navigate to site, and instead the browser cannot find the page
Run Code Online (Sandbox Code Playgroud)
我认为这与URL重定向在后台的行为有关。我最初是作为CNAME记录直接指向“ [whatever] .herokussl.com。”来完成此操作的,但显然是在区域顶点上阻止了MX记录...
我需要做些什么才能得到想要的行为?我只是希望所有裸域或“ www”域都指向我的“ www”域。
更新:有关我的DNS设置的更多信息
HOST NAME IP ADDRESS/URL RECORD TYPE
--------- -------------- -----------
@ http://www.[domain].com URL Redirect (301)
www …
Run Code Online (Sandbox Code Playgroud)