当我单击电子邮件中的认证链接来实现使用电子邮件认证的成员资格方法时,我想在服务器内部确认令牌之后调用用户创建API。我想知道如何在控制器之间进行通信
//emailcontroller.js
router.get('/register/token', function(req, res) {
// check token
if(check(req.params.token)) {
request('http://localhost:8080/api/user', function(data) {
});
}
});
//usercontroller.js
router.post('/api/user', function(req, res) {
var user = new User();
user.userId = req.body.userId;
user.userPw = req.body.userPw;
user.save();
});
我要调用的用户创建API内部确认在服务器中的令牌后,当我点击,才能在电子邮件认证链接使用电子邮件认证来实现会员的方法。
如上所述,电子邮件控制器和用户控制器被分开,并且每个都被路由。我想模块化代码,以便我想调用现有的用户创建API将其用于通用目的,而不是为特定控制器创建和导出常用功能。
/*I do not want to implement it this way.*/
//emailController.js
router.get('/register/token', function(req, res) {
// check token
if(check(req.params.token)) {
userContoller.createUserFromEmail(userId, userPw);
}
});
//userController.js
exports.createUserFromEmail = function(userId, userPw) {
var user = new User();
user.userId = userId;
user.userPw = userPw;
user.save();
}
但是,在许多例子中,我从来没有见过控制器之间的通信。所以我不知道我认为是对的。相反,我认为在服务器上调用API的成本可能会更高。
我想知道控制器之间通信的正确模式。请记住,提出问题时只有堆栈溢出。
你的意思是,当用户点击电子邮件中,你要拨打的用户链接/创建路线? 你的问题是不透明的。请解释一下 –