Modify login process
This commit is contained in:
+2
-1
@@ -7,7 +7,8 @@ const headers = {
|
||||
const listAll = () => {
|
||||
return request({
|
||||
url: '/auth/api/v1/author/blog/list',
|
||||
method: 'GET'
|
||||
method: 'GET',
|
||||
headers: headers
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -3,7 +3,7 @@ import request from '../utils/request'
|
||||
const get_notes = (params: Object) => {
|
||||
return request({
|
||||
url: '/auth/api/v1/one_note',
|
||||
method: 'get',
|
||||
method: 'GET',
|
||||
params: params
|
||||
})
|
||||
}
|
||||
@@ -11,7 +11,7 @@ const get_notes = (params: Object) => {
|
||||
const update_page = (params: Object) => {
|
||||
return request({
|
||||
url: '/auth/api/v1/one_note/update_page',
|
||||
method: 'post',
|
||||
method: 'POST',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
@@ -19,7 +19,7 @@ const update_page = (params: Object) => {
|
||||
const update_section = (params: Object) => {
|
||||
return request({
|
||||
url: '/auth/api/v1/one_note/update_section',
|
||||
method: 'post',
|
||||
method: 'POST',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
@@ -27,14 +27,14 @@ const update_section = (params: Object) => {
|
||||
const insert_section = () => {
|
||||
return request({
|
||||
url: '/auth/api/v1/one_note/insert_section',
|
||||
method: 'put'
|
||||
method: 'PUT'
|
||||
})
|
||||
}
|
||||
|
||||
const insert_page = (params: Object) => {
|
||||
return request({
|
||||
url: '/auth/one_note/insert_page',
|
||||
method: 'put',
|
||||
method: 'PUT',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
+9
-1
@@ -15,4 +15,12 @@ const obtainUserInfo = (token: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export { authorize, obtainUserInfo }
|
||||
const logout = (id: string) => {
|
||||
return request({
|
||||
url: '/auth/api/v1/logout/' + id,
|
||||
method: 'GET'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export { authorize, obtainUserInfo, logout }
|
||||
@@ -0,0 +1,15 @@
|
||||
<template>
|
||||
<span class="dialog-footer">
|
||||
当你看到了,这个页面,这表示了,你通过百度扫描登陆了我的秘密基地,但是很遗憾的告诉你,我们将以非法登录的方式处理你的请求,88
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.dashboard {
|
||||
background-color: beige;
|
||||
}
|
||||
</style>
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="nav-main">
|
||||
当前时间:{{ time }}
|
||||
<span>论一个程序员的寂寞与忧伤</span>
|
||||
<el-dropdown trigger="click" v-show="user.owner">
|
||||
<el-dropdown trigger="click" v-show="tenant.account">
|
||||
<el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
@@ -11,7 +11,7 @@
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<span @click="doLogin" v-show="!user.owner">登录</span>
|
||||
<span @click="doLogin" v-show="!tenant.account">登录</span>
|
||||
</div>
|
||||
<el-dialog v-model="dialogVisible" title="提示" width="30%">
|
||||
<span>确认你的登出操作么?</span>
|
||||
@@ -28,10 +28,11 @@
|
||||
import $moment from "moment";
|
||||
import { reactive, ref } from "vue";
|
||||
import router from '../../router'
|
||||
import { useUserStore } from '../../store/user'
|
||||
import { useTenantStore } from '../../store/tenant'
|
||||
import { logout } from '../../api/user'
|
||||
// obtain user infomation
|
||||
const user = useUserStore()
|
||||
user.reflush()
|
||||
const tenant = useTenantStore()
|
||||
tenant.reflush()
|
||||
const dialogVisible = ref(false)
|
||||
|
||||
// show time
|
||||
@@ -48,9 +49,11 @@ const doLogin = () => {
|
||||
}
|
||||
const doLogout = () => {
|
||||
dialogVisible.value = false
|
||||
user.logout()
|
||||
router.push({
|
||||
path: '/home'
|
||||
logout(tenant.id).then(() => {
|
||||
tenant.logout()
|
||||
router.push({
|
||||
path: '/login'
|
||||
})
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -34,15 +34,15 @@
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { useUserStore } from '../../store/user'
|
||||
import { useTenantStore } from '../../store/tenant'
|
||||
import router from '../../router'
|
||||
import baiduCloudImage from "../../assets/baiducloud.png"
|
||||
import config from '../../const/config'
|
||||
import { getQrCode } from '../../api/login'
|
||||
|
||||
|
||||
let qrcode = config.BAIDU_CLOUD_URL + config.RESPONSE_TYPE + config.CLIENT_ID + config.REDIRECT_URI + config.SCOPE + config.DEVICE_ID + config.QR_CODE + config.DISPLAY
|
||||
|
||||
const user = useUserStore()
|
||||
const tenant = useTenantStore()
|
||||
|
||||
const ruleFormRef = ref<FormInstance>()
|
||||
const loginForm = reactive({
|
||||
@@ -50,13 +50,6 @@ const loginForm = reactive({
|
||||
password: ''
|
||||
})
|
||||
|
||||
const loginWithBaiDu = () => {
|
||||
window.open("", "11");
|
||||
// getQrCode().then((response) => {
|
||||
|
||||
// })
|
||||
}
|
||||
|
||||
const validateUserName = (rule: any, value: string, callback: Function) => {
|
||||
if (!value) {
|
||||
callback(new Error("请输入的用户名"))
|
||||
@@ -83,7 +76,7 @@ const dologin = (form: any) => {
|
||||
return
|
||||
form.validate((valid: any) => {
|
||||
if (valid) {
|
||||
user.login(loginForm.user_id, loginForm.password).then(res => {
|
||||
tenant.login(loginForm.user_id, loginForm.password).then(res => {
|
||||
console.log(1)
|
||||
router.push({
|
||||
path: '/home'
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
type User = {
|
||||
type Tenant = {
|
||||
id: string,
|
||||
username: string
|
||||
account: string
|
||||
}
|
||||
|
||||
export { User }
|
||||
export { Tenant }
|
||||
|
||||
+25
-11
@@ -12,8 +12,8 @@ let app = createApp(App)
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.use(store)
|
||||
import { getToken, getUser, setToken, setUser } from './utils/auth'
|
||||
import { User } from './entity/index'
|
||||
import { getToken, getTenant, setToken, setTenant } from './utils/auth'
|
||||
import { Tenant } from './entity/index'
|
||||
import Cookies from 'js-cookie'
|
||||
import { obtainUserInfo } from './api/user'
|
||||
const whiteList = ['/login']
|
||||
@@ -21,13 +21,29 @@ let url = window.location.href
|
||||
|
||||
async function checktoken(url: string) {
|
||||
if (url.search("token") != -1) {
|
||||
let authorizeToken = url.split("token=")[1]
|
||||
setToken(authorizeToken)
|
||||
|
||||
const list = url.split("?token=")
|
||||
|
||||
let base_url = list[0]
|
||||
let authorizeToken = list[1]
|
||||
if (list.length < 2 || authorizeToken.length == 0) {
|
||||
router.push({
|
||||
path: '/illustration',
|
||||
})
|
||||
return
|
||||
}
|
||||
await obtainUserInfo(authorizeToken).then(response => {
|
||||
setUser(response.data)
|
||||
|
||||
if (response.status == 200) {
|
||||
const tenant = {
|
||||
id: response.data.id,
|
||||
account: response.data.account
|
||||
}
|
||||
setToken(authorizeToken)
|
||||
setTenant(tenant)
|
||||
window.open(base_url, "_self")
|
||||
}
|
||||
})
|
||||
let base_url = url.split("?token=")[0]
|
||||
window.open(base_url, "_self")
|
||||
}
|
||||
}
|
||||
checktoken(url)
|
||||
@@ -52,7 +68,7 @@ router.beforeEach((to, from, next) => {
|
||||
next('/')
|
||||
break;
|
||||
case '/':
|
||||
const user = <User>(JSON.parse(getUser() as string))
|
||||
const tenant = <Tenant>(JSON.parse(getTenant() as string))
|
||||
if (url.search("write") != -1) {
|
||||
next('/BlogEditer')
|
||||
} else if (url.search("view") != -1) {
|
||||
@@ -61,12 +77,10 @@ router.beforeEach((to, from, next) => {
|
||||
path: '/BlogViewer',
|
||||
query: { bid: bid }
|
||||
})
|
||||
// next('/BlogViewer')
|
||||
console.log(1)
|
||||
} else {
|
||||
router.push({
|
||||
path: '/home',
|
||||
query: user
|
||||
query: tenant
|
||||
})
|
||||
}
|
||||
break;
|
||||
|
||||
+5
-1
@@ -78,7 +78,11 @@ const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: "/login",
|
||||
component: () => import('../components/login/login.vue')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/illustration",
|
||||
component: () => import('../components/illustration/index.vue')
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { defineStore, acceptHMRUpdate } from 'pinia'
|
||||
import { authorize } from '../api/user'
|
||||
import { getToken, setToken, resetToken, setTenant, getTenant } from '../utils/auth'
|
||||
import { Tenant } from '../entity/index'
|
||||
|
||||
/**
|
||||
* Simulate a login
|
||||
* @param {string} a
|
||||
* @param {string} p
|
||||
*/
|
||||
// function apiLogin(a, p) {
|
||||
// if (a === 'ed' && p === 'ed') return Promise.resolve({ isAdmin: true })
|
||||
// if (p === 'ed') return Promise.resolve({ isAdmin: false })
|
||||
// return Promise.reject(new Error('invalid credentials'))
|
||||
// }
|
||||
|
||||
export const useTenantStore = defineStore({
|
||||
id: 'tenant',
|
||||
state: () => ({
|
||||
account: '',
|
||||
token: '',
|
||||
id: ''
|
||||
}),
|
||||
|
||||
getters: {
|
||||
|
||||
},
|
||||
actions: {
|
||||
logout() {
|
||||
this.$patch({
|
||||
account: '',
|
||||
token: '',
|
||||
id: ''
|
||||
})
|
||||
resetToken()
|
||||
// we could do other stuff like redirecting the user
|
||||
},
|
||||
|
||||
/**
|
||||
* Attempt to login a user
|
||||
* @param {string} user_id
|
||||
* @param {string} user_password
|
||||
*/
|
||||
// async login(user_id: string, user_password: string) {
|
||||
// const userData = await authorize({ user_id, user_password })
|
||||
// if (userData.data.token) {
|
||||
// this.$patch({
|
||||
// account: user_id,
|
||||
|
||||
// ...userData.data,
|
||||
// id: 'true'
|
||||
// })
|
||||
// setToken(userData.data.token)
|
||||
// setTenant(userData)
|
||||
// console.log('authorize success!')
|
||||
// }
|
||||
// return new Promise((resolve, reject) => {
|
||||
// if (userData.data.message) {
|
||||
// reject(userData.data.message)
|
||||
// } else {
|
||||
// resolve(userData.data)
|
||||
// }
|
||||
// })
|
||||
// },
|
||||
async reflush() {
|
||||
if (getToken()) {
|
||||
const tenant = <Tenant>(JSON.parse(getTenant() as string))
|
||||
const token = <string>getToken()
|
||||
this.$patch({
|
||||
account: tenant.account,
|
||||
token: token,
|
||||
id: tenant.id
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useTenantStore, import.meta.hot))
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
import { defineStore, acceptHMRUpdate } from 'pinia'
|
||||
import { authorize } from '../api/user'
|
||||
import { getToken, setToken, resetToken, setUser, getUser } from '../utils/auth'
|
||||
import { User } from '../entity/index'
|
||||
|
||||
/**
|
||||
* Simulate a login
|
||||
* @param {string} a
|
||||
* @param {string} p
|
||||
*/
|
||||
// function apiLogin(a, p) {
|
||||
// if (a === 'ed' && p === 'ed') return Promise.resolve({ isAdmin: true })
|
||||
// if (p === 'ed') return Promise.resolve({ isAdmin: false })
|
||||
// return Promise.reject(new Error('invalid credentials'))
|
||||
// }
|
||||
|
||||
export const useUserStore = defineStore({
|
||||
id: 'user',
|
||||
state: () => ({
|
||||
name: '',
|
||||
token: '',
|
||||
owner: false
|
||||
}),
|
||||
|
||||
getters: {
|
||||
|
||||
},
|
||||
actions: {
|
||||
logout() {
|
||||
this.$patch({
|
||||
name: '',
|
||||
token: '',
|
||||
owner: false
|
||||
})
|
||||
resetToken()
|
||||
// we could do other stuff like redirecting the user
|
||||
},
|
||||
|
||||
/**
|
||||
* Attempt to login a user
|
||||
* @param {string} user_id
|
||||
* @param {string} user_password
|
||||
*/
|
||||
async login(user_id: string, user_password: string) {
|
||||
const userData = await authorize({ user_id, user_password })
|
||||
if (userData.data.token) {
|
||||
this.$patch({
|
||||
name: user_id,
|
||||
|
||||
...userData.data,
|
||||
owner: true
|
||||
})
|
||||
setToken(userData.data.token)
|
||||
setUser(userData)
|
||||
console.log('authorize success!')
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (userData.data.message) {
|
||||
reject(userData.data.message)
|
||||
} else {
|
||||
resolve(userData.data)
|
||||
}
|
||||
})
|
||||
},
|
||||
async reflush() {
|
||||
if (getToken()) {
|
||||
const user = <User>(JSON.parse(getUser() as string))
|
||||
const token = <string>getToken()
|
||||
this.$patch({
|
||||
name: user.id,
|
||||
token: token,
|
||||
owner: true
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useUserStore, import.meta.hot))
|
||||
}
|
||||
+6
-6
@@ -8,17 +8,17 @@ const setToken = (token: String) => {
|
||||
Cookies.set('token', token)
|
||||
}
|
||||
|
||||
const setUser = (user: object) => {
|
||||
Cookies.set('user', JSON.stringify(user))
|
||||
const setTenant = (tenant: object) => {
|
||||
Cookies.set('tenant', JSON.stringify(tenant))
|
||||
}
|
||||
|
||||
const getUser = () => {
|
||||
return Cookies.get('user')
|
||||
const getTenant = () => {
|
||||
return Cookies.get('tenant')
|
||||
}
|
||||
|
||||
const resetToken = () => {
|
||||
Cookies.remove('token')
|
||||
Cookies.remove('user')
|
||||
Cookies.remove('tenant')
|
||||
}
|
||||
|
||||
export { getToken, setToken, resetToken, setUser, getUser }
|
||||
export { getToken, setToken, resetToken, setTenant, getTenant }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import { getToken } from '../utils/auth'
|
||||
import { getToken, getTenant } from '../utils/auth'
|
||||
|
||||
const service = axios.create(
|
||||
{
|
||||
@@ -13,6 +13,11 @@ service.interceptors.request.use(
|
||||
if (typeof getToken() === 'string') {
|
||||
(config as any).headers['Authorization'] = 'Bearer' + getToken()
|
||||
}
|
||||
const tenant = getTenant()
|
||||
if (typeof tenant === 'string') {
|
||||
(config as any).headers['id'] = JSON.parse(tenant).id
|
||||
}
|
||||
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</div>
|
||||
</el-form>
|
||||
<div class="create_dialog">
|
||||
<el-button type="primary" @click="handleInsert" v-show="user.owner">新建</el-button>
|
||||
<el-button type="primary" @click="handleInsert" v-show="Tenant.account">新建</el-button>
|
||||
</div>
|
||||
|
||||
<el-table ref="multipleTableRef" :data="tableData" @selection-change="handleSelectionChange" style="width: 100%">
|
||||
@@ -36,9 +36,11 @@
|
||||
<el-icon :size="20" @click="copyNumber(scope.row)" class="click-icon">
|
||||
<CopyDocument />
|
||||
</el-icon>
|
||||
<el-button class="click-icon" size="small" @click="handleEdit(scope.$index, scope.row)" v-show="user.owner">编辑
|
||||
<el-button class="click-icon" size="small" @click="handleEdit(scope.$index, scope.row)"
|
||||
v-show="Tenant.account">编辑
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)" v-show="user.owner">删除
|
||||
<el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)" v-show="Tenant.account">
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -70,9 +72,9 @@ import { CopyDocument } from "@element-plus/icons-vue";
|
||||
import { ElNotification } from 'element-plus'
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { h } from 'vue'
|
||||
import { useUserStore } from '../../store/user'
|
||||
import { useTenantStore } from '../../store/tenant'
|
||||
// obtain user infomation
|
||||
const user = useUserStore()
|
||||
const Tenant = useTenantStore()
|
||||
|
||||
const bookmark_types = reactive<any[]>([])
|
||||
bookmark_type().then(response => {
|
||||
|
||||
Reference in New Issue
Block a user