change name of pack, add oalib

master v0.1.0
veypi 3 years ago
parent bcbfc0380a
commit aae799c7fa

@ -1,6 +1,6 @@
# OneAuth
统一验证服务
统一验证及应用管理服务
## 用户验证思路

@ -1,17 +1,17 @@
package api
import (
"OneAuth/api/app"
"OneAuth/api/role"
"OneAuth/api/token"
"OneAuth/api/user"
"OneAuth/api/wx"
"OneAuth/cfg"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/veypi/OneAuth/api/app"
"github.com/veypi/OneAuth/api/role"
"github.com/veypi/OneAuth/api/token"
"github.com/veypi/OneAuth/api/user"
"github.com/veypi/OneAuth/api/wx"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/core"
"github.com/veypi/OneBD/rfc"

@ -1,11 +1,11 @@
package app
import (
"OneAuth/cfg"
"OneAuth/libs/auth"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/models"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
"github.com/veypi/utils"

@ -1,12 +1,12 @@
package app
import (
"OneAuth/cfg"
"OneAuth/libs/app"
"OneAuth/libs/auth"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/models"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/app"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
)

@ -1,12 +1,12 @@
package role
import (
"OneAuth/cfg"
"OneAuth/libs/auth"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/libs/token"
"OneAuth/models"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/core"
"strconv"
@ -46,10 +46,10 @@ func (h *authHandler) Get() (interface{}, error) {
if err != nil {
return nil, err
}
l := make([]*token.SimpleAuth, 0, 10)
l := make([]*oalib.SimpleAuth, 0, 10)
for _, as := range u.GetAuths() {
if as.AppUUID == uuid {
l = append(l, &token.SimpleAuth{
l = append(l, &oalib.SimpleAuth{
RID: as.RID,
RUID: as.RUID,
Level: as.Level,

@ -1,11 +1,11 @@
package role
import (
"OneAuth/cfg"
"OneAuth/libs/auth"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/models"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
"gorm.io/gorm"
)

@ -1,9 +1,9 @@
package role
import (
"OneAuth/libs/auth"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneBD"
)

@ -1,13 +1,13 @@
package token
import (
"OneAuth/cfg"
"OneAuth/libs/app"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/libs/token"
"OneAuth/models"
"errors"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/app"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/libs/token"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
"gorm.io/gorm"

@ -1,16 +1,16 @@
package user
import (
"OneAuth/cfg"
"OneAuth/libs/app"
"OneAuth/libs/auth"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/libs/token"
"OneAuth/models"
"encoding/base64"
"errors"
"fmt"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/app"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/libs/token"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
"github.com/veypi/utils/log"

@ -1,11 +1,11 @@
package user
import (
"OneAuth/cfg"
"OneAuth/libs/base"
"OneAuth/libs/oerr"
"OneAuth/models"
"errors"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/base"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
"gorm.io/gorm"
)

@ -1,11 +1,11 @@
package wx
import (
"OneAuth/cfg"
"OneAuth/libs/tools"
"OneAuth/models"
"errors"
"fmt"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/tools"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
"github.com/veypi/utils"

@ -1,4 +1,4 @@
module OneAuth
module github.com/veypi/OneAuth
go 1.16
@ -12,4 +12,4 @@ require (
gorm.io/gorm v1.21.3
)
replace github.com/veypi/OneBD v0.4.1 => ../OceanCurrent/OneBD
//replace github.com/veypi/OneBD v0.4.1 => ../OceanCurrent/OneBD

@ -1,10 +1,10 @@
package app
import (
"OneAuth/libs/auth"
"OneAuth/libs/oerr"
"OneAuth/models"
"errors"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/models"
"gorm.io/gorm"
)

@ -1,7 +1,8 @@
package auth
import (
"OneAuth/models"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/utils"
"gorm.io/gorm"
)
@ -37,15 +38,15 @@ func BindUserRole(tx *gorm.DB, userID uint, roleID uint) error {
return err
}
func BindUserAuth(tx *gorm.DB, userID uint, resID uint, level models.AuthLevel, ruid string) error {
func BindUserAuth(tx *gorm.DB, userID uint, resID uint, level oalib.AuthLevel, ruid string) error {
return bind(tx, userID, resID, level, ruid, false)
}
func BindRoleAuth(tx *gorm.DB, roleID uint, resID uint, level models.AuthLevel, ruid string) error {
func BindRoleAuth(tx *gorm.DB, roleID uint, resID uint, level oalib.AuthLevel, ruid string) error {
return bind(tx, roleID, resID, level, ruid, true)
}
func bind(tx *gorm.DB, id uint, resID uint, level models.AuthLevel, ruid string, isRole bool) error {
func bind(tx *gorm.DB, id uint, resID uint, level oalib.AuthLevel, ruid string, isRole bool) error {
r := &models.Resource{}
r.ID = resID
err := tx.Where(r).First(r).Error

@ -1,10 +1,10 @@
package base
import (
"OneAuth/libs/oerr"
"OneAuth/libs/tools"
"errors"
"github.com/json-iterator/go"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/libs/tools"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
"github.com/veypi/utils/log"

@ -1,16 +1,16 @@
package base
import (
"OneAuth/cfg"
"OneAuth/libs/oerr"
"OneAuth/libs/token"
"OneAuth/models"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/oerr"
"github.com/veypi/OneAuth/libs/token"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
)
type UserHandler struct {
Payload *token.PayLoad
Payload *oalib.PayLoad
ignoreMethod map[rfc.Method]bool
}
@ -22,7 +22,7 @@ func (a *UserHandler) Init(m OneBD.Meta) error {
}
func (a *UserHandler) ParsePayload(m OneBD.Meta) error {
a.Payload = new(token.PayLoad)
a.Payload = new(oalib.PayLoad)
tokenStr := m.GetHeader("auth_token")
if tokenStr == "" {
return oerr.NotLogin
@ -43,6 +43,6 @@ func (a *UserHandler) Ignore(methods ...rfc.Method) {
}
}
func (a *UserHandler) GetAuth(ResourceID string, ResourceUUID ...string) models.AuthLevel {
func (a *UserHandler) GetAuth(ResourceID string, ResourceUUID ...string) oalib.AuthLevel {
return a.Payload.GetAuth(ResourceID, ResourceUUID...)
}

@ -1,6 +1,6 @@
package key
import "OneAuth/cfg"
import "github.com/veypi/OneAuth/cfg"
func App(uuid string) string {
if uuid == cfg.CFG.APPUUID {

@ -1,7 +1,7 @@
package key
import (
"OneAuth/cfg"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/utils"
"sync"
)

@ -1,60 +1,19 @@
package token
import (
"OneAuth/models"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/utils/jwt"
)
type SimpleAuth struct {
RID string `json:"rid"`
// 具体某个资源的id
RUID string `json:"ruid"`
Level models.AuthLevel `json:"level"`
}
// TODO:: roles 是否会造成token过大 ?
type PayLoad struct {
jwt.Payload
ID uint `json:"id"`
Auth []*SimpleAuth `json:"auth"`
}
// GetAuth resource_uuid 缺省或仅第一个有效 权限会被更高权限覆盖
func (p *PayLoad) GetAuth(ResourceID string, ResourceUUID ...string) models.AuthLevel {
res := models.AuthNone
if p == nil || p.Auth == nil {
return res
}
ruid := ""
if len(ResourceUUID) > 0 {
ruid = ResourceUUID[0]
}
for _, a := range p.Auth {
if a.RID == ResourceID {
if a.RUID != "" {
if a.RUID == ruid {
if a.Level > res {
res = a.Level
}
} else {
continue
}
} else if a.Level > res {
res = a.Level
}
}
}
return res
}
func GetToken(u *models.User, uuid string, key string) (string, error) {
payload := &PayLoad{
payload := &oalib.PayLoad{
ID: u.ID,
Auth: []*SimpleAuth{},
Auth: []*oalib.SimpleAuth{},
}
for _, a := range u.GetAuths() {
if uuid == a.AppUUID {
payload.Auth = append(payload.Auth, &SimpleAuth{
payload.Auth = append(payload.Auth, &oalib.SimpleAuth{
RID: a.RID,
RUID: a.RUID,
Level: a.Level,
@ -64,6 +23,6 @@ func GetToken(u *models.User, uuid string, key string) (string, error) {
return jwt.GetToken(payload, []byte(key))
}
func ParseToken(token string, payload *PayLoad, key string) (bool, error) {
func ParseToken(token string, payload *oalib.PayLoad, key string) (bool, error) {
return jwt.ParseToken(token, payload, []byte(key))
}

@ -1,9 +1,9 @@
package main
import (
"OneAuth/cfg"
"OneAuth/sub"
"github.com/urfave/cli/v2"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/sub"
"github.com/veypi/utils/cmd"
"github.com/veypi/utils/log"
"os"
@ -14,7 +14,7 @@ const Version = "v0.1.0"
func main() {
cmd.LoadCfg(cfg.Path, cfg.CFG)
app := cli.NewApp()
app.Name = "OneAuth"
app.Name = "github.com/veypi/OneAuth"
app.Usage = "one auth"
app.Version = Version
app.Flags = []cli.Flag{

@ -1,11 +1,11 @@
package models
import (
"OneAuth/cfg"
"bytes"
"database/sql/driver"
"errors"
"fmt"
"github.com/veypi/OneAuth/cfg"
"time"
)

@ -1,5 +1,7 @@
package models
import "github.com/veypi/OneAuth/oalib"
type UserRole struct {
BaseModel
UserID uint `json:"user_id"`
@ -19,60 +21,6 @@ type Role struct {
UserCount uint `json:"user_count"`
}
// AuthLevel 权限等级
// 对于操作类权限
// 0 禁止执行
// 1 允许执行
// 对于资源类权限
// 0 相当于没有
// 1 有限读权限
// 2 读权限
// 3 创建权限
// 4 修改权限
// 5 删除权限
// 6 赋予其余人权限
type AuthLevel uint
const (
AuthNone AuthLevel = 0
AuthDo AuthLevel = 1
// AuthPart TODO: 临时权限
AuthPart AuthLevel = 1
AuthRead AuthLevel = 2
AuthCreate AuthLevel = 3
AuthUpdate AuthLevel = 4
AuthDelete AuthLevel = 5
AuthAll AuthLevel = 6
)
func (a AuthLevel) Upper(b AuthLevel) bool {
return a > b
}
func (a AuthLevel) CanDo() bool {
return a > AuthNone
}
func (a AuthLevel) CanRead() bool {
return a >= AuthRead
}
func (a AuthLevel) CanCreate() bool {
return a >= AuthCreate
}
func (a AuthLevel) CanUpdate() bool {
return a >= AuthUpdate
}
func (a AuthLevel) CanDelete() bool {
return a >= AuthDelete
}
func (a AuthLevel) CanDoAny() bool {
return a >= AuthAll
}
// Auth 资源权限
type Auth struct {
BaseModel
@ -90,8 +38,8 @@ type Auth struct {
// resource_name 用于其他系统方便区分权限的名字
RID string `json:"rid" gorm:""`
// 具体某个资源的id
RUID string `json:"ruid"`
Level AuthLevel `json:"level"`
RUID string `json:"ruid"`
Level oalib.AuthLevel `json:"level"`
}
type Resource struct {

@ -1,6 +1,7 @@
package models
import (
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/utils"
"gorm.io/gorm"
)
@ -45,8 +46,8 @@ func (u *User) GetAuths() []*Auth {
return list
}
func (u *User) GetAuth(uuid, ResourceID string, ResourceUUID ...string) AuthLevel {
var res = AuthNone
func (u *User) GetAuth(uuid, ResourceID string, ResourceUUID ...string) oalib.AuthLevel {
var res = oalib.AuthNone
ruid := ""
if len(ResourceUUID) > 0 {
ruid = ResourceUUID[0]

@ -1,3 +0,0 @@
> 1%
last 2 versions
not dead

@ -1,5 +0,0 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

@ -1 +0,0 @@
src/libs/wwLogin.js

@ -1,23 +0,0 @@
module.exports = {
root: true,
env: {
node: true
},
extends: [
'plugin:vue/essential',
'@vue/standard',
'@vue/typescript/recommended'
],
parserOptions: {
ecmaVersion: 2020
},
rules: {
'object-curly-spacing': 0,
'space-before-function-paren': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/no-explicit-any': 0,
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}

23
oaf2/.gitignore vendored

@ -1,23 +0,0 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

@ -1,24 +0,0 @@
# oaf
## Project setup
```
yarn install
```
### Compiles and hot-reloads for development
```
yarn serve
```
### Compiles and minifies for production
```
yarn build
```
### Lints and fixes files
```
yarn lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

@ -1,5 +0,0 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

@ -1,49 +0,0 @@
{
"name": "oaf",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@veypi/one-icon": "^1.0.1",
"axios": "^0.21.1",
"core-js": "^3.6.5",
"js-base64": "^3.6.0",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-m-message": "^3.1.0",
"vue-property-decorator": "^9.1.2",
"vue-router": "^3.2.0",
"vuetify": "^2.4.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-typescript": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/eslint-config-standard": "^5.1.2",
"@vue/eslint-config-typescript": "^5.0.2",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^6.2.2",
"less": "^3.0.4",
"less-loader": "^5.0.0",
"sass": "^1.32.0",
"sass-loader": "^10.0.0",
"typescript": "~3.9.3",
"vue-cli-plugin-vuetify": "^2.2.2",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.7.0"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

File diff suppressed because one or more lines are too long

@ -1,20 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- <link rel="icon" href="<%= BASE_URL %>favicon.ico">-->
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

@ -1,63 +0,0 @@
<template>
<v-app @mousewheel.native.prevent="">
<v-app-bar
app
color="primary"
dark
>
<div class="d-flex align-center">
<one-icon style="color: aqua;font-size: 56px">glassdoor</one-icon>
<span class="font-italic font-weight-bold" style="font-size: 20px">统一认证</span>
</div>
<v-spacer></v-spacer>
</v-app-bar>
<v-main>
<router-view></router-view>
</v-main>
</v-app>
</template>
<script lang="ts">
import Vue from 'vue'
import util from '@/libs/util'
export default Vue.extend({
name: 'App',
components: {},
data: () => ({
//
}),
beforeCreate() {
util.title('统一认证')
this.$store.dispatch('fetchSelf')
}
})
</script>
<style lang="less">
@import './assets/common';
html,
body {
.full_size;
margin: 0;
padding: 0;
}
#app {
.full_size;
//.none_select;
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
}
::-webkit-scrollbar {
display: none; /* Chrome Safari */
}
</style>

@ -1,65 +0,0 @@
import axios from 'axios'
import store from '@/store'
function baseRequests(url: string, method: any = 'GET', query: any, data: any, success: any, fail?: Function) {
return axios({
url: url,
params: query,
data: data,
method: method,
headers: {
auth_token: localStorage.auth_token
}
})
.then((res: any) => {
if ('auth_token' in res.headers) {
localStorage.auth_token = res.headers.auth_token
}
if (method === 'HEAD') {
success(res.headers)
} else {
success(res.data)
}
})
.catch((e: any) => {
if (e.response && e.response.status === 401) {
console.log(e)
store.dispatch('handleLogout')
return
}
console.log(e)
if (e.response && e.response.status === 500) {
return
}
if (typeof fail === 'function') {
fail(e.response)
} else if (e.response && e.response.status === 400) {
console.log(400)
} else {
console.log(e.request)
}
})
}
const ajax = {
get(url: '', data = {}, success = {}, fail?: Function) {
return baseRequests(url, 'GET', data, {}, success, fail)
},
head(url: '', data = {}, success = {}, fail?: Function) {
return baseRequests(url, 'HEAD', data, {}, success, fail)
},
delete(url: '', data = {}, success = {}, fail?: Function) {
return baseRequests(url, 'DELETE', data, {}, success, fail)
},
post(url: '', data = {}, success = {}, fail?: Function) {
return baseRequests(url, 'POST', {}, data, success, fail)
},
put(url: '', data = {}, success = {}, fail?: Function) {
return baseRequests(url, 'PUT', {}, data, success, fail)
},
patch(url: '', data = {}, success = {}, fail?: Function) {
return baseRequests(url, 'PATCH', {}, data, success, fail)
}
}
export default ajax

@ -1,216 +0,0 @@
/*
* Copyright (C) 2019 light <light@light-laptop>
*
* Distributed under terms of the MIT license.
*/
import Vue from 'vue'
import {Base64} from 'js-base64'
import ajax from './ajax'
import store from '@/store'
export type SuccessFunction<T> = (e: any) => void;
export type FailedFunction<T> = (e: any) => void;
const Code = {
42011: '无操作权限',
22031: '资源不存在 或 您无权操作该资源'
}
class Interface {
private readonly method: Function
private readonly api: string
private readonly data: any
constructor(method: Function, api: string, data?: any) {
this.method = method
this.api = api
this.data = data
}
Start(success: SuccessFunction<any>, fail?: FailedFunction<any>) {
const newFail = function (data: any) {
if (data && data.code === 40001) {
// no login
store.dispatch('handleLogout')
return
}
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
if (data && data.code > 0 && Code[data.code]) {
}
if (fail) {
fail(data)
}
}
const newSuccess = function (data: any) {
if (Number(data.status) === 1) {
if (success) {
success(data.content)
}
} else {
newFail(data)
if (data.code === 41001) {
store.dispatch('handleLogout')
// bus.$emit('log_out')
}
}
}
this.method(this.api, this.data, newSuccess, newFail)
}
}
const message = {
count() {
return new Interface(ajax.get, '/api/message/', {
count: true,
status: 'UnRead'
})
},
get_content(id: number) {
return new Interface(ajax.get, '/api/message/' + Number(id))
},
list(status: string) {
return new Interface(ajax.get, '/api/message/', {status})
},
update(id: number, status: string) {
return new Interface(ajax.patch, '/api/message/' + Number(id), {status})
}
}
const role = {
local: '/api/role/',
get(id: number) {
return new Interface(ajax.get, this.local + id)
},
list() {
return new Interface(ajax.get, this.local)
},
update(id: number, props: any) {
return new Interface(ajax.patch, this.local + id, props)
},
create(props: any) {
return new Interface(ajax.post, this.local, props)
},
del(id: number) {
return new Interface(ajax.delete, this.local + id)
},
bind(id: number, aid: number) {
return new Interface(ajax.get, this.local + id + '/bind/' + aid)
},
unbind(id: number, aid: number) {
return new Interface(ajax.get, this.local + id + '/unbind/' + aid)
}
}
const app = {
local: '/api/app/',
self() {
return new Interface(ajax.get, this.local, {is_self: true})
},
get(id: string) {
return new Interface(ajax.get, this.local + id)
},
list() {
return new Interface(ajax.get, this.local)
}
}
const user = {
local: '/api/user/',
register(username: string, password: string, uuid: string, prop?: any) {
const data = Object.assign({
username: username,
uuid: uuid,
password: Base64.encode(password)
}, prop)
return new Interface(ajax.post, this.local, data)
},
login(username: string, password: string, uuid: string) {
return new Interface(ajax.head, this.local + username, {
uid_type: 'username',
uuid: uuid,
password: Base64.encode(password)
})
}
}
const api = {
role: role,
app: app,
user: user,
admin: {
auths() {
return new Interface(ajax.get, '/api/auth/')
},
user: {
create(props: any) {
const p = Object.assign({}, props)
p.password = Base64.encode(props.password)
return new Interface(ajax.post, '/api/user/', p)
},
update(user_id: number, props: any) {
return new Interface(ajax.patch, '/api/user/' + user_id, props)
},
enable(user_id: number) {
return new Interface(ajax.patch, '/api/user/' + user_id, {
status: 'ok'
})
},
disable(user_id: number) {
return new Interface(ajax.patch, '/api/user/' + user_id, {
status: 'disabled'
})
},
attach_role(user_id: number, props: any) {
return new Interface(ajax.post, '/api/user/' + user_id + '/role/', props)
},
detach_role(user_id: number, id: any) {
return new Interface(ajax.delete, '/api/user/' + user_id + '/role/' + id)
},
reset_pass(user_id: number, password: string) {
return new Interface(ajax.patch, '/api/user/' + user_id, {password})
}
}
},
auth: {
event() {
return {
local: '/api/user/event/',
list() {
return new Interface(ajax.get, this.local)
},
create(title: string, tag: string, start_date: any, end_date: any) {
return new Interface(ajax.post, this.local, {title, tag, start_date, end_date})
},
del(id: number) {
return new Interface(ajax.delete, this.local + id)
}
}
},
favorite(name: string, tag: string, ok: boolean) {
if (ok) {
return new Interface(ajax.post, '/api/user/favorite', {name, tag})
}
return new Interface(ajax.delete, '/api/user/favorite', {name, tag})
},
get(id: number) {
return new Interface(ajax.get, '/api/user/' + id)
},
search(username: string) {
return new Interface(ajax.get, '/api/user/', {
username
})
}
},
message: message
}
const Api = {
install(vue: typeof Vue): void {
vue.prototype.$api = api
}
}
export {Api}
export default api

@ -1,25 +0,0 @@
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
.full_size {
width: 100%;
height: 100%;
}
.none_select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.none_border{
border: none;
}
.none_border_input {
.ivu-input {
.none_border;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

@ -1 +0,0 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 87.5 100"><defs><style>.cls-1{fill:#1697f6;}.cls-2{fill:#7bc6ff;}.cls-3{fill:#1867c0;}.cls-4{fill:#aeddff;}</style></defs><title>Artboard 46</title><polyline class="cls-1" points="43.75 0 23.31 0 43.75 48.32"/><polygon class="cls-2" points="43.75 62.5 43.75 100 0 14.58 22.92 14.58 43.75 62.5"/><polyline class="cls-3" points="43.75 0 64.19 0 43.75 48.32"/><polygon class="cls-4" points="64.58 14.58 87.5 14.58 43.75 100 43.75 62.5 64.58 14.58"/></svg>

Before

Width:  |  Height:  |  Size: 539 B

@ -1,44 +0,0 @@
<template>
<div id="wx_reg"></div>
</template>
<script lang='ts'>
import {Component, Vue, Prop} from 'vue-property-decorator'
import '@/libs/wwLogin.js'
@Component({
components: {}
})
export default class WxLogin extends Vue {
goto(id: string, app: string, url: string, state?: number, href?: string) {
// eslint-disable-next-line
// @ts-ignore
window.WwLogin({
id: 'wx_reg',
appid: id,
agentid: app,
redirect_uri: encodeURIComponent(url),
state: state,
href: href
})
}
@Prop({default: ''})
aid = ''
@Prop({default: ''})
app = ''
@Prop({default: ''})
url = ''
mounted() {
this.goto(this.aid, this.app, this.url, new Date().getTime())
}
created() {
}
}
</script>
<style scoped>
</style>

@ -1,33 +0,0 @@
<template>
<v-card class="core" elevation="4">
<v-system-bar color="info">
<one-icon>mail</one-icon>
<v-spacer></v-spacer>
<one-icon>user-group</one-icon>
<span>*{{ core.user_count }}</span>
</v-system-bar>
<div></div>
</v-card>
</template>
<script lang='ts'>
import {Component, Prop, Vue} from 'vue-property-decorator'
@Component({
components: {}
})
export default class AppCard extends Vue {
@Prop({default: {}})
core: any
mounted() {
console.log(this.core)
}
}
</script>
<style scoped>
.core {
width: 256px;
background: #2c3e50;
height: 128px;
}
</style>

@ -1,20 +0,0 @@
<template>
<div></div>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
@Component({
components: {}
})
export default class Demo extends Vue {
mounted() {
}
created() {
}
}
</script>
<style scoped>
</style>

@ -1,64 +0,0 @@
function padLeftZero(str: string): string {
return ('00' + str).substr(str.length)
}
const util = {
title: function (title: string) {
window.document.title = title ? title + ' - oa' : 'veypi project'
},
getCookie(name: string) {
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
const arr = document.cookie.match(reg)
if (arr) {
return unescape(arr[2])
} else return null
},
delCookie(name: string) {
const exp = new Date()
exp.setTime(exp.getTime() - 1)
const cval = this.getCookie(name)
if (cval !== null) {
document.cookie = name + '=' + cval + ';expires=' + exp.toLocaleString()
}
},
setCookie(name: string, value: string, time: number) {
const exp = new Date()
exp.setTime(exp.getTime() + time)
document.cookie =
name + '=' + escape(value) + ';expires=' + exp.toLocaleString()
},
checkLogin() {
// return parseInt(this.getCookie('stat')) === 1
return Boolean(localStorage.auth_token)
},
formatDate(date: Date, fmt: string) {
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
(date.getFullYear() + '').substr(4 - RegExp.$1.length)
)
}
const o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
}
for (const k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const str = o[k] + ''
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length === 1 ? str : padLeftZero(str)
)
}
}
return fmt
}
}
export default util

@ -1,2 +0,0 @@
!function(a,b,c){function d(c){var d=b.createElement("iframe"),e="https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid="+c.appid+"&agentid="+c.agentid+"&redirect_uri="+c.redirect_uri+"&state="+c.state+"&login_type=jssdk";e+=c.style?"&style="+c.style:"",e+=c.href?"&href="+c.href:"",d.src=e,d.frameBorder="0",d.allowTransparency="true",d.scrolling="no",d.width="300px",d.height="400px";var f=b.getElementById(c.id);f.innerHTML="",f.appendChild(d),d.onload=function(){d.contentWindow.postMessage&&a.addEventListener&&(a.addEventListener("message",function(b){
b.data&&b.origin.indexOf("work.weixin.qq.com")>-1&&(a.location.href=b.data)}),d.contentWindow.postMessage("ask_usePostMessage","*"))}}a.WwLogin=d}(window,document);

@ -1,24 +0,0 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify'
import {Api} from '@/api'
import OneIcon from '@veypi/one-icon'
import Message from 'vue-m-message'
import 'vue-m-message/dist/index.css'
Vue.use(Message) // will mount `Vue.prototype.$message`
// Vue.use(OneIcon, {href: 'https://at.alicdn.com/t/font_2872366_7aws02sx9bl.js'})
Vue.use(OneIcon, {href: './icon.js'})
Vue.use(Api)
Vue.config.productionTip = false
new Vue({
router,
store,
vuetify,
render: h => h(App)
}).$mount('#app')

@ -1,24 +0,0 @@
import Vue from 'vue'
import Vuetify from 'vuetify/lib/framework'
Vue.use(Vuetify)
const light = {
primary: '#2196f3',
secondary: '#00bcd4',
accent: '#3f51b5',
error: '#f44336',
warning: '#ff5722',
info: '#ff9800',
success: '#4caf50',
reset: '#684bff'
}
export default new Vuetify({
theme: {
dark: false,
themes: {
light: light
}
}
})

@ -1,57 +0,0 @@
import Vue from 'vue'
import VueRouter, {RouteConfig} from 'vue-router'
import Home from '../views/Home.vue'
import Demo from '@/views/demo.vue'
import Login from '@/views/login.vue'
import Register from '@/views/register.vue'
import NotFound from '@/views/404.vue'
Vue.use(VueRouter)
// 避免push到相同路径报错
// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location: any) {
// eslint-disable-next-line
// @ts-ignore
return originalPush.call(this, location).catch(err => err)
}
const routes: Array<RouteConfig> = [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/app',
name: 'app',
component: Demo
},
{
path: '/login/:uuid?',
name: 'login',
component: Login
},
{
path: '/register/:uuid?',
name: 'register',
component: Register
},
{
path: '/wx',
name: 'wx',
component: () => import('../views/wx.vue')
},
{
path: '*',
name: '404',
component: NotFound
}
]
const router = new VueRouter({
routes
})
export default router

@ -1,13 +0,0 @@
import Vue, { VNode } from 'vue'
declare global {
namespace JSX {
// tslint:disable no-empty-interface
interface Element extends VNode {}
// tslint:disable no-empty-interface
interface ElementClass extends Vue {}
interface IntrinsicElements {
[elem: string]: any;
}
}
}

@ -1,5 +0,0 @@
declare module '*.js'
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}

@ -1,4 +0,0 @@
declare module 'vuetify/lib/framework' {
import Vuetify from 'vuetify'
export default Vuetify
}

@ -1,30 +0,0 @@
import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/api'
import router from '@/router'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
oauuid: '',
user: null
},
mutations: {
setOA(state: any, data: any) {
state.oauuid = data.uuid
}
},
actions: {
fetchSelf({commit}) {
api.app.self().Start(d => {
commit('setOA', d)
})
},
handleLogout() {
localStorage.removeItem('auth_token')
router.push({name: 'login'})
}
},
modules: {}
})

@ -1,14 +0,0 @@
// 1. 确保在声明补充的类型之前导入 'vue'
import Vue from 'vue'
import api from '@/api'
export type PluginFunction<T> = (Vue: typeof Vue, options?: T) => void;
// 2. 定制一个文件,设置你想要补充的类型
// 在 types/vue.d.ts 里 Vue 有构造函数类型
declare module 'vue/types/vue' {
// 3. 声明为 Vue 补充的东西
interface Vue {
$api: typeof api;
}
}

@ -1,24 +0,0 @@
<style>
</style>
<template>
<div class='home d-flex justify-center align-center'>
<one-icon style="font-size: 100px">404</one-icon>
</div>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
import util from '@/libs/util'
@Component({
components: {}
})
export default class NotFound extends Vue {
mounted() {
}
created() {
util.title('404')
}
}
</script>

@ -1,50 +0,0 @@
<style>
.home {
height: 100%;
width: 100%;
}
</style>
<template>
<div class='full_size'>
<v-row no-gutters class="pa-8">
<v-col v-for="(item, key) in apps" :key="key" class="mx-4 my-2">
<AppCard :core="item"></AppCard>
</v-col>
</v-row>
</div>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
import util from '@/libs/util'
import AppCard from '@/components/app.vue'
@Component({
components: {
AppCard
}
})
export default class Home extends Vue {
apps = []
getApps() {
this.$api.app.list().Start(d => {
console.log(d)
this.apps = d
})
}
mounted() {
this.getApps()
}
created() {
}
beforeCreate() {
if (!util.checkLogin()) {
this.$router.push({name: 'login', query: this.$route.query, params: this.$route.params})
}
}
}
</script>

@ -1,21 +0,0 @@
<style>
</style>
<template>
<div class='home d-flex justify-center align-center'>
</div>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
@Component({
components: {}
})
export default class Demo extends Vue {
mounted() {
}
created() {
}
}
</script>

@ -1,123 +0,0 @@
<style>
</style>
<template>
<v-row align="center" class="fill-height" justify="center" style="background: #ebebeb">
<v-col cols="12" sm="8" md="6" lg="4" xl="3">
<v-card class="elevation-12 mx-5" style="opacity: 0.8">
<v-row justify="center">
<v-col cols="10">
<v-card class="elevation-1 mt-n12 primary theme--dark">
<v-card-text class="text-center">
<h1 class="display-2 font-weight-bold mb-2">Login</h1>
<v-tooltip left>
<template v-slot:activator="{ on }">
<v-btn icon large v-on="on">
<v-icon>mdi-cellphone</v-icon>
</v-btn>
</template>
<span style="font-family:'Noto Sans Armenian'">手机登录</span>
</v-tooltip>
<v-tooltip right>
<template v-slot:activator="{ on }">
<v-btn icon large v-on="on">
<v-icon>mdi-barcode</v-icon>
</v-btn>
</template>
<span>授权码登录</span>
</v-tooltip>
</v-card-text>
</v-card>
</v-col>
</v-row>
<v-card-text>
<v-form ref="form">
<v-text-field
v-model="formInline.user"
:counter="16"
:rules="ruleInline.user"
label="账号"
required
prepend-inner-icon="mdi-account-circle"
></v-text-field>
<v-text-field
v-model="formInline.password"
type="password"
:counter="16"
:rules="ruleInline.password"
label="密码"
prepend-inner-icon="mdi-lock"
@keyup.enter="handleSubmit"
required
></v-text-field>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer/>
<v-btn type="primary" @click="handleSubmit"></v-btn>
<router-link :to="{name: 'register', query:$route.query, params: $route.params}"
style="text-decoration: none;">
<v-btn type="primary" style="margin-left:8px">注册</v-btn>
</router-link>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
import util from '@/libs/util'
@Component({
components: {}
})
export default class Login extends Vue {
formInline = {
user: '',
password: ''
}
ruleInline = {
user: [
(v: string) => !!v || 'required',
(v: string) => (v && v.length >= 3 && v.length <= 16) || '长度要求3~16'
],
password: [
(v: string) => !!v || 'required',
(v: string) => (v && v.length >= 6 && v.length <= 16) || '长度要求6~16'
]
}
get app_uuid() {
return this.$route.params.uuid || this.$store.state.oauuid
}
handleSubmit() {
// eslint-disable-next-line
// @ts-ignore
if (!this.$refs.form.validate()) {
return
}
this.$api.user.login(this.formInline.user, this.formInline.password, this.app_uuid).Start(
data => {
console.log(data)
if (util.checkLogin()) {
// this.$message.success('')
// EventBus.$emit('login', true)
this.$nextTick(() => {
if (this.$route.query.redirect) {
window.location.href = this.$route.query.redirect as string
}
this.$router.push({name: 'home'})
})
} else {
// this.$message.error('')
}
},
() => {
// this.$message.error('')
}
)
}
}
</script>

@ -1,124 +0,0 @@
<style>
</style>
<template>
<v-row class="fill-height" align="center" justify="center" style="background: #ebebeb">
<v-col cols="12" sm="8" md="6" lg="4" xl="3">
<v-card class="elevation-12 mx-5" style="opacity: 0.8">
<v-row justify="center">
<v-card class="elevation-1 mt-n7 primary" style="width: 80%">
<v-card-actions>
<v-row>
<v-icon
style="position: absolute;left: 10px;top:19px;z-index: 1"
@click="$router.back()"
size="36"
>mdi-arrow-left-circle
</v-icon>
<v-col cols="12" class="text-center">
<h1 class="display-2 ">注册</h1>
</v-col>
</v-row>
</v-card-actions>
</v-card>
</v-row>
<v-card-text class="text-center">
<v-form ref="form">
<v-text-field
type="text"
prepend-inner-icon="mdi-account-circle"
v-model="form.username"
label="账号"
:rules="ruleInline.user"
:counter="16"
>
</v-text-field>
<v-text-field
type="password"
v-model="form.passwd"
label="密码"
prepend-inner-icon="mdi-lock"
:rules="ruleInline.password"
:counter="16"
></v-text-field>
<v-text-field
type="password"
v-model="form.passwdCheck"
label="密码"
prepend-inner-icon="mdi-lock"
:rules="ruleInline.passwordCheck"
:counter="16"
@keyup.enter="handleSubmit"
></v-text-field>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn type="primary" @click="handleSubmit"></v-btn>
<v-btn @click="handleReset()"></v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
@Component({
components: {}
})
export default class Register extends Vue {
form = {
passwd: '',
passwdCheck: '',
email: '',
username: ''
}
ruleInline = {
user: [
(v: string) => !!v || 'required',
(v: string) => (v && v.length >= 3 && v.length <= 16) || '长度要求3~16'
],
password: [
(v: string) => !!v || 'required',
(v: string) => (v && v.length >= 6 && v.length <= 16) || '长度要求6~16'
],
passwordCheck: [
(v: string) => !!v || 'required',
(v: string) => (v && v === this.form.passwd) || '密码不一致'
]
}
get app_uuid() {
return this.$route.params.uuid || this.$store.state.oauuid
}
handleSubmit() {
// eslint-disable-next-line
// @ts-ignore
if (!this.$refs.form.validate()) {
return
}
this.$api.user.register(this.form.username, this.form.passwd, this.app_uuid).Start(
() => {
this.$message.success('注册成功!')
this.$router.push({name: 'login', params: this.$route.params, query: this.$route.query})
},
(data) => {
if (data && data.code === '31011') {
this.$message.error('用户名重复')
} else {
this.$message.error('注册失败')
}
}
)
}
handleReset() {
this.form.username = ''
this.form.passwd = ''
this.form.passwdCheck = ''
}
}
</script>

@ -1,66 +0,0 @@
<template>
<div class='home d-flex justify-center align-center'>
<wx-login v-if="enable" :aid="aid" :app="agentID" :url="url"></wx-login>
<v-overlay :value="!enable">
<v-progress-circular
indeterminate
size="64"
></v-progress-circular>
</v-overlay>
</div>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
import WxLogin from '@/components/WxLogin.vue'
@Component({
components: {
WxLogin
}
})
export default class Wx extends Vue {
aid = ''
agentID = ''
url = ''
get enable() {
return this.uuid && this.aid && this.agentID && this.url
}
get uuid() {
return this.$route.query.uuid
}
get code() {
return this.$route.query.code
}
get state() {
return this.$route.query.state
}
get msg() {
return this.$route.query.msg
}
mounted() {
if (this.msg) {
console.log(this.msg)
alert(this.msg)
}
}
created() {
if (this.uuid) {
this.$api.app.get(this.uuid as string).Start(e => {
this.url = e.wx.url + '/api/wx/login/' + this.uuid
this.aid = e.wx.corp_id
this.agentID = e.wx.agent_id
})
}
}
}
</script>
<style scoped>
</style>

@ -1,40 +0,0 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}

@ -1,28 +0,0 @@
module.exports = {
transpileDependencies: [
'vuetify'
],
configureWebpack: {
output: {
filename: '[name].[hash].js'
}
},
outputDir: '../sub/static',
devServer: {
host: '0.0.0.0',
port: 19520,
disableHostCheck: true,
proxy: {
'^/api': {
target: 'http://127.0.0.1:4001',
ws: true,
changeOrigin: true
},
'^/media': {
target: 'http://127.0.0.1:4001',
ws: true,
changeOrigin: true
}
}
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,62 @@
package oalib
/**
* @name: auth
* @author: veypi <i@veypi.com>
* @date: 2021-11-17 16:49
* @descriptionauth
**/
// AuthLevel 权限等级
// 对于操作类权限
// 0 禁止执行
// 1 允许执行
// 对于资源类权限
// 0 相当于没有
// 1 有限读权限
// 2 读权限
// 3 创建权限
// 4 修改权限
// 5 删除权限
// 6 赋予其余人权限
type AuthLevel uint
const (
AuthNone AuthLevel = 0
AuthDo AuthLevel = 1
// AuthPart TODO: 临时权限
AuthPart AuthLevel = 1
AuthRead AuthLevel = 2
AuthCreate AuthLevel = 3
AuthUpdate AuthLevel = 4
AuthDelete AuthLevel = 5
AuthAll AuthLevel = 6
)
func (a AuthLevel) Upper(b AuthLevel) bool {
return a > b
}
func (a AuthLevel) CanDo() bool {
return a > AuthNone
}
func (a AuthLevel) CanRead() bool {
return a >= AuthRead
}
func (a AuthLevel) CanCreate() bool {
return a >= AuthCreate
}
func (a AuthLevel) CanUpdate() bool {
return a >= AuthUpdate
}
func (a AuthLevel) CanDelete() bool {
return a >= AuthDelete
}
func (a AuthLevel) CanDoAny() bool {
return a >= AuthAll
}

@ -0,0 +1,22 @@
package oalib
/**
* @name: config
* @author: veypi <i@veypi.com>
* @date: 2021-11-17 16:30
* @descriptionconfig
* @update: 2021-11-17 16:30
**/
type Config struct {
Host string
UUID string
Key string
}
func (c *Config) Valid() bool {
if c != nil && c.Host != "" && c.UUID != "" && c.Key != "" {
return true
}
return false
}

@ -0,0 +1,36 @@
package oalib
import (
"fmt"
"github.com/veypi/utils/jwt"
)
/**
* @name: main
* @author: veypi <i@veypi.com>
* @date: 2021-11-17 16:28
* @descriptionmain
**/
func New(c *Config) *OA {
if !c.Valid() {
panic("invalid oa config")
}
return &OA{cfg: c, Key: []byte(c.Key)}
}
type OA struct {
cfg *Config
Key []byte
}
func (oa *OA) Ping() {
}
func (oa *OA) LoginUrl() string {
return fmt.Sprintf("%s/login?uuid=%s", oa.cfg.Host, oa.cfg.Key)
}
func (oa *OA) Parse(token string, payload jwt.PayloadInterface) (bool, error) {
return jwt.ParseToken(token, payload, oa.Key)
}

@ -0,0 +1,54 @@
package oalib
/**
* @name: payload
* @author: veypi <i@veypi.com>
* @date: 2021-11-17 16:45
* @descriptionpayload
**/
import (
"github.com/veypi/utils/jwt"
)
type SimpleAuth struct {
RID string `json:"rid"`
// 具体某个资源的id
RUID string `json:"ruid"`
Level AuthLevel `json:"level"`
}
// PayLoad TODO:: roles 是否会造成token过大 ?
type PayLoad struct {
jwt.Payload
ID uint `json:"id"`
Auth []*SimpleAuth `json:"auth"`
}
// GetAuth resource_uuid 缺省或仅第一个有效 权限会被更高权限覆盖
func (p *PayLoad) GetAuth(ResourceID string, ResourceUUID ...string) AuthLevel {
res := AuthNone
if p == nil || p.Auth == nil {
return res
}
ruid := ""
if len(ResourceUUID) > 0 {
ruid = ResourceUUID[0]
}
for _, a := range p.Auth {
if a.RID == ResourceID {
if a.RUID != "" {
if a.RUID == ruid {
if a.Level > res {
res = a.Level
}
} else {
continue
}
} else if a.Level > res {
res = a.Level
}
}
}
return res
}

@ -1,9 +1,9 @@
package sub
import (
"OneAuth/cfg"
"OneAuth/models"
"github.com/urfave/cli/v2"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/models"
"github.com/veypi/utils"
"github.com/veypi/utils/log"
)

@ -1,10 +1,11 @@
package sub
import (
"OneAuth/cfg"
"OneAuth/libs/auth"
"OneAuth/models"
"github.com/urfave/cli/v2"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/libs/auth"
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/utils"
)
@ -95,7 +96,7 @@ func role(reset_init_role bool) error {
return err
}
authMap[na] = a
err = auth.BindRoleAuth(cfg.DB(), adminRole.ID, a.ID, models.AuthAll, "")
err = auth.BindRoleAuth(cfg.DB(), adminRole.ID, a.ID, oalib.AuthAll, "")
if err != nil {
return err
}
@ -108,7 +109,7 @@ func role(reset_init_role bool) error {
if err != nil {
return err
}
e1 := auth.BindRoleAuth(cfg.DB(), userRole.ID, authMap[auth.APP].ID, models.AuthRead, "")
e1 := auth.BindRoleAuth(cfg.DB(), userRole.ID, authMap[auth.APP].ID, oalib.AuthRead, "")
if err := utils.MultiErr(e1); err != nil {
return err
}

@ -1,9 +1,9 @@
package sub
import (
"OneAuth/cfg"
"OneAuth/models"
"github.com/urfave/cli/v2"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneAuth/models"
"github.com/veypi/utils/log"
)

@ -1,9 +1,9 @@
package sub
import (
"OneAuth/api"
"OneAuth/cfg"
"github.com/urfave/cli/v2"
"github.com/veypi/OneAuth/api"
"github.com/veypi/OneAuth/cfg"
"github.com/veypi/OneBD"
"github.com/veypi/utils/log"
)

Loading…
Cancel
Save