basiclogin

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

basiclogin-gin

为Cookie设计的轻量级登录框架,兼容chrome 、firefox浏览器,暂未测试safari浏览器。

Lightweight login framework designed for cookie, compatible with chrome, firefox, not tested safari.

Reference https://developer.mozilla.org/docs/Web/HTTP/Authentication

Get

go get github.com/bddjr/basiclogin-gin

Example

See test/main.go

loginGroup := Router.Group("login")
basiclogin.New(loginGroup, func(ctx *gin.Context, username, password string, secure bool) {
    // ⚠ If you need *http.Cookie, please use
    //   ctx.Writer.Header().Add("Set-Cookie", cookie.String())
    if username == staticUserName && hmac.Equal([]byte(password), []byte(StaticPassword)) {
        ctx.SetCookie(cookieName, cookieValue, 0, "/", "", secure, true)
        ctx.Header("Referrer-Policy", "no-referrer")
        basiclogin.ScriptRedirect(ctx, 401, "/")
        return
    }
	ctx.String(401, "Wrong usename or password")
})

License

BSD-3-clause license

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(group *gin.RouterGroup, callBack func(ctx *gin.Context, username string, password string, secure bool))

⚠ If you need *http.Cookie, please use

ctx.Writer.Header().Add("Set-Cookie", cookie.String())

func ScriptRedirect

func ScriptRedirect(ctx *gin.Context, code int, path string)

func ScriptRedirectWithQuery added in v0.0.7

func ScriptRedirectWithQuery(ctx *gin.Context, code int, path string)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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