UNPKG

captcha-igid

Version:
147 lines (116 loc) 3.15 kB
const {TaggedTransition} = require('copious-transitions') // Captcha Users class CaptchaUsers extends TaggedTransition { constructor(descendant) { if ( descendant ) { super(descendant) } else { super("user") } this.domain = "" } set_domain(domain) { this.domain = domain } existence_query(udata) { return { "ucwid" : udata.ucwid } } from_cache() { return(true) } back_ref() { return("user_id") } kv_store_key() { return("ucwid") } primary_key() { return("ucwid") } session_key() { return("ucwid") } match_key() { return("session_token") } secondary_match_key() { return("token") } action_selector(action) { let idx = ['login','register'].indexOf(action) return(idx >= 0) } secondary_action_selector(action) { let idx = ['login-secondary'].indexOf(action) return(idx >= 0) } sess_data_accessor() { return("ucwid") } update(data) { data.domain = this.domain let axioms = { "public_derivation" : data.public_derivation, "signer_public_key" : data.signer_public_key } delete data.public_derivation // -- the derivation will be stored until a session is authorize.. \\ delete data.signer_public_key // -- other specific user data for session management will be stored in a user cache return([data,axioms]) } tracking(u_obj) { //u_obj._tracking = do_hash(JSON.stringify(u_obj)) } } // Captcha Paths class CaptchaPaths extends TaggedTransition { constructor() { super("captcha") this.addModule('dynamic') } match_key() { return('captcha_val') } uuid_prefix() { return('svg+') } } // Contact Paths class ContactPaths extends CaptchaUsers { constructor() { super("contact") } // update(data) { data.comment = ('' + data.token) + '\n' + data.comment.trim() data.domain = this.domain return(data) } } // Password Reset class AdminActions extends CaptchaUsers { constructor() { super("password-reset") } // } class CaptchaCustomTransitions { constructor() { this.captcha_keyed = new CaptchaPaths() this.contact_keyed = new ContactPaths() this.users_keyed = new CaptchaUsers() this.admin_actions_keyed = new AdminActions() } initialize(conf) { /// ignores configuration // ignores conf.custom_transitions global.G_captcha_trns = this.captcha_keyed global.G_contact_trns = this.contact_keyed global.G_users_trns = this.users_keyed global.G_admin_actions_trns = this.admin_actions_keyed let domain = conf.domain G_contact_trns.set_domain(domain) G_users_trns.set_domain(domain) G_admin_actions_trns.set_domain(domain) } } module.exports = new CaptchaCustomTransitions()