mirror of https://github.com/veypi/OneAuth.git
用户权限编辑 登录跳转
parent
f90d4c9371
commit
e081e4ecb6
@ -1,12 +1,46 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/veypi/OneAuth/cfg"
|
||||
"github.com/veypi/OneAuth/models"
|
||||
"github.com/veypi/OneAuth/oalib"
|
||||
"github.com/veypi/OneBD"
|
||||
"github.com/veypi/OneBD/rfc"
|
||||
"github.com/veypi/utils/jwt"
|
||||
)
|
||||
|
||||
func Router(r OneBD.Router) {
|
||||
r.Set("/", appHandlerP, rfc.MethodPost, rfc.MethodGet)
|
||||
r.Set("/:uuid", appHandlerP, rfc.MethodGet, rfc.MethodPatch)
|
||||
r.Set("/:uuid/user/:id", auHandlerP, rfc.MethodAll)
|
||||
r.Set("/:uuid/ping", ping, rfc.MethodGet)
|
||||
}
|
||||
|
||||
func ping(m OneBD.Meta) {
|
||||
var err error
|
||||
defer func() {
|
||||
if err != nil {
|
||||
m.WriteHeader(rfc.StatusBadRequest)
|
||||
m.Write([]byte(err.Error()))
|
||||
} else {
|
||||
m.WriteHeader(rfc.StatusOK)
|
||||
m.Write([]byte("ok"))
|
||||
}
|
||||
}()
|
||||
t := m.GetHeader("auth_token")
|
||||
uuid := m.Params("uuid")
|
||||
a := &models.App{}
|
||||
err = cfg.DB().Where("UUID = ?", uuid).First(a).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
p := &oalib.PayLoad{}
|
||||
ok, err := jwt.ParseToken(t, p, []byte(a.Key))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
err = errors.New("invalid key")
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-select
|
||||
filterable
|
||||
placeholder="搜索用户"
|
||||
:options="options"
|
||||
:loading="loading"
|
||||
clearable
|
||||
remote
|
||||
@search="handleSearch"
|
||||
@update-value="select"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {ref} from 'vue'
|
||||
import api from '@/api'
|
||||
import {modelsUser} from '@/models'
|
||||
|
||||
let emits = defineEmits<{
|
||||
(e: 'selected', v:modelsUser): void
|
||||
}>()
|
||||
let options = ref([])
|
||||
let loading = ref(false)
|
||||
|
||||
function select(v, o) {
|
||||
emits('selected', o.user)
|
||||
}
|
||||
|
||||
function handleSearch(query: string) {
|
||||
if (!query.length) {
|
||||
options.value = []
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
api.user.search(query).Start((e: modelsUser[]) => {
|
||||
let l = []
|
||||
for (let u of e) {
|
||||
l.push({
|
||||
label: u.Username,
|
||||
value: u.ID,
|
||||
user: u,
|
||||
})
|
||||
}
|
||||
options.value = l
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
Loading…
Reference in New Issue