Skip to content

Commit

Permalink
feat: 登录密码加密
Browse files Browse the repository at this point in the history
* fix: 修改登录后跳转方式

* fix: 修改物模型的其他配置按照类型配置
  • Loading branch information
XieYongHong authored Jun 30, 2023
1 parent 3ff87e2 commit 5bd178f
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"jetlinks-store": "^0.0.3",
"jetlinks-ui-components": "^1.0.21",
"js-cookie": "^3.0.1",
"jsencrypt": "^3.3.2",
"less": "^4.1.3",
"less-loader": "^11.1.0",
"lodash-es": "^4.17.21",
Expand Down
7 changes: 7 additions & 0 deletions src/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ export const loginout_api = () => server.get<any>('/user-token/reset')
export const getOAuth2 = (params: any) => server.get<any>('/oauth2/authorize', params)

export const initApplication = (clientId: string | number) => server.get<{name: string}>(`/application/${clientId}/info`)


/**
* 登录加密信息
* @returns
*/
export const authLoginConfig = () => server.get(`/authorize/login/configs`)
24 changes: 19 additions & 5 deletions src/components/Metadata/ConfigParam/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,32 @@
</template>
<template #content>
<div style="max-width: 400px;" class="ant-form-vertical">
<j-form-item v-for="item in config.properties" :name="name.concat([item.property])" :label="item.name">
<template v-if='item.type?.type === "string"'>
<j-form-item v-for="item in config.properties" :key="item.property" :name="name.concat([item.property])" :label="item.name">
<!-- <template v-if='item.type?.type === "string"'>
<j-input v-model:value='value[item.property]' size="small" :placeholder="`请输入${item.name}`"/>
</template>
<j-select v-else v-model:value="value[item.property]" :options="item.type?.elements?.map((e: { 'text': string, 'value': string }) => ({
<template v-else-if='item.type?.type === "int"'>
<j-input-number style="width: 100%;" v-model:value='value[item.property]' size="small" :placeholder="`请输入${item.name}`"/>
</template>
<j-select v-else :mode="item.type?.multi ? 'multiple' : ''" v-model:value="value[item.property]" :options="item.type?.elements?.map((e: { 'text': string, 'value': string }) => ({
label: e.text,
value: e.value,
}))" size="small" :placeholder="`请输入${item.name}`"></j-select>
}))" size="small" :placeholder="`请输入${item.name}`"></j-select> -->
<ValueItem
v-model:modelValue="value[item.property]"
:itemType="item.type?.type"
:mode="item?.type?.multi ? 'multiple' : ''"
:options="
item.type?.elements?.map(e => ({
label: e.text,
value: e.value,
}))
"
/>
</j-form-item>
</div>
</template>
{{ config.name || 存储配置 }}
{{ config.name || '存储配置' }}
<AIcon type="EditOutlined" class="item-icon" />
</j-popover>
</j-button>
Expand Down
6 changes: 6 additions & 0 deletions src/components/ValueItem/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="value-item-warp">
<j-select
v-if="typeMap.get(itemType) === 'select'"
:mode="mode"
v-model:value="myValue"
:options="options"
allowClear
Expand Down Expand Up @@ -139,6 +140,11 @@ const props = defineProps({
type: Array as PropType<DefaultOptionType[]>,
default: () => [],
},
// 多选框
mode: {
type: String as PropType<'multiple' | 'tags' | 'combobox' | ''>,
default: ''
}
});
// type Props = {
// itemData?: Object;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/encrypt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import JSEncrypt from "jsencrypt";

export const encrypt =(txt:string,publicKey:string)=>{
const encryptor = new JSEncrypt()
encryptor.setPublicKey(publicKey)
return encryptor.encrypt(txt)
}
37 changes: 35 additions & 2 deletions src/views/user/Login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ import {
getInitSet,
systemVersion,
bindInfo,
settingDetail, userDetail
settingDetail, userDetail,
authLoginConfig
} from '@/api/login'
import { useUserInfo } from '@/store/userInfo';
import { useSystem } from '@/store/system'
import { LocalStore } from '@/utils/comm';
import { BASE_API_PATH, TOKEN_KEY, Version_Code } from '@/utils/variable';
import { SystemConst } from '@/utils/consts';
import {encrypt} from '@/utils/encrypt'
const store = useUserInfo();
const systemStore = useSystem();
Expand All @@ -199,6 +201,12 @@ const form = reactive({
verifyKey: '',
});
const RsaConfig = reactive<any>({
enabled:false, //是否加密
publicKey:'', //rsa公钥,使用此公钥对密码进行加密
id:'' //密钥ID
})
const rules = {
username: [
{
Expand Down Expand Up @@ -249,7 +257,14 @@ iconMap.set('third-party', getImage('/apply/provider5.png'));
const onFinish = async () => {
try {
loading.value = true;
const res: any = await authLogin(form);
const data = {
...form,
password:RsaConfig.enabled?encrypt(form.password,RsaConfig.publicKey):form.password,
encryptId:RsaConfig.enabled?RsaConfig.id:undefined
}
const res: any = await authLogin(data);
loading.value = false;
if (res.success) {
LocalStore.set(TOKEN_KEY, res?.result.token);
Expand Down Expand Up @@ -283,6 +298,7 @@ const onFinish = async () => {
form.verifyCode = '';
getCode();
loading.value = false;
getRsa()
}
};
Expand Down Expand Up @@ -317,6 +333,18 @@ const getOpen = () => {
systemStore.getFront()
};
//获取加密信息
const getRsa =async () =>{
const res:any = await authLoginConfig()
if(res.status === 200){
if(res.result?.encrypt){
RsaConfig.enabled = res.result?.encrypt.enabled
RsaConfig.publicKey = res.result?.encrypt.publicKey
RsaConfig.id = res.result?.encrypt.id
}
}
}
const basis = computed(() => {
return systemStore.configInfo['front'] || {}
})
Expand Down Expand Up @@ -352,6 +380,11 @@ watch(
getOpen();
getCode();
screenRotation(screenWidth.value, screenHeight.value);
onMounted(()=>{
getRsa()
})
</script>

<style scoped lang="less">
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default defineConfig(({ mode}) => {
[env.VITE_APP_BASE_API]: {
// target: 'http://192.168.32.226:8844',
// target: 'http://192.168.32.244:8881',
target: 'http://120.77.179.54:8844', // 120测试
target: 'http://192.168.32.163:8844', //张季本地
// target: 'http://120.77.179.54:8844', // 120测试
// target: 'http://192.168.33.46:8844', // 本地开发环境
ws: 'ws://192.168.33.46:8844',
changeOrigin: true,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3862,6 +3862,11 @@ jsbn@~0.1.0:
resolved "https://registry.jetlinks.cn/jsbn/-/jsbn-0.1.1.tgz"
integrity sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==

jsencrypt@^3.3.2:
version "3.3.2"
resolved "http://registry.jetlinks.cn/jsencrypt/-/jsencrypt-3.3.2.tgz#b0f1a2278810c7ba1cb8957af11195354622df7c"
integrity sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==

jsesc@^2.5.1:
version "2.5.2"
resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz"
Expand Down

0 comments on commit 5bd178f

Please sign in to comment.