Skip to content

Commit

Permalink
fix(status): check secure context, fix #171
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 22, 2021
1 parent 19f253e commit 2738d34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
15 changes: 10 additions & 5 deletions packages/plugin-status/client/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable no-undef */

import { createApp, defineAsyncComponent } from 'vue'
import { createApp, defineAsyncComponent, Ref } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import Card from './components/card.vue'
import Collapse from './components/collapse.vue'
import Button from './components/button.vue'
import Input from './components/input.vue'
import App from './views/layout/index.vue'
import { start, user, receive } from '.'
import * as client from '.'

import '@fortawesome/fontawesome-free/css/fontawesome.css'
import '@fortawesome/fontawesome-free/css/brands.css'
Expand All @@ -16,13 +17,17 @@ import '@fortawesome/fontawesome-free/css/solid.css'

import './index.scss'

type Keys<O, T = any> = {
[K in keyof O]: O[K] extends T ? K : never
}[keyof O]

declare module 'vue-router' {
interface RouteMeta {
icon?: string
hidden?: boolean
authorize?: boolean
frameless?: boolean
require?: ('stats' | 'profile' | 'registry')[]
require?: Keys<typeof client, Ref>[]
}
}

Expand All @@ -48,12 +53,12 @@ const router = createRouter({
}, {
path: '/sandbox',
name: '沙盒',
meta: { icon: 'laptop-code', authorize: true },
meta: { icon: 'laptop-code', require: ['user'] },
component: () => import('./views/sandbox.vue'),
}, {
path: '/profile',
name: '资料',
meta: { icon: 'user-circle', authorize: true, hidden: true },
meta: { icon: 'user-circle', require: ['user'], hidden: true },
component: () => import('./views/profile.vue'),
}, {
path: '/login',
Expand All @@ -79,7 +84,7 @@ receive('expire', () => {
})

router.beforeEach((route) => {
if (route.meta.authorize && !user.value) {
if (route.meta.require.includes('user') && !user.value) {
return '/login'
}
})
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-status/client/views/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
</div>
</template>
<template v-else>
<h1>
<h1 v-if="secure">
<span :class="{ inactive: config.authType === 1 }" @click="config.authType = 0">平台账户登录</span>
/
<span :class="{ inactive: config.authType === 0 }" @click="config.authType = 1">用户名密码登录</span>
</h1>
<h1 v-else><span>平台账户登录</span></h1>
<template v-if="config.authType === 0">
<k-input prefix="at" placeholder="平台名" v-model="config.platform"/>
<k-input prefix="user" placeholder="账号" v-model="config.userId" @enter="enter"/>
Expand Down Expand Up @@ -53,6 +54,9 @@ interface LoginData {
message?: string
}
const secure = isSecureContext
if (!secure) config.value.authType = 0
const data = ref<LoginData>({})
const router = useRouter()
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-status/client/views/profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>用户名:{{ user.name }}</p>
<p>权限等级:{{ user.authority }}</p>
</k-card>
<k-card title="设置密码">
<k-card title="设置密码" v-if="secure">
<k-input v-model="password" @enter="enter"
:type="config.showPass ? 'text' : 'password'"
:suffix="config.showPass ? 'eye' : 'eye-slash'"
Expand All @@ -20,6 +20,7 @@
import { user, config, send, sha256 } from '~/client'
import { ref } from 'vue'
const secure = isSecureContext
const password = ref(config.value.password)
async function enter() {
Expand Down

0 comments on commit 2738d34

Please sign in to comment.