나는 mean.js를 사용하여 등록 된 사용자가 콘텐츠에 액세스하도록합니다. 그것은 일종의 일입니다. 사람들이 내용을 볼 수 있도록 isAllowed를 isAllowed로 변경할 수 있습니다. 문제는 사용자가 로그인 할 때 콘텐츠가 승인되지 않는다는 것입니다. 기사 예제가 정상적으로 작동합니다. 하지만 내 섹션을 만들면 로그인 한 사용자는 페이지에 액세스 할 수 없습니다!사용자 승인이 Mean.JS에서 작동하지 않습니다.
그래서 기본적으로 내가 로그인하는 경우, 나는 메시지가 :! 3000/requestoffwork
내가 로그인 및 isAllowed에 isAllowed을 변경하는 경우, 나는 그것을 액세스 할 수 있습니다 내가 localhost로가는하려고하면 '사용자가 권한이 없습니다'
'use strict';
/**
* Module dependencies.
*/
var acl = require('acl');
// Using the memory backend
acl = new acl(new acl.memoryBackend());
/**
* Invoke Articles Permissions
*/
exports.invokeRolesPolicies = function() {
acl.allow([{
roles: ['admin'],
allows: [{
resources: '/api/articles',
permissions: '*'
}, {
resources: '/api/articles/:articleId',
permissions: '*'
}]
}, {
roles: ['user'],
allows: [{
resources: '/requestoffwork',
permissions: '*'
}, {
resources: '/api/articles/:articleId',
permissions: ['get']
}]
}, {
roles: ['guest'],
allows: [{
resources: '/api/articles',
permissions: ['get']
}, {
resources: '/api/articles/:articleId',
permissions: ['get']
}]
}]);
};
/**
* Check If Articles Policy Allows
*/
exports.isAllowed = function (req, res, next) {
var roles = (req.user) ? req.user.roles : ['guest'];
// If an article is being processed and the current user created it then allow any manipulation
if (req.article && req.user && req.article.user.id === req.user.id) {
return next();
}
// Check for user roles
acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) {
if (err) {
// An authorization error occurred.
return res.status(500).send('Unexpected authorization error');
} else {
if (isAllowed) {
// Access granted! Invoke next middleware
return next();
} else {
return res.status(403).json({
message: 'User is not authorized'
});
}
}
});
};
이
는 경로app.route('/requestoffwork').all(managementPolicy.isAllowed)
.get(management.list)
.post(management.submit);
입니다 그리고 여기에 사용자
에 대한 데이터를의 0{"_id":"5788fe46587a1c0b07a04078","displayName":"","provider":"local","__v":0,"created":"2016-07-15T15:16:22.625Z","roles":["user"],"profileImageURL":"modules/users/client/img/profile/default.png","email":"[email protected]","lastName":"","firstName":”"}
@ 루크 크론 (Luke Kroon)이라는 명성 점수가 15 점이라면 나는이 제안을 포기할 것이다. 문제는 admin 모듈에서 "사용자 직렬화 해제"부분입니다. 나는 그것을 나의 새로운 모듈에 추가했고 그것은 효과가 있었다! 누군가가 이것을 읽고 도움이되기를 바랍니다. upvoting하지 미안 해요, 루크 :) –