How to create plugin


(M Zain Damlag) #1

Hello everyone,
I’m new comer to discourse and I loved it very much.

Recently I do some changes in discourse “session controller” by adding to functions so that I could login to forum remotely using SSO.

I were going to change this in online source code but every time I rebuild all changes restored to origin, so I read that I need to put these changes in “Session Controller” and routes file via plugin.

I searched for how do this via plugin or a documentation for how doing an plugin but I didn’t reached any thing.

Can any one helps me ?

(Jeff Atwood) #2

Can you describe the changes you needed to make in more detail? Why did you need to make these changes?

(M Zain Damlag) #3

These changes is two functions similar to sso_login and sso in session controller, so I can login to forum remotely when user login in my website, he will be logged in the too without needing to visit the forum.

(Dean Taylor) #4

Also relevant, you might want to try reading this thread from here - perhaps avoid making changes to core:

(M Zain Damlag) #5

@DeanMarkTaylor Thanks for your help, I didn’t understand the part of i frame but I’m already do these changes in my local development discourse and It works correctly. I didn’t change any of the core code I just added new two functions to initiate the SSO and all works correctly, I just need to upload these changes to my website that use docker so I need to put them in a form of plugin

These changes are:
1- Session Controller: Adding two functions and adding them to "skip_before_filter"
2- Route File: Adding two lines for these functions

I wanna know who can make a plugin do this changes in my website.

(M Zain Damlag) #6

Hello, Any Help? Waiting

(Sigurður Guðbrandsson) #7

You do realize that we’re all helping each other in volunteer work … so if we don’t reply, it might be because the question was hard to understand and/or answer.

Anyway, to make this simple for you, @DeanMarkTaylor gave you a link to an answer that will log in the user without having to do any changes to the core (yes, you were doing changes to the core), is simple to implement and works every time on all clients.

After reading your original post, I understand that you’re trying to automatically log a user into your discourse forum without having the user going into the forum itself, is that correct?

If so, it would be best for you to implement an iframe solution.
Iframe solution does not require a new plugin or any changes to any core files … it simply works.

An iframe solution works like this:

  1. The user logs into your external website.
  2. After the user logs in, the external website adds an iframe that will try to automatically log in to discourse
    @AdamCapriola created this awesome WordPress functionality here: Official Single-Sign-On for Discourse (sso)

If you’re adamant on turning your changes into a plugin, then you’ll just have to set up a development environment and figure out how to create the plugin …
When I was writing my first plugin, I just went to Discourse · GitHub and read the source code of other plugins to figure out how the plugin architecture works.

Best of luck.

(M Zain Damlag) #8

@sigurdur Thanks for your reply, I know that we are helping each other in volunteering work, I really appreciate this and hope to learn and help others too, and I already done my plugin for this, I think it’s more reliable way and hope if I can make it applicable for all not customized for my website.

(Sigurður Guðbrandsson) #9

Cool … can you share the plugin on GitHub?

(M Zain Damlag) #10

No problem in sharing it, but Its customized to my website as everyone needs to use it will need to write the same code I used in my external website login system