用户加密机制设计初步完成

This commit is contained in:
veypi
2021-10-21 18:09:40 +08:00
parent cd7029c298
commit 82b64a4bb2
40 changed files with 1027 additions and 322 deletions
+4 -4
View File
@@ -6,11 +6,10 @@
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-btn text class="font-italic" style="font-size: 20px">
统一认证
</v-btn>
</v-app-bar>
<v-main>
@@ -32,8 +31,9 @@ export default Vue.extend({
//
}),
mounted() {
beforeCreate() {
util.title('统一认证')
this.$store.dispatch('fetchSelf')
}
})
</script>
+10 -19
View File
@@ -32,7 +32,7 @@ class Interface {
const newFail = function (data: any) {
if (data && data.code === 40001) {
// no login
store.dispatch('handleLogOut')
store.dispatch('handleLogout')
return
}
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
@@ -52,7 +52,7 @@ class Interface {
} else {
newFail(data)
if (data.code === 41001) {
store.dispatch('handleLogOut')
store.dispatch('handleLogout')
// bus.$emit('log_out')
}
}
@@ -106,6 +106,9 @@ const role = {
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)
},
@@ -116,15 +119,18 @@ const app = {
const user = {
local: '/api/user/',
register(username: string, password: string, prop?: any) {
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) {
login(username: string, password: string, uuid: string) {
return new Interface(ajax.head, this.local + username, {
uid_type: 'username',
uuid: uuid,
password: Base64.encode(password)
})
}
@@ -196,21 +202,6 @@ const api = {
return new Interface(ajax.get, '/api/user/', {
username
})
},
login(username: string, password: string) {
return new Interface(ajax.head, '/api/user/' + username, {
password: Base64.encode(password)
})
},
// @title 职位
// @domain 部门
register(username: string, password: string, domain?: string, title?: string) {
return new Interface(ajax.post, '/api/user/', {
username: username,
password: Base64.encode(password),
domain: domain,
title: title
})
}
},
message: message
+6 -4
View File
@@ -9,7 +9,9 @@ import '@/libs/wwLogin.js'
components: {}
})
export default class WxLogin extends Vue {
goto(id: string, app: string, url: string, state?: string, href?: string) {
goto(id: string, app: string, url: string, state?: number, href?: string) {
// eslint-disable-next-line
// @ts-ignore
window.WwLogin({
id: 'wx_reg',
appid: id,
@@ -21,13 +23,13 @@ export default class WxLogin extends Vue {
}
@Prop({default: ''})
aid: ''
aid = ''
@Prop({default: ''})
app: ''
app = ''
@Prop({default: ''})
url: ''
url = ''
mounted() {
this.goto(this.aid, this.app, this.url, new Date().getTime())
+28
View File
@@ -0,0 +1,28 @@
<template>
<svg class="icon" aria-hidden="true">
<use :xlink:href="'#icon-'+icon"></use>
</svg>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
@Component({
components: {}
})
export default class OneIcon extends Vue {
get icon() {
if (this.$slots.default) return this.$slots.default[0].text?.trim()
console.warn('blank icon name')
return ''
}
}
</script>
<style scoped>
.icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
</style>
+26
View File
@@ -0,0 +1,26 @@
import Vue from 'vue'
import OneIcon from './icon.vue'
function loadJS(url: string) {
const script = document.createElement('script')
script.type = 'text/javascript'
script.src = url
document.getElementsByTagName('head')[0].appendChild(script)
}
export default {
installed: false,
install(vue: typeof Vue, options?: { href: '' }): void {
if (this.installed) {
return
}
this.installed = true
if (options && options.href) {
console.log(options.href)
loadJS(options.href)
} else {
console.error('not set iconfont href')
}
vue.component('one-icon', OneIcon)
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ function padLeftZero(str: string): string {
const util = {
title: function (title: string) {
window.document.title = title ? title + ' - Home' : 'veypi project'
window.document.title = title ? title + ' - oa' : 'veypi project'
},
getCookie(name: string) {
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
+7
View File
@@ -4,7 +4,14 @@ 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
+18 -3
View File
@@ -4,13 +4,23 @@ 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',
name: 'home',
component: Home
},
{
@@ -19,12 +29,12 @@ const routes: Array<RouteConfig> = [
component: Demo
},
{
path: '/login',
path: '/login/:uuid?',
name: 'login',
component: Login
},
{
path: '/register',
path: '/register/:uuid?',
name: 'register',
component: Register
},
@@ -32,6 +42,11 @@ const routes: Array<RouteConfig> = [
path: '/wx',
name: 'wx',
component: () => import('../views/wx.vue')
},
{
path: '*',
name: '404',
component: NotFound
}
]
+16 -2
View File
@@ -1,16 +1,30 @@
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: {
}
modules: {}
})
+24
View File
@@ -0,0 +1,24 @@
<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>
+18
View File
@@ -6,20 +6,38 @@
</style>
<template>
<div class='home d-flex justify-center align-center'>
<one-icon style="color: aqua;font-size: 50px">glassdoor</one-icon>
</div>
</template>
<script lang='ts'>
import {Component, Vue} from 'vue-property-decorator'
import util from '@/libs/util'
@Component({
components: {}
})
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>
+16 -9
View File
@@ -54,7 +54,8 @@
<v-card-actions>
<v-spacer/>
<v-btn type="primary" @click="handleSubmit">登录</v-btn>
<router-link to="/register" style="text-decoration: none;">
<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>
@@ -87,13 +88,26 @@ export default class Login extends Vue {
]
}
get app_uuid() {
return this.$route.params.uuid || this.$store.state.oauuid
}
handleSubmit() {
this.$api.auth.login(this.formInline.user, this.formInline.password).Start(
// 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 {
@@ -105,12 +119,5 @@ export default class Login extends Vue {
}
)
}
mounted() {
}
created() {
console.log(this.formInline)
}
}
</script>
+11 -5
View File
@@ -90,20 +90,26 @@ export default class Register extends Vue {
]
}
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).Start(
this.$api.user.register(this.form.username, this.form.passwd, this.app_uuid).Start(
(data) => {
// this.$message.success('注册成功!')
this.$router.push({name: 'login'})
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('用户名重复')
this.$message.error('用户名重复')
} else {
// this.$message.error('注册失败')
this.$message.error('注册失败')
}
}
)