2019-11-16 19:25:44 -05:00
|
|
|
/* eslint-disable consistent-return */
|
|
|
|
import { Server } from '..';
|
|
|
|
import { Route } from '../../class';
|
|
|
|
|
|
|
|
export default class Account extends Route {
|
|
|
|
constructor(server: Server) {
|
|
|
|
super(server, { path: '/account', deprecated: false });
|
|
|
|
}
|
|
|
|
|
2019-11-16 19:51:29 -05:00
|
|
|
public bind() {
|
2019-11-16 19:25:44 -05:00
|
|
|
this.router.use(async (req, res, next) => {
|
2019-11-16 20:13:35 -05:00
|
|
|
const account = await this.server.client.db.Account.findOne({ username: req.query.username });
|
2019-11-16 19:25:44 -05:00
|
|
|
if (!account) return res.status(401).json({ code: this.constants.codes.ACCOUNT_NOT_FOUND, message: 'UNAUTHORIZED' });
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
const authResult = await this.server.security.checkBearer(account._id, this.server.security.extractBearer(req));
|
|
|
|
if (!authResult) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: 'UNAUTHORIZED' });
|
|
|
|
next();
|
|
|
|
});
|
2019-11-16 19:37:45 -05:00
|
|
|
|
|
|
|
this.router.get('/', async (req, res) => {
|
2019-11-16 20:13:35 -05:00
|
|
|
const account = await this.server.client.db.Account.findOne({ username: req.query.username });
|
2019-11-16 19:37:45 -05:00
|
|
|
const acc: any = {};
|
|
|
|
acc.username = account.username;
|
|
|
|
acc.userID = account.userID;
|
|
|
|
acc.email = account.emailAddress;
|
|
|
|
acc.locked = account.locked;
|
|
|
|
acc.root = account.root;
|
|
|
|
acc.createdAt = account.createdAt;
|
|
|
|
acc.createdBy = account.createdBy;
|
|
|
|
acc.permissions = account.permissions;
|
|
|
|
res.status(200).json({ code: this.constants.codes.SUCCESS, message: acc });
|
|
|
|
});
|
2019-11-16 19:25:44 -05:00
|
|
|
}
|
|
|
|
}
|