galaxy

package module
v0.0.0-...-d274286 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

README

galaxy

权限系统 例子见 example

package main

import (
    "galaxy"
    "time"
)
func main() {
    a := &galaxy.Galaxy{}
    a.AdminPort = 8000
    a.MysqlDsn = "user:pass@tcp(127.0.0.1:3306)/galaxy"
    a.TemplatePath = "/path/galaxy/templates"
    //如果已经存在beego orm 请修改default为其他
    a.DbName = "default"
    go a.Run()
    time.Sleep(10000000 * time.Second)
}

调用方式 以beego为例 在router.go中

var FilterUser = func(ctx *context.Context) {

	if ctx.Request.RequestURI == "/Login" {
		return
	}

	if ctx.Request.RequestURI == "/LoginOut" {
		return
	}

	if strings.HasPrefix(ctx.Request.RequestURI, "/static") {
		return
	}

	if admin, ok := ctx.Input.CruSession.Get("adminInfo").(*models.Admin); !ok {
		ctx.WriteString(`{"Status":"2","ErrInfo":"您还没有登录!请您先登录!"}`)
	} else {
		if ok := galaxy.ValidatePermission(admin.UserId, ctx.Request.RequestURI); !ok {
		    ctx.WriteString(`{"Status":"0","ErrInfo":"您没有权限访问!"}`)
		}
	}

}
func init() {
    beego.Router("/", &controllers.Index{}) //根目录
    beego.InsertFilter("*", beego.BeforeRouter, FilterUser)
}

自己完成注册用户可以调用 galaxy.AddUser galaxy.EditUser galaxy.DelUser

登录验证 galaxy.GetUserInfo(name, password)

导入数据库 首先需要创建数据库 或者导入到已有数据库 注意会覆盖原有数据库 有user表的注意了 mysqldump -u用户名 -p密码 -h主机 数据库 < doc/galaxy.sql

要完善的功能: 修改管理员密码

Documentation

Overview

	权限控制
    存储落地默认mysql
    web 控制页面
    权限
    群组
    用户

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Galaxy

type Galaxy struct {
	AdminPort    int    //管理界面端口
	MysqlDsn     string //user:pass@tcp(127.0.0.1:3306)/galaxy?timeout=3s&parseTime=true&loc=Local&charset=utf8mb4,utf8
	MysqlNum     int
	TemplatePath string
	Debug        bool
	DbName       string
	AdminList    map[string]string
}

func (*Galaxy) AddLog

func (this *Galaxy) AddLog(user_id int64, role_id int, logContent, tag, ipv4 string) error

写入操作日志

func (*Galaxy) AddUser

func (this *Galaxy) AddUser(id int64, name, info, pass string) (err error)

添加用户 pass为加密之后的字符串

func (*Galaxy) DelUser

func (this *Galaxy) DelUser(id int64) (err error)

删除用户

func (*Galaxy) EditUser

func (this *Galaxy) EditUser(id int64, name, info string, status int, pass string) (err error)

编辑用户 pass为加密之后的字符串

func (*Galaxy) GetPermissionByUserId

func (this *Galaxy) GetPermissionByUserId(userId int64) (mp []*model.Permission, err error)

根据角色ID获取权限列表

func (*Galaxy) GetUserInfo

func (this *Galaxy) GetUserInfo(name, password string) (*model.User, error)

获取用户详情 pass为加密之后的字符串

func (*Galaxy) GetUserRole

func (this *Galaxy) GetUserRole(userId int64) *model.Role

获取角色ID

func (*Galaxy) Run

func (this *Galaxy) Run() (err error)

func (*Galaxy) ValidatePermission

func (this *Galaxy) ValidatePermission(userId int64, path string) bool

验证权限

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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