login

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

README

GoAdmin Login Theme Components

Offers a variety of default login page theme, and the ways of verification code.

How To

The following code shows how to use the login module, please pay attention to the relevant comments.

package main

import (
	_ "github.com/GoAdminGroup/go-admin/adapter/gin"	    
        _ "github.com/GoAdminGroup/go-admin/adapter/gin"
        _ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
        // import the theme2 login theme, if you don`t use, don`t import
        _ "github.com/GoAdminGroup/components/login/theme2"
	
	"github.com/GoAdminGroup/components/login"
	"github.com/GoAdminGroup/go-admin/engine"
	"github.com/GoAdminGroup/go-admin/examples/datamodel"
	"github.com/GoAdminGroup/go-admin/plugins/admin"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/captcha"
	"github.com/gin-gonic/gin"
	"io/ioutil"
)

func main() {
	r := gin.Default()

	gin.SetMode(gin.ReleaseMode)
	gin.DefaultWriter = ioutil.Discard

	eng := engine.Default()
	adminPlugin := admin.NewAdmin(datamodel.Generators)
	adminPlugin.AddGenerator("user", datamodel.GetUserTable)

        // use the login theme component
        login.Init(login.Config{
            Theme: "theme2", // theme name
            CaptchaDigits: 5, // Use captcha images, here on behalf of how many authentication code Numbers
            // Use tencent verification code, need to offer appID and appSecret
            // TencentWaterProofWallData: login.TencentWaterProofWallData{
            //    AppID:"",
            //    AppSecret: "",
            // }   
        })

	if err := eng.AddConfigFromJson("./config.json").
		AddPlugins(adminPlugin).
		Use(r); err != nil {
		panic(err)
	}
	
	// load the CAPTCHA driver if you use it
	adminPlugin.SetCaptcha(map[string]string{"driver": login.CaptchaDriverKeyDefault})
	captcha.Add(login.CaptchaDriverKeyDefault, new(login.DigitsCaptcha))
	// captcha.Add(login.CaptchaDriverKeyDefault, new(login.TencentCaptcha))

	r.Static("/uploads", "./uploads")

	_ = r.Run(":9033")
}

Documentation

Index

Constants

View Source
const (
	CaptchaDriverKeyTencent = "tencent"
	CaptchaDriverKeyDefault = "digits"

	CaptchaDisableDuration = time.Minute * 2
)

Variables

This section is empty.

Functions

func Init

func Init(cfg ...Config)

func Register

func Register(key string, theme Theme)

Types

type CaptchaData

type CaptchaData map[string]CaptchaDataItem

func (*CaptchaData) Clean

func (c *CaptchaData) Clean()

type CaptchaDataItem

type CaptchaDataItem struct {
	Time time.Time `json:"time"`
	Data string    `json:"data"`
	Num  int       `json:"num"`
}

type Config

type Config struct {
	TencentWaterProofWallData TencentWaterProofWallData `json:"tencent_water_proof_wall_data"`
	CaptchaDigits             int                       `json:"captcha_digits"`
	Theme                     string                    `json:"theme"`
}

type DigitsCaptcha

type DigitsCaptcha struct{}

func (*DigitsCaptcha) Validate

func (c *DigitsCaptcha) Validate(token string) bool

type Login

type Login struct {
	TencentWaterProofWallData TencentWaterProofWallData `json:"tencent_water_proof_wall_data"`
	CaptchaDigits             int                       `json:"captcha_digits"`
	CaptchaID                 string                    `json:"captcha_id"`
	CaptchaImgSrc             string                    `json:"captcha_img_src"`
	Theme                     string                    `json:"theme"`
}

func Get

func Get(cfg ...Config) *Login

func (*Login) GetAsset

func (l *Login) GetAsset(name string) ([]byte, error)

func (*Login) GetAssetList

func (l *Login) GetAssetList() []string

func (*Login) GetCSS

func (l *Login) GetCSS() template.CSS

func (*Login) GetCallbacks

func (l *Login) GetCallbacks() types.Callbacks

func (*Login) GetContent

func (l *Login) GetContent() template.HTML

func (*Login) GetJS

func (l *Login) GetJS() template.JS

func (*Login) GetName

func (l *Login) GetName() string

func (*Login) GetTemplate

func (l *Login) GetTemplate() (*template.Template, string)

func (*Login) IsAPage

func (l *Login) IsAPage() bool

type TencentCaptcha

type TencentCaptcha struct {
	AppID     string `json:"app_id"`
	AppSecret string `json:"app_secret"`
}

func (*TencentCaptcha) Validate

func (c *TencentCaptcha) Validate(token string) bool

type TencentCaptchaRes

type TencentCaptchaRes struct {
	Response  string `json:"response"`
	EvilLevel string `json:"evil_level"`
	ErrMsg    string `json:"err_msg"`
}

type TencentWaterProofWallData

type TencentWaterProofWallData struct {
	AppID     string `json:"app_id"`
	AppSecret string `json:"app_secret"`
}

type Theme

type Theme interface {
	GetAssetList() []string
	GetAsset(name string) ([]byte, error)
	GetHTML() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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