Sails.js Waterlock /认证/注册会导致错误500 [英] Sails.js Waterlock /auth/register causes error 500

查看:254
本文介绍了Sails.js Waterlock /认证/注册会导致错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图让Waterlock不创建登录新用户。

In trying to make Waterlock not to create new user on login.

当我设置 createOnNotFound ,并尝试使用的http://本地主机:?1337 /认证/注册email=a@s.d&密码= 12345678 来注册一个新用户。我有 500 错误:

When I set createOnNotFound to false and try to use http://localhost:1337/auth/register?email=a@s.d&password=12345678 to register a new user. I've got 500 error:

error: Sending 500 ("Server Error") response: TypeError: undefined is not a function
at Object.module.exports (D:\temp\sails-waterlock\node_modules\waterlock\lib\controllers\actions\register.js:25:44)
at bound (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21)
at routeTargetFnWrapper (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:179:5)
at callbacks (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37)
at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11)
at pass (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5)
at nextRoute (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:100:7)
at callbacks (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:167:11)
at C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:187:7
at alwaysAllow (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\hooks\policies\index.js:207:11)
at routeTargetFnWrapper (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\lib\router\bind.js:179:5)
at callbacks (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37)
at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
at param (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11)
at pass (C:\Users\sandres\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) [TypeError: undefined is not a function]

寄存器模块 ,其中错误情况是 waterlock 库的一部分。

下面那张寄存器模块的code,因为它现在是:

Here goes the code of the register module as it is now:

'use strict';

/**
 * login action
 *
 * tries to find if we have an auth method to handle this type of login
 * request.
 *
 * GET /auth/login
 */
module.exports = function(req, res){
   var params = waterlock._utils.allParams(req);

  // If there is only 1 chosen auth method just assume it
  if(waterlock._utils.countTopLevel(waterlock.methods) === 1){
    params.type = waterlock._utils.accessObjectLikeArray(0, waterlock.methods).authType;
  }

  if(typeof params.type === 'undefined'){
    return res.badRequest('You must specify a type parameter.');
  }

  if(waterlock.methods.hasOwnProperty(params.type)){
    // call the login function of the correct auth type
    waterlock.methods[params.type].actions.register(req, res);
  }else{
    return res.badRequest('unknown/invalid authentication type');
  }
};

帆v 0.11,Waterlock v 0.1.0

Sails v 0.11, Waterlock v 0.1.0

我怎么能现在就注册用户?

How can I register user now?

更新:

此情况发生的原因进行登记行动尚未 waterlock本地-auth的实施
模块I用于身份验证。请参见这个PR 了解详情。

This happens due to register action is not yet implemented in waterlock-local-auth module I use for authentication. See this PR for details.

所以更新的问题是:如何围绕这个工作,直到实现将完成

So the updated question is: how to work this around until the implementation will be done?

推荐答案

我在 /controllers/AuthController.js 自定义登记行动解决了这个:

I've solved this with custom registration action in /controllers/AuthController.js:

module.exports = require('waterlock').waterlocked({

    register: function(req, res) {
        var params = req.params.all(),
                        def = waterlock.Auth.definition,
                        criteria = { },
                        scopeKey = def.email !== undefined ? 'email' : 'username';

        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);
                });
        });
    }

});

这是exactely我所需要的。

This is exactely what I need.

韦恩-O ,Waterlock贡献者之一,的 说,他将完成他的执行登记在 waterlock本地-auth的

Meanwhile Wayne-o, one of Waterlock contributors, said that he will finish his implementation of registration in waterlock-local-auth.

这篇关于Sails.js Waterlock /认证/注册会导致错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆