Skip to content

Instantly share code, notes, and snippets.

View as27's full-sized avatar
🏠
Working from home

Andreas Schröpfer as27

🏠
Working from home
View GitHub Profile
@as27
as27 / gop5js_simple.go
Created April 26, 2018 21:35
A simple gop5js example
package main
import (
"github.com/as27/gop5js"
)
func main() {
gop5js.CanvasHeight = 400
gop5js.CanvasWidth = 400
gop5js.Draw = draw
@as27
as27 / pages.go
Created March 22, 2017 18:52
Generated file
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
@as27
as27 / auth.go
Created March 15, 2017 16:29
Buffalo Auth Tutorial: Setting scope
goth.UseProviders(
github.New(
os.Getenv("GITHUB_KEY"),
os.Getenv("GITHUB_SECRET"),
fmt.Sprintf("%s%s", App().Host, "/auth/github/callback"),
"user:email"),
)
@as27
as27 / app.go
Last active March 15, 2017 16:37
Buffalo Auth Tutorial: secure routes
// 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
@as27
as27 / middleware.go
Created March 11, 2017 19:04
Buffalo Auth Tutorial: Checking if a user is logged in
// 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
}
@as27
as27 / auth.go
Created March 10, 2017 20:57
Buffalo Auth Tutorial - modification in the AuthCallback
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)
@as27
as27 / app.go
Last active September 27, 2017 13:00
Buffalo Auth Tutorial app 01
// 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",
})
@as27
as27 / auth.go
Created March 10, 2017 11:05
Buffalo auth tutorial auth.go
package actions
import (
"fmt"
"os"
"github.com/gobuffalo/buffalo"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/github"
@as27
as27 / app.js
Created February 11, 2017 10:07
const Home = Vue.component('home',{
data : () => {
return {
a: "1",
collections : {}
}
},
template: `<div><h1>Home</h1><router-view></router-view></div>`,
mounted: () => {
var data = {};