mirror of
https://github.com/Foltik/Shimapan
synced 2025-03-06 12:10:32 -05:00
Add auth failure logging
This commit is contained in:
parent
6d6768a849
commit
19d8d026fe
@ -1,6 +1,7 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const config = require('config');
|
||||
const fs = require('fs').promises;
|
||||
|
||||
const ModelPath = '../../models/';
|
||||
const User = require(ModelPath + 'User.js');
|
||||
@ -33,8 +34,11 @@ const login = (user, req) => {
|
||||
const validateInvite = wrap(async (req, res, next) => {
|
||||
const invite = await Invite.findOne({code: req.body.invite}).catch(next);
|
||||
|
||||
if (!invite)
|
||||
if (!invite) {
|
||||
// Log failure
|
||||
await fs.appendFile('auth.log', `${new Date().toISOString()} register ${req.connection.remoteAddress}`);
|
||||
return res.status(422).json({message: 'Invalid invite code.'});
|
||||
}
|
||||
|
||||
if (invite.used)
|
||||
return res.status(422).json({message: 'Invite already used.'});
|
||||
@ -92,8 +96,11 @@ const loginProps = [
|
||||
router.post('/login', bodyVerifier(loginProps), canonicalizeRequest, wrap(async (req, res, next) => {
|
||||
// Authenticate
|
||||
const user = await authenticate(req, res, next);
|
||||
if (!user)
|
||||
if (!user) {
|
||||
// Log failure
|
||||
await fs.appendFile('auth.log', `${new Date().toISOString()} login ${req.connection.remoteAddress}`);
|
||||
return res.status(401).json({'message': 'Unauthorized.'});
|
||||
}
|
||||
|
||||
// Create session
|
||||
await login(user, req);
|
||||
|
@ -2,6 +2,7 @@ const ModelPath = '../models/';
|
||||
const Key = require(ModelPath + 'Key.js');
|
||||
const User = require(ModelPath + 'User.js');
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const wrap = require('./wrap.js');
|
||||
const verifyScope = require('./verifyScope.js');
|
||||
|
||||
@ -30,6 +31,9 @@ const checkKey = async (req, scope, status) => {
|
||||
req.key = key.key;
|
||||
status.permission = true;
|
||||
}
|
||||
} else {
|
||||
// Log failure
|
||||
await fs.appendFile('auth.log', `${new Date().toISOString()} key ${req.connection.remoteAddress}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -2,7 +2,8 @@
|
||||
"Server": {
|
||||
"port": 4433,
|
||||
"hostname": "https://shimapan.rocks",
|
||||
"tls": true
|
||||
"tls": true,
|
||||
"trustProxy": []
|
||||
},
|
||||
"Database": {
|
||||
"host": "mongodb://localhost:27017/shimapan"
|
||||
|
@ -2,7 +2,8 @@
|
||||
"Server": {
|
||||
"port": 8080,
|
||||
"hostname": "http://localhost:8080",
|
||||
"tls": false
|
||||
"tls": false,
|
||||
"trustProxy": []
|
||||
},
|
||||
"Database": {
|
||||
"host": "mongodb://localhost:27017/shimapan-dev"
|
||||
|
@ -2,7 +2,8 @@
|
||||
"Server": {
|
||||
"port": 8080,
|
||||
"hostname": "http://localhost:8080",
|
||||
"tls": false
|
||||
"tls": false,
|
||||
"trustProxy": []
|
||||
},
|
||||
"Database": {
|
||||
"host": "mongodb://localhost:27017/shimapan-test"
|
||||
|
3
extra/shimapan.filter
Normal file
3
extra/shimapan.filter
Normal file
@ -0,0 +1,3 @@
|
||||
[Definition]
|
||||
failregex = \w <HOST>
|
||||
ignoreregex =
|
Loading…
Reference in New Issue
Block a user