Back to

Package admin

Latest Go to latest

The highest tagged major version is .

Published: Aug 18, 2020 | License: MIT | Module:



var AdminUserMigration = &gormigrate.Migration{
	ID: "init_admin",
	Migrate: func(tx *gorm.DB) error {
		var err error

		type adminUser struct {
			Email     string `gorm:"not null;unique"`
			FirstName string
			LastName  string
			Password  []byte
			LastLogin *time.Time

		if err = tx.CreateTable(&adminUser{}).Error; err != nil {
			return err
		var pwd []byte
		if pwd, err = bcrypt.GenerateFromPassword([]byte("changeme"), bcrypt.DefaultCost); err != nil {
			return err
		usr := adminUser{
			Email:    "",
			Password: pwd,
		return tx.Save(&usr).Error
	Rollback: func(tx *gorm.DB) error {
		return tx.DropTable("admin_users").Error

AdminUserMigration is the migration that creates our user model

type Admin

type Admin struct {
	// contains filtered or unexported fields

Admin abstracts the whole QOR Admin + authentication process

func New

func New(db *gorm.DB, prefix, cookiesecret string) *Admin

New will create a new admin using the provided gorm connection, a prefix for the various routes. Prefix can be an empty string. The cookie secret will be used to encrypt/decrypt the cookie on the backend side.

func (Admin) Bind

func (a Admin) Bind(r *gin.Engine)

Bind will bind the admin interface to an already existing gin router (*gin.Engine).

type User

type User struct {
	Email     string `gorm:"not null;unique"`
	FirstName string
	LastName  string
	Password  []byte
	LastLogin *time.Time

User defines how an admin user is represented in database

func (User) CheckPassword

func (u User) CheckPassword(raw string) bool

CheckPassword is a simple utility function to check the password given as raw against the user's hashed password

func (User) DisplayName

func (u User) DisplayName() string

DisplayName satisfies the interface for Qor Admin

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword is a simple utility function to hash the password sent via API before inserting it in database

func (User) TableName

func (u User) TableName() string

TableName allows to override the name of the table

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier