从服务器端表单进行 Waterlocks 身份验证
Waterlocks authentication from server side form
我在使用 waterlock-local-auth 时遇到问题。基本上我整天都在玩水锁,试图弄清楚如何创建一个新用户(使用散列密码和所有),以及如何从服务器端 sails.js 视图上的表单对用户进行身份验证。但是一直都没有成功。下面是我的登录表单发布到的 LoginController 中的代码。任何帮助将不胜感激。谢谢!
module.exports = {
login: function(req, res) {
var isAuthenticated = function(){...} <-- Authenticated by waterlocks
if(isAuthenticated) {
res.view('home');
}
else {
res.view('login', {errorMessage: "Invalid username or password"});
}
}
};
好的,基本上我使用了此处发布的解决方案 ()。 ;0)
module.exports = require('waterlock').waterlocked({
// Endpoint for registering new users. Taken from:
register: function (req, res) {
var params = req.params.all(),
def = waterlock.Auth.definition,
criteria = {},
scopeKey = def.email !== undefined ? 'email' : 'username'; // Determines if the credentials are using username or emailaddess.
var attr = { password: params.password }
attr[scopeKey] = params[scopeKey];
criteria[scopeKey] = attr[scopeKey];
waterlock.engine.findAuth(criteria, function (err, user) {
if (user)
return res.badRequest("User already exists");
else
waterlock.engine.findOrCreateAuth(criteria, attr, function (err, user) {
if (err)
return res.badRequest(err);
delete user.password;
return res.ok(user);
});
});
}
});
我在使用 waterlock-local-auth 时遇到问题。基本上我整天都在玩水锁,试图弄清楚如何创建一个新用户(使用散列密码和所有),以及如何从服务器端 sails.js 视图上的表单对用户进行身份验证。但是一直都没有成功。下面是我的登录表单发布到的 LoginController 中的代码。任何帮助将不胜感激。谢谢!
module.exports = {
login: function(req, res) {
var isAuthenticated = function(){...} <-- Authenticated by waterlocks
if(isAuthenticated) {
res.view('home');
}
else {
res.view('login', {errorMessage: "Invalid username or password"});
}
}
};
好的,基本上我使用了此处发布的解决方案 (
module.exports = require('waterlock').waterlocked({
// Endpoint for registering new users. Taken from:
register: function (req, res) {
var params = req.params.all(),
def = waterlock.Auth.definition,
criteria = {},
scopeKey = def.email !== undefined ? 'email' : 'username'; // Determines if the credentials are using username or emailaddess.
var attr = { password: params.password }
attr[scopeKey] = params[scopeKey];
criteria[scopeKey] = attr[scopeKey];
waterlock.engine.findAuth(criteria, function (err, user) {
if (user)
return res.badRequest("User already exists");
else
waterlock.engine.findOrCreateAuth(criteria, attr, function (err, user) {
if (err)
return res.badRequest(err);
delete user.password;
return res.ok(user);
});
});
}
});