Skip to content

Commit

Permalink
Improved: support to not let user move around launchpad until passwor…
Browse files Browse the repository at this point in the history
…d is not changed(hotwax#63)
  • Loading branch information
ymaheshwari1 committed Oct 26, 2023
1 parent 81ed2e0 commit 4a671a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const authGuard = async (to: any, from: any, next: any) => {
next()
};

const resetGuard = async (to: any, from: any, next: any) => {
const authStore = useAuthStore()
if (authStore.requirePasswordChange) {
next('/resetPassword')
}
next()
};

const routes: Array<RouteRecordRaw> = [
{
path: '/',
Expand All @@ -30,6 +38,7 @@ const routes: Array<RouteRecordRaw> = [
path: '/home',
name: 'Home',
component: Home,
beforeEnter: resetGuard
},
{
path: '/login',
Expand Down
8 changes: 3 additions & 5 deletions src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const useAuthStore = defineStore('authStore', {
value: '',
expiration: undefined
},
redirectUrl: ''
redirectUrl: '',
requirePasswordChange: false // denotes if password change is required for the user
}),
getters: {
isAuthenticated: (state) => {
Expand Down Expand Up @@ -41,7 +42,6 @@ export const useAuthStore = defineStore('authStore', {
this.redirectUrl = redirectUrl
},
async login(username: string, password: string) {
let requirePasswordChange = false; // denotes if password change is required for the user
try {
const resp = await UserService.login(username, password);
if (hasError(resp)) {
Expand All @@ -55,7 +55,7 @@ export const useAuthStore = defineStore('authStore', {
expiration: resp.data.expirationTime
}

requirePasswordChange = resp.data.requirePasswordChange
this.requirePasswordChange = resp.data.requirePasswordChange

this.current = await UserService.getUserProfile(this.token.value);
updateToken(this.token.value)
Expand All @@ -71,8 +71,6 @@ export const useAuthStore = defineStore('authStore', {
console.error("error: ", error);
return Promise.reject(new Error(error))
}

return requirePasswordChange;
},
async samlLogin(token: string, expirationTime: string) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ export default defineComponent({
}
try {
const requirePasswordChange = await this.authStore.login(username.trim(), password)
await this.authStore.login(username.trim(), password)
// when password needs to be changed, redirecting the user to reset page
if(requirePasswordChange) {
if(this.authStore.requirePasswordChange) {
this.username = ''
this.password = ''
this.router.push('/resetPassword');
Expand Down
4 changes: 3 additions & 1 deletion src/views/ResetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ion-item>
<ion-item lines="none">
<ion-label position="fixed">{{ $t("Confirm Password") }}</ion-label>
<ion-input @ionFocus="passwordMatchError = false" name="confirmPassword" v-model="confirmPassword" id="confirmPassword" :type="showConfirmPassword ? 'text' : 'password'" error-text="Please enter password" />
<ion-input @ionFocus="passwordMatchError = false" name="confirmPassword" v-model="confirmPassword" id="confirmPassword" :type="showConfirmPassword ? 'text' : 'password'"/>
<ion-button fill="clear" @click="showConfirmPassword = !showConfirmPassword">
<ion-icon :icon="showConfirmPassword ? eyeOutline : eyeOffOutline"/>
</ion-button>
Expand Down Expand Up @@ -118,6 +118,8 @@ export default defineComponent({
const resp = await UserService.resetPassword(params);
if(!hasError(resp) && resp?.data?.successMessage) {
// once password is changed, resetting the value to false
this.authStore.requirePasswordChange = false;
if (this.authStore.getRedirectUrl) {
window.location.href = `${this.authStore.getRedirectUrl}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}`
} else {
Expand Down

0 comments on commit 4a671a1

Please sign in to comment.