fix(core): fixed limited ip for admin center issue

This commit is contained in:
OldHawk
2018-04-23 16:09:40 +08:00
parent 65e31da45b
commit 34ddd451bb
4 changed files with 25 additions and 6 deletions

View File

@@ -5,9 +5,9 @@
.module('core')
.run(routeFilter);
routeFilter.$inject = ['$rootScope', '$state', 'Authentication', 'MeanTorrentConfig'];
routeFilter.$inject = ['$rootScope', '$state', 'Authentication', 'MeanTorrentConfig', 'UsersService'];
function routeFilter($rootScope, $state, Authentication, MeanTorrentConfig) {
function routeFilter($rootScope, $state, Authentication, MeanTorrentConfig, UsersService) {
$rootScope.$on('$stateChangeStart', stateChangeStart);
$rootScope.$on('$stateChangeSuccess', stateChangeSuccess);
@@ -41,11 +41,14 @@
} else {
if (toState.name.startsWith('admin.')) {
var adminAccessConfig = MeanTorrentConfig.meanTorrentConfig.adminAccess;
if (adminAccessConfig.limit) {
if (Authentication.user && !adminAccessConfig.limitedIp.includes(Authentication.user.curr_signed_ip)) {
event.preventDefault();
$state.transitionTo('access-deny');
}
UsersService.getMyIp(function (res) {
if (Authentication.user && !adminAccessConfig.limitedIp.includes(res.ip)) {
event.preventDefault();
$state.transitionTo('access-deny');
}
});
}
}
}

View File

@@ -89,6 +89,10 @@
method: 'GET',
url: '/api/users/:userId/following',
isArray: true
},
getMyIp: {
method: 'GET',
url: '/api/users/myIp'
}
});

View File

@@ -288,3 +288,14 @@ exports.unIdle = function (req, res, next) {
});
}
};
/**
* getMyIp
* @param req
* @param res
*/
exports.getMyIp = function (req, res) {
res.status(200).send({
ip: req.user.curr_signed_ip
});
};

View File

@@ -6,6 +6,7 @@ module.exports = function (app) {
// Setting up the users profile api
app.route('/api/users/me').get(users.me);
app.route('/api/users/myIp').get(users.getMyIp);
app.route('/api/users').put(users.update);
app.route('/api/users/accounts').delete(users.removeOAuthProvider);
app.route('/api/users/password').post(users.changePassword);