auth_admin

package
v0.0.0-...-b1f09d4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Base on https://github.com/martini-contrib/sessionauth 这里不能随便自定义,否则,需要改的好多地方,如 模板

Index

Constants

View Source
const (
	DefaultKey = "github.com/foxiswho/echo-go/modules/auth_admin"
)

Variables

View Source
var (
	// RedirectUrl should be the relative URL for your login route
	RedirectUrl string = "/admin/login"

	// RedirectParam is the query string parameter that will be set
	// with the page the user_service was trying to visit before they were
	// intercepted.
	RedirectParam string = "return_url"

	// SessionKey is the key containing the unique ID in your session
	SessionKey string = "ADMINAUTHUNIQUEID"
)

Functions

func AuthenticateSession

func AuthenticateSession(s session.Session, user Admin) error

AuthenticateSession will mark the session and user_service object as authenticated. Then the Login() user_service function will be called. This function should be called after you have validated a user_service.

func LoginRequired

func LoginRequired() echo.MiddlewareFunc

LoginRequired verifies that the current user_service is authenticated. Any routes that require a login should have this handler placed in the flow. If the user_service is not authenticated, they will be redirected to /login with the "next" get parameter set to the attempted URL.

func Logout

func Logout(s session.Session, user Admin)

Logout will clear out the session and call the Logout() user_service function.

func New

func New(newAdmin func() Admin) echo.MiddlewareFunc

func UpdateUser

func UpdateUser(s session.Session, user Admin) error

UpdateUser updates the Admin object stored in the session. This is useful incase a change is made to the user_service model that needs to persist across requests.

Types

type Admin

type Admin interface {
	// Return whether this user_service is logged in or not
	IsAuthenticated() bool

	// Set any flags or extra data that should be available
	Login()

	// Clear any sensitive data out of the user_service
	Logout()

	// Return the unique identifier of this user_service object
	UniqueId() interface{}

	RoleId() int

	// Populate this user_service object with values
	GetById(id interface{}) error
}

type AuthAdmin

type AuthAdmin struct {
	Admin
}

func Default

func Default(c echo.Context) AuthAdmin

shortcut to get AuthAdmin

func (AuthAdmin) LogoutTest

func (a AuthAdmin) LogoutTest(s session.Session)

Jump to

Keyboard shortcuts

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