UNPKG

captcha-igid

Version:
130 lines (111 loc) 4.04 kB
const { GeneralTransitionEngine } = require('copious-transitions') const g_crypto = require('crypto-wraps') const {FileOperations} = require('extra-file-class') // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- // class CaptchaTransitionEngineClass extends GeneralTransitionEngine { // constructor() { super() } /** * seeking_endpoint_paths * * Included for special cases * @returns Array */ seeking_endpoint_paths() { return ['user'] // const {MessageRelay} = require('categorical-handlers') } /** * set_messenger * * @param {string} path * @param {object} messenger -- communication object */ async set_messenger(path,messenger) { if ( path === 'special_user' ) { this.relayer = messenger } this.create_special_user_session(messenger.conf.user_def_file) // initialize the special user... } /** * set_contractual_filters * * @param {object} tp -- transition processing * @param {object} uh -- user handling * @param {object} mh -- media handler */ set_contractual_filters(tp,uh,mh) { // super.set_contractual_filters(tp,uh,mh) // this.fos = new FileOperations((this.class_conf ? this.class_conf.transition_files : false)) // } async create_special_user_session(used_def_file) { // let user_obj = await this.fos.load_json_data_at_path(used_def_file) // must have ucwid and name fields await this.registration_transition(user_obj,false) user_obj.logged_in = true // await this.db.add_user(user_obj) // let transtion_object = { "user_key" : user_obj.ucwid, "_t_u_key" : "ucwid", "strategy" : "igid", "_db_session_key" : "ucwid" } // let nonce = '' + g_crypto.gen_nonce() // transtion_object.token = 'user+' + g_crypto.gen_nonce() // this token identifies this transition object (for secondar) let session_token = sess_m.do_hash(post_body[sess_m.hashables.field1] + post_body[sess_m.hashables.field2] + nonce) // this is the session identifier just getting started. transtion_object.session_token = session_token transtion_object.strategy = post_body.strategy // this.stash_session_token(user_obj,transtion_object,sess_tok) // user has _tracking // await this.session_manager.initialize_session_state('user',session_token,transtion_object) // await this.relayer.create_on_path(transtion_object,'special-user') // } // admin_transition_finalizer ---- // ---- // Methods for handling administrative actions ... admin_transition_finalizer(t_obj) { // transition object switch ( t_obj.action ) { case 'special-user' : { this.session_manager.process_user("logout",t_obj,false, G_users_trns.primary_key()) this.create_special_user_session(t_obj.file) break; } default: { break; } } } // special users status // the user has to be stored and have access to a key... The user should be created by // When such a user is created ... a previous one should be removed... // async special_user_status(post_body) { // look up the use in the post_body and see if it the admin user if ( this.db ) { // register the user ... intentionally ephemeral let user = await this.db.fetch_user(post_body) if ( user ) { if ( user._admin_key === post_body._admin_key ) { return true } } } return false } } // module.exports = new CaptchaTransitionEngineClass()