diff --git a/plugins.go b/plugins.go index eda182f5..f485cead 100644 --- a/plugins.go +++ b/plugins.go @@ -6,12 +6,17 @@ import ( var ( pluginRoutes []*plugins.Routing + allPlugins []*plugins.Plugin ) func InitPluginsDatabase() { plugins.InitDB(db) } +func SetAuthorized() { + +} + func Routes() []*plugins.Routing { return plugins.PluginRoutes } diff --git a/plugins/html/slack.html b/plugins/html/slack.html new file mode 100644 index 00000000..97556a0b --- /dev/null +++ b/plugins/html/slack.html @@ -0,0 +1 @@ +yooyyo \ No newline at end of file diff --git a/plugins/init.go b/plugins/plugins.go similarity index 62% rename from plugins/init.go rename to plugins/plugins.go index 53613c41..aa880937 100644 --- a/plugins/init.go +++ b/plugins/plugins.go @@ -3,24 +3,45 @@ package plugins import ( "database/sql" "net/http" + "fmt" ) var ( db *sql.DB PluginRoutes []*Routing + Plugins []*Plugin ) +type Plugin struct { + Name string +} + type Routing struct { URL string Method string Handler func(http.ResponseWriter, *http.Request) } +func Add(name string) { + plugin := &Plugin{name} + Plugins = append(Plugins, plugin) +} + func AddRoute(url string, method string, handle func(http.ResponseWriter, *http.Request)) { route := &Routing{url, method, handle} PluginRoutes = append(PluginRoutes, route) } +func Authenticated(r *http.Request) bool { + + + return true +} + +func log(msg... string) { + fmt.Println(" @plugins: ",msg) +} + func InitDB(database *sql.DB) { db = database } diff --git a/plugins/slack.go b/plugins/slack.go index 611beffd..26d56656 100644 --- a/plugins/slack.go +++ b/plugins/slack.go @@ -1,30 +1,69 @@ package plugins -import "net/http" +import ( + "net/http" + "strconv" +) + +const ( + SLACK_TABLE = "plugin_slack" +) func init() { - AddRoute("save_slack", "POST", SaveIt) - AddRoute("create_slack", "GET", Create) + Add("slack") + AddRoute("install_slack", "GET", InstallSlack) + AddRoute("uninstall_slack", "GET", UninstallSlack) + AddRoute("save_slack", "POST", SaveSettings) } -func SaveIt(w http.ResponseWriter, r *http.Request) { +type Slack struct { + Key string + Secret string + Enabled bool + Channel string +} + +func InstallSlack(w http.ResponseWriter, r *http.Request) { + CreateTable() http.Redirect(w, r, "/plugins", http.StatusSeeOther) } -func Create(w http.ResponseWriter, r *http.Request) { - CreateTable() +func UninstallSlack(w http.ResponseWriter, r *http.Request) { + DropTable() + http.Redirect(w, r, "/plugins", http.StatusSeeOther) } +func SaveSettings(w http.ResponseWriter, r *http.Request) { + r.ParseForm() + key := r.PostForm.Get("key") + secret := r.PostForm.Get("secret") + enabled, _ := strconv.ParseBool(r.PostForm.Get("enabled")) + channel := r.PostForm.Get("channel") + + slack := &Slack { + key, + secret, + enabled, + channel, + } + + slack.UpdateTable() + + http.Redirect(w, r, "/plugins", http.StatusSeeOther) +} + + func CreateTable() { - sql := "CREATE TABLE slack (enabled BOOLEAN, api_key text, api_key text, channel text);" + sql := "CREATE TABLE "+SLACK_TABLE+" (enabled BOOLEAN, api_key text, api_secret text, channel text);" + db.QueryRow(sql).Scan() +} + +func (s *Slack) UpdateTable() { + sql := "CREATE TABLE "+SLACK_TABLE+" (enabled BOOLEAN, api_key text, api_key text, channel text);" db.QueryRow(sql).Scan() } func DropTable() { - sql := "DROP TABLE slack;" + sql := "DROP TABLE "+SLACK_TABLE+";" db.QueryRow(sql).Scan() } - -func UpdateDatabase() { - -}