web,db - comments, remove legacy code and add error page
This commit is contained in:
parent
be6f4dc2ac
commit
e2de57ea0a
6
app.js
6
app.js
@ -5,11 +5,7 @@
|
||||
*/
|
||||
|
||||
|
||||
// GDS: Global Data System
|
||||
global['gds'] = {
|
||||
debug: (process.env.NODE_ENV === 'debug') ? true : false,
|
||||
cfg: require(__dirname+'/bin/config')
|
||||
};
|
||||
global['debug'] = (process.env.NODE_ENV === 'debug') ? true : false;
|
||||
global['__dirname'] = __dirname;
|
||||
|
||||
/**
|
||||
|
@ -103,7 +103,6 @@ methods.addUser = async (nick, email, passhash, group) => {
|
||||
* deletes user identified by haystack from database
|
||||
* @author Ruben Meyer
|
||||
* @async
|
||||
* @TODO add functionality
|
||||
* @param {String} haystack email or nick
|
||||
* @return {Object} async(reply, err)
|
||||
*/
|
||||
@ -216,17 +215,17 @@ methods.updateUser = async (id, obj) => {
|
||||
|
||||
|
||||
/**
|
||||
* updates data based on login
|
||||
* updates data based on user activity
|
||||
* @author Ruben Meyer
|
||||
* @async
|
||||
* @TODO UPDATE METHOD; PROBABLY OUTDATED
|
||||
* @param {Number} id User ID
|
||||
* @param {Object} data data JSON -> remember
|
||||
* @return {Object} async({date => 'Login Date', token => 'RememberMe Cookie Token'}, err)
|
||||
* @param {Object} data data
|
||||
* @return {Object} async({date => 'ISO Date', timestamp => 'Timestamp'}, err)
|
||||
*/
|
||||
methods.addActivity = async (id, data) => {
|
||||
if(!(typeof id === 'string' || id instanceof mongoose.Types.ObjectId)) return {err: new TypeError('id is not a string::database.updateNewAction('+id+','+JSON.stringify(options)+')', module.filename)};
|
||||
if(typeof options !== 'object' && options !== null) return {err: new TypeError('obj is not an object::database.updateUserProfile('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||
if(!(typeof id === 'string' || id instanceof mongoose.Types.ObjectId)) return {err: new TypeError('id is not a string::database.addActivity('+id+','+JSON.stringify(options)+')', module.filename)};
|
||||
if(typeof options !== 'object' && options !== null) return {err: new TypeError('obj is not an object::database.addActivity('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||
|
||||
let date = new Date().toISOString();
|
||||
let timestamp = new Date(date).getTime();
|
||||
@ -236,28 +235,11 @@ methods.addActivity = async (id, data) => {
|
||||
last_action: date
|
||||
});
|
||||
|
||||
if(options.rememberme && options.new_token !== false) {
|
||||
var token = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, (c) => (c ^ crypto.randomBytes(new Uint8Array(1).length)[0] & 15 >> c / 4).toString(16));
|
||||
var Remember = models.remember;
|
||||
|
||||
try {
|
||||
data = await Remember.findOneAndUpdate({userId: id}, {token: token, timestamp: Date.now()}, {upsert: true}).exec();
|
||||
return {reply: {
|
||||
date: date,
|
||||
timestamp: timestamp,
|
||||
token: token
|
||||
timestamp: timestamp
|
||||
}};
|
||||
}
|
||||
catch(err) {
|
||||
return {err: err};
|
||||
}
|
||||
} else {
|
||||
return {reply: {
|
||||
date: date,
|
||||
timestamp: timestamp,
|
||||
token: options.old_token
|
||||
}};
|
||||
}
|
||||
} catch(err) {
|
||||
return {err: err};
|
||||
}
|
||||
@ -488,10 +470,9 @@ methods.getApps = async () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* return auth obj
|
||||
* set authentication token for app,user combination
|
||||
* @author Ruben Meyer
|
||||
* @async
|
||||
* @TODO
|
||||
* @param {Object} obj data obj (aId, uId)
|
||||
* @return {Object} async({timestamp, token}, err)
|
||||
*/
|
||||
@ -522,15 +503,14 @@ methods.setAuthCode = async (obj) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* return auth obj
|
||||
* verify authentication token for app,user combination
|
||||
* @author Ruben Meyer
|
||||
* @async
|
||||
* @TODO
|
||||
* @param {Object} obj data obj (aId, aSecret, uId, token)
|
||||
* @return {Object} async(bool, err)
|
||||
*/
|
||||
methods.getAuth = async (obj) => {
|
||||
if(typeof obj !== 'object') return {err: new TypeError('obj is not an object::database.getAuthCode('+JSON.stringify(obj)+')', module.filename)};
|
||||
if(typeof obj !== 'object') return {err: new TypeError('obj is not an object::database.getAuth('+JSON.stringify(obj)+')', module.filename)};
|
||||
|
||||
var AuthCode = models.authCode;
|
||||
|
||||
@ -562,10 +542,6 @@ methods.getAuth = async (obj) => {
|
||||
&& obj.uId == String(data.userId)
|
||||
&& obj.aSecret == data1.secret) {
|
||||
return {reply: true};
|
||||
//methods.setAuthCode({
|
||||
// aId: obj.aId,
|
||||
// uId: obj.uId
|
||||
//});
|
||||
}
|
||||
else return{reply: false};
|
||||
} catch(err) {
|
||||
@ -579,7 +555,7 @@ methods.getAuth = async (obj) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* return app permission
|
||||
* verify if the application exists and the redirectUrl is correct
|
||||
* @author Ruben Meyer
|
||||
* @async
|
||||
* @TODO
|
||||
|
@ -82,7 +82,7 @@ methods.err = methods.error;
|
||||
|
||||
// DEBUG
|
||||
methods.debug = (...data) => {
|
||||
if(global['gds'].debug) {
|
||||
if(global['debug'] === true) {
|
||||
log(console.log, data);
|
||||
|
||||
if(data.length == 1) data = data[0];
|
||||
|
@ -8,7 +8,6 @@ module.exports = {
|
||||
* @url /api/login
|
||||
* @method POST
|
||||
* @POST ['email', 'password']
|
||||
* @TODO add new activity 'action.user.login'
|
||||
*/
|
||||
post: async (req, res) => {
|
||||
// if user is logged in (existing session); FAIL
|
||||
|
@ -1,3 +1,5 @@
|
||||
let cfg = require(global['__dirname']+'/bin/config');
|
||||
|
||||
module.exports = {
|
||||
path: "/register",
|
||||
/**
|
||||
@ -7,7 +9,7 @@ module.exports = {
|
||||
*/
|
||||
post: async (req, res) => {
|
||||
// if registration is disabled
|
||||
if(!global['gds'].cfg.web.registration) {
|
||||
if(!cfg.web.registration) {
|
||||
return res.type('json').status(400).end(JSON.stringify({status: 400, message: "msg.auth.registration.deactivated"}));
|
||||
} else {
|
||||
// am i rite?
|
||||
|
@ -126,7 +126,7 @@ let getRoutes = async () => {
|
||||
* @url /*
|
||||
* @method all
|
||||
*/
|
||||
route.get(['/request', '/login', '/logout', '/reset', '/admin'], asyncer(async (req, res, next) => {
|
||||
route.get(['/request', '/register', '/login', '/logout', '/reset', '/admin'], asyncer(async (req, res, next) => {
|
||||
// passthrough to next route
|
||||
if(req.path.startsWith('/api'))
|
||||
return next();
|
||||
|
19
bin/web/views/blocks/error/error.pug
Normal file
19
bin/web/views/blocks/error/error.pug
Normal file
@ -0,0 +1,19 @@
|
||||
append var
|
||||
if((!breadcrumb && !title) || overwrite_vars)
|
||||
- var breadcrumb = {0: {"name": cfg.app.name, "href": "/"}, 1: {"name": "500 - unknown error", "active": true}};
|
||||
- var title = "I'm so sooryy";
|
||||
|
||||
.uk-flex.uk-margin-medium-top.uk-margin-medium-bottom
|
||||
div(class="uk-width-auto uk-width-1-4@s")
|
||||
.uk-flex.uk-flex-auto.uk-flex-column.uk-flex-center.uk-margin-left.uk-margin-right
|
||||
if(!error)
|
||||
h1 Me so sorry.
|
||||
p Could not find something which belongs to your interests.
|
||||
a(href="/").uk-button.uk-button-default Home
|
||||
else
|
||||
append var
|
||||
- breadcrumb[1] = {"name": error.statusCode + " - "+error.name, "active": true};
|
||||
h1= error.statusCode + " Error: " + error.name
|
||||
p= error.error_description
|
||||
a(href="/").uk-button.uk-button-default Home
|
||||
div(class="uk-width-auto uk-width-1-4@s")
|
4
bin/web/views/error/error.pug
Normal file
4
bin/web/views/error/error.pug
Normal file
@ -0,0 +1,4 @@
|
||||
extends ../blocks/layout.pug
|
||||
|
||||
append content
|
||||
include ../blocks/error/error.pug
|
Loading…
x
Reference in New Issue
Block a user