@ -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
} } ;
}
catch ( err ) {
return { err : err } ;
}
} else {
return { reply : {
date : date ,
timestamp : timestamp ,
token : options . old _token
} } ;
}
return { reply : {
date : date ,
timestamp : timestamp
} } ;
} 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.getAuth Code ('+ 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