diff --git a/package.json b/package.json index 11c21d109..737c08690 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azion-platform-kit", - "version": "1.8.7", + "version": "1.8.8", "private": true, "type": "module", "repository": { @@ -22,6 +22,7 @@ "prepare": "husky install" }, "dependencies": { + "@feedback-fish/vue": "^1.0.1", "@guolao/vue-monaco-editor": "^1.3.0", "@vee-validate/yup": "^4.11.1", "@vueuse/core": "^10.7.0", @@ -46,7 +47,6 @@ "@commitlint/config-conventional": "^17.7.0", "@rushstack/eslint-patch": "^1.3.2", "@tailwindcss/typography": "^0.5.10", - "caniuse-lite": "^1.0.30001584", "@types/c3": "^0.7.11", "@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue-jsx": "^3.0.1", @@ -55,6 +55,7 @@ "@vue/eslint-config-prettier": "^8.0.0", "@vue/test-utils": "^2.4.1", "autoprefixer": "^10.4.14", + "caniuse-lite": "^1.0.30001584", "cypress": "13.5.0", "eslint": "^8.45.0", "eslint-plugin-cypress": "^2.13.3", diff --git a/src/router/routes/password-routes/index.js b/src/router/routes/password-routes/index.js index 08f9c5775..39433944f 100644 --- a/src/router/routes/password-routes/index.js +++ b/src/router/routes/password-routes/index.js @@ -6,11 +6,12 @@ export const passwordRoutes = { name: 'new-password', children: [ { - path: 'new/:uidb64/:token', + path: 'new/:uidb64/:token?', name: 'reset-password', component: () => import('@views/NewPassword/NewPasswordView.vue'), props: { - resetPasswordService: AuthServices.resetPasswordService + resetPasswordService: AuthServices.resetPasswordService, + passwordSettingService: AuthServices.passwordSettingService }, meta: { isPublic: true, diff --git a/src/services/auth-services/index.js b/src/services/auth-services/index.js index 1f913e00b..9735a203f 100644 --- a/src/services/auth-services/index.js +++ b/src/services/auth-services/index.js @@ -5,6 +5,7 @@ import { refreshAuthenticationService } from './refresh-authentication-service' import { logoutService } from './logout-service' import { sendResetPasswordEmailService } from './send-reset-password-email-service' import { resetPasswordService } from './reset-password-service' +import { passwordSettingService } from './password-setting-service' export { loginService, @@ -13,5 +14,6 @@ export { switchAccountService, logoutService, sendResetPasswordEmailService, - resetPasswordService + resetPasswordService, + passwordSettingService } diff --git a/src/services/auth-services/make-password-setting-service-base-url.js b/src/services/auth-services/make-password-setting-service-base-url.js new file mode 100644 index 000000000..dedb16123 --- /dev/null +++ b/src/services/auth-services/make-password-setting-service-base-url.js @@ -0,0 +1,4 @@ +export const makePasswordSettingServiceBaseUrl = () => { + const version = 'v4' + return `${version}/iam/user/password` +} diff --git a/src/services/auth-services/password-setting-service.js b/src/services/auth-services/password-setting-service.js new file mode 100644 index 000000000..cb2d713f3 --- /dev/null +++ b/src/services/auth-services/password-setting-service.js @@ -0,0 +1,52 @@ +import { AxiosHttpClientAdapter } from '@/services/axios/AxiosHttpClientAdapter' +import * as Errors from '@/services/axios/errors' +import { makePasswordSettingServiceBaseUrl } from './make-password-setting-service-base-url' + +export const passwordSettingService = async (payload) => { + let httpResponse = await AxiosHttpClientAdapter.request({ + url: makePasswordSettingServiceBaseUrl(), + method: 'POST', + body: payload + }) + return parseHttpResponse(httpResponse) +} + +/** + * @param {Object} httpResponse - The HTTP response object. + * @param {Object} httpResponse.body - The response body. + * @param {String} httpResponse.statusCode - The HTTP status code. + * @returns {Object} The result message based on the status code. + * @throws {Error} If there is an error with the response. + */ + +const parseHttpResponse = (httpResponse) => { + switch (httpResponse.statusCode) { + case 200: + return httpResponse.body + case 400: + throw new Error(extractApiError(httpResponse.body, 'non_field_errors')).message + case 403: + throw new Errors.PermissionError().message + case 404: + throw new Error(extractApiError(httpResponse.body, 'detail')).message + case 500: + throw new Errors.InternalServerError().message + default: + throw new Errors.UnexpectedError().message + } +} + +/** + * @param {Object} errorSchema - The error schema. + * @param {string} key - The error key of error schema. + * @returns {string} The result message based on the status code. + */ +const extractApiError = (errorSchema, key) => { + const errorMessage = errorSchema[key] || 'Unexpected error.' + + if (errorMessage === 'Not found.') { + return 'Token not found.' + } + + return errorMessage +} diff --git a/src/templates/dialog-unsaved-block/index.vue b/src/templates/dialog-unsaved-block/index.vue index 87ea32d56..21cb37e46 100644 --- a/src/templates/dialog-unsaved-block/index.vue +++ b/src/templates/dialog-unsaved-block/index.vue @@ -1,5 +1,5 @@