lots...
This commit is contained in:
56
controller/auth.js
Normal file
56
controller/auth.js
Normal file
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
const {User, AuthToken} = require('>/models');
|
||||
|
||||
|
||||
class Auth{
|
||||
static errors = {
|
||||
login: function(){
|
||||
let error = new Error('LDAPLoginFailed');
|
||||
error.name = 'LDAPLoginFailed';
|
||||
error.message = `Invalid Credentials, login failed.`;
|
||||
error.status = 401;
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
static async login(data){
|
||||
try{
|
||||
let user = await User.login(data);
|
||||
let token = await AuthToken.create({username: user.username});
|
||||
|
||||
return {user, token}
|
||||
}catch(error){
|
||||
console.log('login error', error);
|
||||
throw this.errors.login();
|
||||
}
|
||||
}
|
||||
|
||||
static async checkToken(token){
|
||||
try{
|
||||
token = await AuthToken.get(token);
|
||||
if(token && token.check()) return token;
|
||||
|
||||
throw this.errors.login();
|
||||
}catch(error){
|
||||
throw this.errors.login();
|
||||
}
|
||||
}
|
||||
|
||||
static async logout(data){
|
||||
let token = await AuthToken.get(data);
|
||||
await token.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Auth.logOut = async function(data){
|
||||
try{
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {Auth};
|
||||
|
7
controller/index.js
Normal file
7
controller/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
auth: require('./auth'),
|
||||
pubsub: require('./pubsub'),
|
||||
torrent: require('./torrent'),
|
||||
}
|
6
controller/pubsub.js
Normal file
6
controller/pubsub.js
Normal file
@ -0,0 +1,6 @@
|
||||
const {PubSub} = require('p2psub');
|
||||
|
||||
ps = new PubSub();
|
||||
|
||||
|
||||
module.exports = ps;
|
15
controller/torrent.js
Normal file
15
controller/torrent.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const ps = require('./pubsub.js');
|
||||
const {Torrent} = require('>/models');
|
||||
|
||||
console.log('here!!!!!!!!!!!!!')
|
||||
|
||||
setInterval(async function(){
|
||||
ps.publish('torrent:server:status', await Torrent.trClient.sessionStats())
|
||||
}, 3000);
|
||||
|
||||
|
||||
// ps.subscribe(/./g, function(...args){
|
||||
// console.log('event', args);
|
||||
// });
|
Reference in New Issue
Block a user