Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: support for maarg login in ofbiz apps (preorder-299) #125

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ VUE_APP_LOCALES={"en": "English", "ja": "日本語", "es": "Español"}
VUE_APP_CURRENCY_FORMATS={"en": {"currency": {"style": "currency","currency": "USD"}}, "ja": {"currency": {"style": "currency", "currency": "JPY"}}, "es": {"currency": {"style": "currency","currency": "ESP"}}}
VUE_APP_DEFAULT_ALIAS=
VUE_APP_MAARG_LOGIN=["atp", "company", "order-routing", "inventorycount"]
VUE_APP_USERS_LOGIN_URL="http://users.hotwax.io/login"
VUE_APP_USERS_LOGIN_URL="http://users.hotwax.io/login"
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
VUE_APP_MAARG_LOGIN_REQUIRED=["preorder"]
8 changes: 7 additions & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ const isMaargLogin = (handle: string, environment = "") => {
return maargLoginApps.some((appName: string) => appHandle.includes(appName))
}

export { isMaargLogin, showToast }
const isMaargLoginRequired = (handle: string, environment = "") => {
const appHandle = environment ? handle + environment : handle
const maargOmsRequiredApps = JSON.parse(process.env.VUE_APP_MAARG_LOGIN_REQUIRED ? process.env.VUE_APP_MAARG_LOGIN_REQUIRED : [])
return maargOmsRequiredApps.some((appName: string) => appHandle.includes(appName))
}

export { isMaargLogin, isMaargLoginRequired, showToast }
5 changes: 3 additions & 2 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import {
import { useAuthStore } from '@/store/auth';
import { useRouter } from "vue-router";
import { goToOms } from '@hotwax/dxp-components'
import { isMaargLogin } from '@/util';
import { isMaargLogin, isMaargLoginRequired } from '@/util';
import { translate } from '@/i18n';
import UserActionsPopover from '@/components/UserActionsPopover.vue'
import Image from "@/components/Image.vue";
Expand Down Expand Up @@ -144,7 +144,7 @@ export default defineComponent({
},
generateAppLink(app: any, appEnvironment = '') {
const oms = isMaargLogin(app.handle, appEnvironment) ? this.authStore.getMaargOms : this.authStore.getOMS;
window.location.href = this.scheme + app.handle + appEnvironment + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${oms.startsWith('http') ? isMaargLogin(app.handle, appEnvironment) ? oms : oms.includes('/api') ? oms : `${oms}/api/` : oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${isMaargLogin(app.handle, appEnvironment) ? '&omsRedirectionUrl=' + this.authStore.getOMS : ''}` : '')
window.location.href = this.scheme + app.handle + appEnvironment + this.domain + (this.authStore.isAuthenticated ? `/login?oms=${oms.startsWith('http') ? isMaargLogin(app.handle, appEnvironment) ? oms : oms.includes('/api') ? oms : `${oms}/api/` : oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${isMaargLogin(app.handle, appEnvironment) ? '&omsRedirectionUrl=' + this.authStore.getOMS : isMaargLoginRequired(app.handle, appEnvironment) ? '&omsRedirectionUrl=' + this.authStore.getMaargOms : ''}` : '')
},
async openUserActionsPopover(event: any) {
const userActionsPopover = await popoverController.create({
Expand Down Expand Up @@ -251,6 +251,7 @@ export default defineComponent({
domain,
goToOms,
isMaargLogin,
isMaargLoginRequired,
lockClosedOutline,
hardwareChipOutline,
openOutline,
Expand Down
10 changes: 8 additions & 2 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
import { arrowForwardOutline, gridOutline } from 'ionicons/icons'
import { UserService } from "@/services/UserService";
import { translate } from "@/i18n";
import { isMaargLogin, showToast } from "@/util";
import { isMaargLogin, isMaargLoginRequired, showToast } from "@/util";
import { hasError } from "@hotwax/oms-api";

export default defineComponent({
Expand Down Expand Up @@ -241,7 +241,7 @@
await this.authStore.setMaargInstance(resp.data.maargInstanceUrl)
}
} catch (error) {
console.error(error)

Check warning on line 244 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 244 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
}
},
async login() {
Expand All @@ -263,7 +263,7 @@
this.router.push('/')
}
} catch (error) {
console.error(error)

Check warning on line 266 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 266 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
}
this.isLoggingIn = false;
},
Expand All @@ -278,7 +278,7 @@
}
} catch (error) {
this.router.push('/')
console.error(error)

Check warning on line 281 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 281 in src/views/Login.vue

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
}
},
async basicLogin() {
Expand All @@ -304,17 +304,23 @@
},
generateRedirectionLink() {
let omsUrl = ''
let omsRedirectionUrl = ''
if(isMaargLogin(this.authStore.getRedirectUrl)) {
if(this.authStore.getMaargOms) omsUrl = this.authStore.getMaargOms
else {
showToast(translate("This application is not enabled for your account"))
this.router.push("/")
return;
}
omsRedirectionUrl = this.authStore.oms
}

if(isMaargLoginRequired(this.authStore.getRedirectUrl) && this.authStore.getMaargOms) {
omsRedirectionUrl = this.authStore.getMaargOms
}

omsUrl = omsUrl ? omsUrl : this.authStore.oms.startsWith('http') ? this.authStore.oms.includes('/api') ? this.authStore.oms : `${this.authStore.oms}/api/` : this.authStore.oms
window.location.replace(`${this.authStore.getRedirectUrl}?oms=${omsUrl}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${isMaargLogin(this.authStore.getRedirectUrl) ? '&omsRedirectionUrl=' + this.authStore.oms : ''}`)
window.location.replace(`${this.authStore.getRedirectUrl}?oms=${omsUrl}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}${omsRedirectionUrl ? '&omsRedirectionUrl=' + omsRedirectionUrl : ''}`)
}
},
setup () {
Expand Down
Loading