2023-01-03 22:10:39 +00:00
|
|
|
const { WellKnownLocations } = require('./servers/content/web');
|
2023-01-04 03:32:09 +00:00
|
|
|
const User = require('./user');
|
|
|
|
const { Errors } = require('./enig_error');
|
|
|
|
const UserProps = require('./user_property');
|
2023-01-03 22:10:39 +00:00
|
|
|
|
2023-01-04 03:32:09 +00:00
|
|
|
exports.makeUserUrl = makeUserUrl;
|
|
|
|
exports.webFingerProfileUrl = webFingerProfileUrl;
|
|
|
|
exports.selfUrl = selfUrl;
|
|
|
|
exports.userFromAccount = userFromAccount;
|
2023-01-03 22:10:39 +00:00
|
|
|
|
2023-01-04 03:32:09 +00:00
|
|
|
function makeUserUrl(webServer, user, relPrefix) {
|
2023-01-03 22:10:39 +00:00
|
|
|
return webServer.buildUrl(
|
|
|
|
WellKnownLocations.Internal + `${relPrefix}${user.username}`
|
|
|
|
);
|
|
|
|
}
|
2023-01-04 03:32:09 +00:00
|
|
|
|
|
|
|
function webFingerProfileUrl(webServer, user) {
|
|
|
|
return webServer.buildUrl(WellKnownLocations.Internal + `/wf/@${user.username}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function selfUrl(webServer, user) {
|
|
|
|
return makeUserUrl(webServer, user, '/ap/users/');
|
|
|
|
}
|
|
|
|
|
|
|
|
function userFromAccount(accountName, cb) {
|
|
|
|
User.getUserIdAndName(accountName, (err, userId) => {
|
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
User.getUser(userId, (err, user) => {
|
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const accountStatus = user.getPropertyAsNumber(UserProps.AccountStatus);
|
|
|
|
if (
|
|
|
|
User.AccountStatus.disabled == accountStatus ||
|
|
|
|
User.AccountStatus.inactive == accountStatus
|
|
|
|
) {
|
|
|
|
return cb(Errors.AccessDenied('Account disabled', ErrorReasons.Disabled));
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(null, user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|