add verification check and support
This commit is contained in:
1 parent
538dfd283e
commit
91c6792c5c
10 files changed
+90
-16
No files matched your search
+19
-5
@@ -8,6 +8,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElConfigProvider } from 'element-plus';
|
||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
|
||||
import { authOperator } from './operators/auth/operator';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -18,11 +19,24 @@ export default defineComponent({
|
||||
locale: zhCn
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
// if access token is already set, try to get user info
|
||||
const accessToken = this.$store.getters.accessToken;
|
||||
if (accessToken) {
|
||||
this.$store.dispatch('getMe');
|
||||
async mounted() {
|
||||
// if refresh token is already set, try to refresh it and get user info
|
||||
const currentRefreshToken = this.$store.getters.refreshToken;
|
||||
const currentAccessToken = this.$store.getters.accessToken;
|
||||
if (!currentAccessToken) {
|
||||
console.log('user not login');
|
||||
}
|
||||
if (currentRefreshToken) {
|
||||
const {
|
||||
data: { access: accessToken, refresh: refreshToken }
|
||||
} = await authOperator.refreshToken({
|
||||
refresh: currentRefreshToken
|
||||
});
|
||||
await this.$store.dispatch('setAccessToken', accessToken);
|
||||
await this.$store.dispatch('setRefreshToken', refreshToken);
|
||||
await this.$store.dispatch('getMe');
|
||||
} else {
|
||||
console.error('refresh token does not exist');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
</div>
|
||||
<div class="right">
|
||||
<div v-if="itemKey === 'api_key'">
|
||||
<div v-if="!isApplied">
|
||||
<el-popover placement="bottom" :width="200" trigger="click">
|
||||
<div v-if="!applied === true">
|
||||
<el-popover placement="bottom" :width="200" :visible="applied === false">
|
||||
<p class="text-center mb-2">
|
||||
<small>{{ $t('application.message.notApplied') }}</small>
|
||||
</p>
|
||||
@@ -26,7 +26,6 @@
|
||||
v-model="value[itemKey?.toString()]"
|
||||
:placeholder="$t('common.title.placeholderOfInput')"
|
||||
class="inline-block w-4/5"
|
||||
@focus="$emit('refresh-applications')"
|
||||
/>
|
||||
</template>
|
||||
</el-popover>
|
||||
@@ -81,7 +80,8 @@ import { ISchema } from '@/operators/api/models';
|
||||
import { applicationOperator, IApi, IApplication, IApplicationType } from '@/operators';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { ElPopover, ElInput, ElSelect, ElButton, ElTooltip, ElOption, ElMessage } from 'element-plus';
|
||||
import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
|
||||
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants/errorCode';
|
||||
import { getVerificationUrl } from '@/utils';
|
||||
|
||||
interface IData {
|
||||
value: {
|
||||
@@ -112,6 +112,10 @@ export default defineComponent({
|
||||
applications: {
|
||||
type: Array as () => IApplication[],
|
||||
required: true
|
||||
},
|
||||
applied: {
|
||||
type: Boolean,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
emits: ['update:form', 'refresh-applications'],
|
||||
@@ -121,9 +125,6 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isApplied() {
|
||||
return this.applications.filter((application) => application.api?.id === this.api?.id).length > 0;
|
||||
},
|
||||
appliedApplication(): IApplication | undefined {
|
||||
const applications = this.applications.filter((application) => application.api?.id === this.api?.id);
|
||||
if (applications.length > 0) {
|
||||
@@ -160,6 +161,17 @@ export default defineComponent({
|
||||
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
|
||||
ElMessage.error(this.$t('application.message.alreadyApplied'));
|
||||
}
|
||||
if (error?.response?.data?.code === ERROR_CODE_UNVERIFIED) {
|
||||
ElMessage({
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 0,
|
||||
showClose: true,
|
||||
message: `${this.$t(
|
||||
'application.message.unverified'
|
||||
)} <a class="underline" href="${getVerificationUrl()}">${this.$t('application.message.goVerify')}</a>`,
|
||||
type: 'warning'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
v-model:form="formValue.queries"
|
||||
:schema="api?.request?.queries"
|
||||
:api="api"
|
||||
:applied="applied"
|
||||
:applications="applications"
|
||||
@refresh-applications="getApplications"
|
||||
/>
|
||||
@@ -45,6 +46,7 @@ import ApiInfo from './Info.vue';
|
||||
export interface IData {
|
||||
formValue: IForm;
|
||||
applications: IApplication[];
|
||||
applied: boolean | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -69,7 +71,8 @@ export default defineComponent({
|
||||
data(): IData {
|
||||
return {
|
||||
formValue: this.form || {},
|
||||
applications: []
|
||||
applications: [],
|
||||
applied: undefined
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
@@ -89,6 +92,7 @@ export default defineComponent({
|
||||
})
|
||||
.then(({ data: data }: { data: IApplicationListResponse }) => {
|
||||
this.applications = data.items;
|
||||
this.applied = this.applications.filter((item) => item?.api?.id === this.api.id).length > 0;
|
||||
})
|
||||
.catch((error) => {});
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export const ERROR_CODE_UNVERIFIED = 'unverifed';
|
||||
export const ERROR_CODE_UNVERIFIED = 'unverified';
|
||||
export const ERROR_CODE_DUPLICATION = 'duplication';
|
||||
@@ -2,5 +2,7 @@ export default {
|
||||
alreadyApplied: '已经申请过该服务,请到控制台查看',
|
||||
applySuccessfully: '申请成功,即将跳转到控制台',
|
||||
notApplied: '你尚未申请过该服务,请先申请该服务之后使用',
|
||||
yourApplication: '你的申请'
|
||||
yourApplication: '你的申请',
|
||||
unverified: '您需要完成实名认证之后方可申请该服务',
|
||||
goVerify: '去实名认证'
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface IToken {
|
||||
access?: string;
|
||||
refresh?: string;
|
||||
}
|
||||
|
||||
export interface ITokenResponse extends IToken {}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { httpClient } from '../instance';
|
||||
import { ITokenResponse, IToken } from './models';
|
||||
|
||||
class AuthOperator {
|
||||
async refreshToken(payload: IToken): Promise<AxiosResponse<ITokenResponse>> {
|
||||
return httpClient.post('/token/refresh/', payload);
|
||||
}
|
||||
}
|
||||
|
||||
export const authOperator = new AuthOperator();
|
||||
@@ -85,7 +85,7 @@ import {
|
||||
serviceOperator
|
||||
} from '@/operators';
|
||||
import { defineComponent } from 'vue';
|
||||
import { ERROR_CODE_DUPLICATION } from '@/constants';
|
||||
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { apiOperator } from '@/operators/api/operator';
|
||||
import { IApi, IApiListResponse } from '@/operators/api/models';
|
||||
@@ -94,6 +94,7 @@ import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
|
||||
import { ROUTE_CONSOLE_APPLICATION_LIST } from '@/router';
|
||||
import { ElCol, ElRow, ElButton, ElCard, ElDivider, ElSkeleton, ElSkeletonItem } from 'element-plus';
|
||||
import ApiInfo from '@/components/api/Info.vue';
|
||||
import { getVerificationUrl } from '@/utils';
|
||||
|
||||
interface IData {
|
||||
service: IService | undefined;
|
||||
@@ -191,6 +192,17 @@ export default defineComponent({
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
if (error?.response?.data?.code === ERROR_CODE_UNVERIFIED) {
|
||||
ElMessage({
|
||||
dangerouslyUseHTMLString: true,
|
||||
duration: 0,
|
||||
showClose: true,
|
||||
message: `${this.$t(
|
||||
'application.message.unverified'
|
||||
)} <a class="underline" href="${getVerificationUrl()}">${this.$t('application.message.goVerify')}</a>`,
|
||||
type: 'warning'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './baseUrl';
|
||||
export * from './env';
|
||||
export * from './mode';
|
||||
export * from './verification';
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Get verification url
|
||||
* @returns
|
||||
*/
|
||||
|
||||
import { getAuthBaseUrl } from './baseUrl';
|
||||
|
||||
export const getVerificationUrl = () => {
|
||||
const baseUrl = getAuthBaseUrl();
|
||||
const targetUrl = `${baseUrl}/user/verify?redirect=` + window.location.href;
|
||||
return targetUrl;
|
||||
};
|
||||
Reference in new issue
Block a user