improvements
This commit is contained in:
parent
f8fcb5a5d4
commit
479b389464
@ -75,7 +75,7 @@ class Server extends EventEmitter {
|
||||
|
||||
this.app.use(helmet());
|
||||
this.app.use(express.json({ limit: '10mb' }));
|
||||
this.app.use(express.urlencoded());
|
||||
this.app.use(express.urlencoded({ extended: true }));
|
||||
this.app.use(this.logRequest.bind(this)); // Logs every request
|
||||
this.app.use(this.logError.bind(this)); // Logs endpoints that error and sends a 500
|
||||
this.app.use(this.ready.bind(this)); // denies requests before the server is ready
|
||||
@ -167,7 +167,7 @@ class Server extends EventEmitter {
|
||||
this.logger.info(`${profile.username} (${profile.id}) is logging in.`);
|
||||
const user = await this.userDatabase.userFromDiscord(profile);
|
||||
callback(null, user);
|
||||
}));
|
||||
}), { successRedirect: '/api/login/discord/finalise' });
|
||||
|
||||
this.authenticator.addStrategy('local', new LocalStrategy(async (username, password, callback) => {
|
||||
const user = await this.userDatabase.findUser(username);
|
||||
|
@ -60,13 +60,13 @@ class Authenticator {
|
||||
|
||||
}
|
||||
|
||||
addStrategy (name, strategy) {
|
||||
addStrategy (name, strategy, { failureRedirect = '/login/fail', successRedirect = '/home' } = {}) {
|
||||
this.logger.info(`Adding ${name} authentication strategy`);
|
||||
this.passport.use(name, strategy);
|
||||
// Quick access getter to get the middleware for authenticating
|
||||
Object.defineProperty(this, name, {
|
||||
get: () => {
|
||||
return this.passport.authenticate(name, { failureRedirect: '/login/fail', successRedirect: '/home' });
|
||||
return this.passport.authenticate(name, { failureRedirect, successRedirect });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ class User {
|
||||
return this._passwordHash !== null;
|
||||
}
|
||||
|
||||
async setPassword (passwd) {
|
||||
async setPassword (passwd, save = false) {
|
||||
const hash = await Argon2.hash(passwd);
|
||||
this._passwordHash = hash;
|
||||
await this.save();
|
||||
if (save) await this.save();
|
||||
}
|
||||
|
||||
async authenticate (passwd) {
|
||||
@ -67,6 +67,10 @@ class User {
|
||||
return this.permissions[perm];
|
||||
}
|
||||
|
||||
hasExternalProfile (name) {
|
||||
return Boolean(this.externalProfiles[name]);
|
||||
}
|
||||
|
||||
save () {
|
||||
return this._db.updateUser(this);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user