繁体   English   中英

登录成功后重定向或在环回框架中失败

[英]Redirection after the login succeeds or fails in loopback framework

我最近开始使用loopback框架并通过创建一个继承自base'User'的'customer'模型来创建一个简单的登录功能,如下所示:

CUSTOMER.JSON

{
    "name": "customer",
    "base": "User",
    "idInjection": true,
    "properties": {
        "email":{
            "type":"string",
            "required":false
        },
        "username":{
            "type":"string",
            "required":false
        }

    },
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": []
}

CUSTOMER.JS

module.exports = function(customer){

  }

然后我在model-config.json中创建了一个条目,如下所示:

"customer": {
        "dataSource": "mango-database",
        "public": true
    }

是的,我能够轻松登录和注销。 我有一个登录界面,其中包含用户名和密码字段。 我将此表单提交给客户/登录,一旦登录,我就会看到一个屏幕:

{
id: "lvrTjKBKXCFPTMFej6AyegQUFYe5mSc1BiYbROZwCBM0jqae7kZ7v8ZfGujfDGgy",
ttl: 1209600,
created: "2014-12-07T08:12:17.572Z",
userId: "5483e88b5e9cf2fe0c64dd6c"
}

现在我想要而不是这个屏幕,我应该能够将用户重定向到其他页面(仪表板),如果登录失败,它应该返回到登录屏幕。

我在这上面搜索了很多,我找到的只是使用钩子的建议。 但钩子没有这样的事件。 我在哪里写重定向功能? 我的猜测是CUSTOMER.JS

我发现文档很安静!

使用远程钩子中提供的context.res 例如:

Customer.afterRemote('create', function(context, customer, next) {
  var res = context.res; //this is the same response object you get in Express
  res.send('hello world');
})

基本上,您可以访问请求和响应对象,因此只需像在Express中一样进行响应。 有关详细信息,请参阅http://expressjs.com/4x/api.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM