This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/as27/gop5js" | |
) | |
func main() { | |
gop5js.CanvasHeight = 400 | |
gop5js.CanvasWidth = 400 | |
gop5js.Draw = draw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package actions | |
import ( | |
"tutorials/db01/models" | |
"github.com/gobuffalo/buffalo" | |
"github.com/markbates/pop" | |
) | |
// This file is generated by Buffalo. It offers a basic structure for adding, editing and deleting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goth.UseProviders( | |
github.New( | |
os.Getenv("GITHUB_KEY"), | |
os.Getenv("GITHUB_SECRET"), | |
fmt.Sprintf("%s%s", App().Host, "/auth/github/callback"), | |
"user:email"), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the secure group | |
secure := app.Group("/secure") | |
// Add the middleware CheckAuth to the group | |
secure.Use(CheckAuth) | |
// Create a simple secure handler, which renders a html file | |
secure.GET("/", | |
func(c buffalo.Context) error { | |
return c.Render(200, r.HTML("secure/index.html")) | |
}) | |
// Create a logout action, where the userID inside the session is deleted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CheckAuth is the middlewar to check if a user is logged on. | |
func CheckAuth(next buffalo.Handler) buffalo.Handler { | |
return func(c buffalo.Context) error { | |
// Read the userID out of the session | |
userID := c.Session().Get("userID") | |
// If there is no userID redirect to the login page | |
if userID == nil { | |
err := c.Redirect(http.StatusTemporaryRedirect, "/login") | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func AuthCallback(c buffalo.Context) error { | |
user, err := gothic.CompleteUserAuth(c.Response(), c.Request()) | |
if err != nil { | |
return c.Error(401, err) | |
} | |
session := c.Session() | |
session.Set("userID", user.UserID) | |
err = session.Save() | |
if err != nil { | |
return c.Error(401, err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App is where all routes and middleware for buffalo | |
// should be defined. This is the nerve center of your | |
// application. | |
func App() *buffalo.App { | |
if app == nil { | |
app = buffalo.Automatic(buffalo.Options{ | |
Env: ENV, | |
SessionName: "_githubauth_session", | |
Host: "http://localhost:3000", | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package actions | |
import ( | |
"fmt" | |
"os" | |
"github.com/gobuffalo/buffalo" | |
"github.com/markbates/goth" | |
"github.com/markbates/goth/gothic" | |
"github.com/markbates/goth/providers/github" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Home = Vue.component('home',{ | |
data : () => { | |
return { | |
a: "1", | |
collections : {} | |
} | |
}, | |
template: `<div><h1>Home</h1><router-view></router-view></div>`, | |
mounted: () => { | |
var data = {}; |