mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-07-01 16:20:29 +08:00
login add salt
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { MockMethod } from 'vite-plugin-mock'
|
import { MockMethod } from 'vite-plugin-mock'
|
||||||
|
import md5 from 'md5'
|
||||||
import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util'
|
import { resultError, resultSuccess, getRequestToken, requestParams } from '../_util'
|
||||||
|
|
||||||
export function createFakeUserList() {
|
export function createFakeUserList() {
|
||||||
@@ -60,6 +61,14 @@ const fakeCodeList: any = {
|
|||||||
'2': ['2000', '4000', '6000'],
|
'2': ['2000', '4000', '6000'],
|
||||||
}
|
}
|
||||||
export default [
|
export default [
|
||||||
|
{
|
||||||
|
url: '/api/getLoginSalt',
|
||||||
|
timeout: 200,
|
||||||
|
method: 'get',
|
||||||
|
response: () => {
|
||||||
|
return resultSuccess({ salt: 'nc8w9f82hfioq2ci9hcwehcq' })
|
||||||
|
},
|
||||||
|
},
|
||||||
// mock user login
|
// mock user login
|
||||||
{
|
{
|
||||||
url: '/api/login',
|
url: '/api/login',
|
||||||
@@ -68,7 +77,9 @@ export default [
|
|||||||
response: ({ body }) => {
|
response: ({ body }) => {
|
||||||
const { username, password } = body
|
const { username, password } = body
|
||||||
const checkUser = createFakeUserList().find(
|
const checkUser = createFakeUserList().find(
|
||||||
(item) => item.username === username && password === item.password,
|
(item) =>
|
||||||
|
item.username === username &&
|
||||||
|
password === md5(item.password + 'nc8w9f82hfioq2ci9hcwehcq'),
|
||||||
)
|
)
|
||||||
if (!checkUser) {
|
if (!checkUser) {
|
||||||
return resultError('Incorrect account or password!')
|
return resultError('Incorrect account or password!')
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
"echarts": "^5.3.2",
|
"echarts": "^5.3.2",
|
||||||
"intro.js": "^5.1.0",
|
"intro.js": "^5.1.0",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
|
"md5": "^2.3.0",
|
||||||
"mockjs": "^1.1.0",
|
"mockjs": "^1.1.0",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"path-to-regexp": "^6.2.0",
|
"path-to-regexp": "^6.2.0",
|
||||||
@@ -81,6 +82,7 @@
|
|||||||
"@types/inquirer": "^8.2.1",
|
"@types/inquirer": "^8.2.1",
|
||||||
"@types/intro.js": "^3.0.2",
|
"@types/intro.js": "^3.0.2",
|
||||||
"@types/lodash-es": "^4.17.6",
|
"@types/lodash-es": "^4.17.6",
|
||||||
|
"@types/md5": "^2.3.2",
|
||||||
"@types/mockjs": "^1.0.6",
|
"@types/mockjs": "^1.0.6",
|
||||||
"@types/node": "^17.0.25",
|
"@types/node": "^17.0.25",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
|
|||||||
@@ -67,3 +67,7 @@ export interface GetUserInfoModel {
|
|||||||
// 介绍
|
// 介绍
|
||||||
desc?: string
|
desc?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetLoginSaltModel {
|
||||||
|
salt: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import {
|
|||||||
RegisterParams,
|
RegisterParams,
|
||||||
ResetPasswordResultModel,
|
ResetPasswordResultModel,
|
||||||
RegisterResultModel,
|
RegisterResultModel,
|
||||||
|
GetLoginSaltModel,
|
||||||
} from './model/userModel'
|
} from './model/userModel'
|
||||||
|
|
||||||
import { ErrorMessageMode } from '/#/axios'
|
import { ErrorMessageMode } from '/#/axios'
|
||||||
|
|
||||||
enum Api {
|
enum Api {
|
||||||
|
GetLoginSalt = '/getLoginSalt',
|
||||||
Login = '/login',
|
Login = '/login',
|
||||||
Logout = '/logout',
|
Logout = '/logout',
|
||||||
ResetPassword = '/resetPassword',
|
ResetPassword = '/resetPassword',
|
||||||
@@ -66,6 +68,13 @@ export function registerApi(params: RegisterParams, mode: ErrorMessageMode = 'mo
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: getLoginSalt
|
||||||
|
*/
|
||||||
|
export function getLoginSalt(username: string) {
|
||||||
|
return defHttp.get<GetLoginSaltModel>({ url: Api.GetLoginSalt, params: { username: username } })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: getUserInfo
|
* @description: getUserInfo
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { reactive, ref, unref, computed } from 'vue'
|
import { reactive, ref, unref, computed } from 'vue'
|
||||||
|
import md5 from 'md5'
|
||||||
|
|
||||||
import { Checkbox, Form, Input, Row, Col, Button } from 'ant-design-vue'
|
import { Checkbox, Form, Input, Row, Col, Button } from 'ant-design-vue'
|
||||||
import LoginFormTitle from './LoginFormTitle.vue'
|
import LoginFormTitle from './LoginFormTitle.vue'
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
import { useMessage } from '/@/hooks/web/useMessage'
|
import { useMessage } from '/@/hooks/web/useMessage'
|
||||||
|
|
||||||
import { useUserStore } from '/@/store/modules/user'
|
import { useUserStore } from '/@/store/modules/user'
|
||||||
|
import { getLoginSalt } from '/@/api/sys/user'
|
||||||
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'
|
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'
|
||||||
import { useDesign } from '/@/hooks/web/useDesign'
|
import { useDesign } from '/@/hooks/web/useDesign'
|
||||||
// import { onKeyStroke } from '@vueuse/core'
|
// import { onKeyStroke } from '@vueuse/core'
|
||||||
@@ -124,8 +126,9 @@
|
|||||||
if (!data) return
|
if (!data) return
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
const { salt } = await getLoginSalt(data.account)
|
||||||
const userInfo = await userStore.login({
|
const userInfo = await userStore.login({
|
||||||
password: data.password,
|
password: md5(data.password + salt),
|
||||||
username: data.account,
|
username: data.account,
|
||||||
mode: 'none', //不要默认的错误提示
|
mode: 'none', //不要默认的错误提示
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user