• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Hook on a custom page

Scheduled Pinned Locked Moved Plugin Development
11 Posts 3 Posters 2.5k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dinendal
    wrote on last edited by Dinendal
    #1

    Hello there,

    I'm writing a plugin to interconnect 2 systems.
    I would like to know how to fire a hook from a specific custom page (i already create the page).

    The purpose is :

    • go to URL with parameters (ex. http://myaddress/myCustomPage?id=jklDGFYHcgfu)
    • automatically fire a hook that call my plugin
    • parse URL to get parameters (if you could explain how to get the current url in the plugin too, pls)
    • do some stuff etc.

    Could you please help me ?

    Philippe.

    1 Reply Last reply
    0
  • D Offline
    D Offline
    Dinendal
    wrote on last edited by Dinendal
    #2

    The first part is ok, in my plugin.json I use :

    { "hook": "filter:MyTemplate.build", "method": "myMethod" }
    

    So the plugin is called.

    How could I get the current URL from there pls ?
    I see another problem, the page load loops and seems to be stuck after my plugin code was successfully executed. Is there anything to do to let the main process continue ?

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #3

    In your plugin method you can access the request object.

    myPlugin.meyMethod = function (hookData, callback) {
        console.log(hookData.req.url);
        callback(null, hookData);
    };
    
    1 Reply Last reply
    1
  • D Offline
    D Offline
    Dinendal
    wrote on last edited by Dinendal
    #4

    Thanks, it's working.
    With that I fixed the endless loop too.

    1 Reply Last reply
    0
  • D Offline
    D Offline
    Dinendal
    wrote on last edited by
    #5

    Is it possible to log in via a plugin ?
    After verifying ID token from URL I need to log the user with his forum ID.

    I checked some other plugins and I can't really figure out what part of code or function is used to log in users.

    yariplusY 1 Reply Last reply
    0
  • yariplusY Offline
    yariplusY Offline
    yariplus Community Rep
    replied to Dinendal on last edited by yariplus
    #6

    @dinendal Sure. It would be an unusual method of logging in, but there's nothing stopping your plugin from calling the login controller with the request object.

    https://github.com/NodeBB/NodeBB/blob/master/src/controllers/authentication.js#L302

    D 1 Reply Last reply
    0
  • D Offline
    D Offline
    Dinendal
    wrote on last edited by
    #7

    Another question again.
    I'm trying to override the login with this skeleton : https://gist.github.com/julianlam/19deafaa4dbd624ceecd

    It works fine but how could I intercept, in my plugin, the email and password from inputs of the login page ?

    yariplusY 1 Reply Last reply
    0
  • yariplusY Offline
    yariplusY Offline
    yariplus Community Rep
    replied to Dinendal on last edited by
    #8

    @dinendal It's in the req.body object.

    1 Reply Last reply
    0
  • D Offline
    D Offline
    Dinendal
    replied to yariplus on last edited by
    #9

    @yariplus said in Hook on a custom page:

    @dinendal Sure. It would be an unusual method of logging in, but there's nothing stopping your plugin from calling the login controller with the request object.

    https://github.com/NodeBB/NodeBB/blob/master/src/controllers/authentication.js#L302

    I use

    authenticationController.doLogin
    

    I have an error popup from Nodebb :

    Session interrompue
    Il semble que votre session ne soit plus active, ou que le serveur ne la reconnaisse plus. Merci de rafraîchir cette page.
    

    and when I click on OK, i'm correctly log in.
    What am I doing wrong ? Is there another thing to do to be log in properly ?

    1 Reply Last reply
    0
  • D Offline
    D Offline
    Dinendal
    wrote on last edited by
    #10

    translation of the error : "It looks like your login session is no longer active, or no longer recognized by your server..."

    Is there a step that i'm missing ? Because when I click on "OK", I'm logged in...

    "authenticationController.doLogin" is not sufficient ?

    1 Reply Last reply
    0
  • yariplusY Offline
    yariplusY Offline
    yariplus Community Rep
    wrote on last edited by
    #11

    I don't think so, probably something to do with cookies changing. I'm guessing you need to call redirect or status.send to avoid the error.

    https://github.com/NodeBB/NodeBB/blob/master/src/controllers/authentication.js#L292-L296

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development