passwordless

package
v0.0.0-...-20ea284 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2015 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenLength int           = 32
	TtlDuration time.Duration = 20 * time.Minute
)

Variables

This section is empty.

Functions

func BuildRoutes

func BuildRoutes() http.Handler

BuildRoutes returns the routes for the application.

func CsrfMiddleware

func CsrfMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

CsrfMiddleware adds CSRF support via nosurf.

func GetSession

func GetSession(r *http.Request) *sessions.Session

GetSession returns the session for the site.

func HomeHandler

func HomeHandler(w http.ResponseWriter, r *http.Request)

func IsLoggedIn

func IsLoggedIn(r *http.Request) bool

IsLoggedIn is a convenience function for checking if a User exists in the request context.

func Login

func Login(u *User, w http.ResponseWriter, r *http.Request)

Login adds the User's id to the session.

func LoginRequiredMiddleware

func LoginRequiredMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

LoginRequiredMiddleware ensures a User is logged in, otherwise redirects them to the login page.

func LoginSuccessHandler

func LoginSuccessHandler(w http.ResponseWriter, r *http.Request)

func Logout

func Logout(w http.ResponseWriter, r *http.Request)

Logout removes the User from their session.

func LogoutHandler

func LogoutHandler(w http.ResponseWriter, r *http.Request)

func ProfileHandler

func ProfileHandler(w http.ResponseWriter, r *http.Request)

func SendMail

func SendMail(to []string, subject, message string) error

func SetContextUser

func SetContextUser(user *User, r *http.Request)

SetContextUser stores the given user in the request context.

func UserMiddleware

func UserMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

UserMiddleware checks for the User in the session and adds them to the request context if they exist.

func VerifyHandler

func VerifyHandler(w http.ResponseWriter, r *http.Request)

Types

type User

type User struct {
	Id        int64       `db:"id"`
	Email     string      `db:"email"`
	Token     string      `db:"token"`
	Ttl       time.Time   `db:"ttl"`
	OriginUrl null.String `db:"originurl"`
}

func GetContextUser

func GetContextUser(r *http.Request) *User

GetContextUser returns the User for the given request context or nil.

func (*User) IsValidToken

func (u *User) IsValidToken(token string) bool

IsValidToken returns a bool indicating that the User's current token hasn't expired and that the provided token is valid.

func (*User) RefreshToken

func (u *User) RefreshToken() error

RefreshToken refreshes Ttl and Token for the User.

func (*User) UpdateOriginUrl

func (u *User) UpdateOriginUrl(originUrl *url.URL) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL