Skip to content

Commit 336b6da

Browse files
Merge pull request #459 from topcoder-platform/dev
2.6 Wipro DICE IDs Release - 2023-01-04 -> master
2 parents e4cb992 + 91a1f42 commit 336b6da

File tree

19 files changed

+209
-32
lines changed

19 files changed

+209
-32
lines changed

src-ts/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ module.exports = {
251251
2,
252252
4,
253253
],
254+
'react/jsx-no-bind': [
255+
'error',
256+
{
257+
allowFunctions: true,
258+
}
259+
],
254260
'react/jsx-no-useless-fragment': [
255261
0
256262
],

src-ts/config/environments/environment.default.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const EnvironmentConfigDefault: EnvironmentConfigModel = {
3636
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJ0ZXN0MSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzMiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoidGVzdEB0b3Bjb2Rlci5jb20iLCJqdGkiOiJiMzNiNzdjZC1iNTJlLTQwZmUtODM3ZS1iZWI4ZTBhZTZhNGEifQ.jl6Lp_friVNwEP8nfsfmL-vrQFzOFp2IfM_HC7AwGcg',
3737
},
3838
TOPCODER_URLS: {
39+
ACCOUNT_SETTINGS: `${COMMUNITY_WEBSITE}/settings/account`,
3940
API_BASE: `${COMMUNITY_WEBSITE}/api`,
4041
BLOG_PAGE: `${COMMUNITY_WEBSITE}/blog`,
4142
CHALLENGES_PAGE: `${COMMUNITY_WEBSITE}/challenges`,

src-ts/config/environments/environment.prod.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const EnvironmentConfigProd: EnvironmentConfigModel = {
3434
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJ0ZXN0MSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzMiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoidGVzdEB0b3Bjb2Rlci5jb20iLCJqdGkiOiJiMzNiNzdjZC1iNTJlLTQwZmUtODM3ZS1iZWI4ZTBhZTZhNGEifQ.jl6Lp_friVNwEP8nfsfmL-vrQFzOFp2IfM_HC7AwGcg',
3535
},
3636
TOPCODER_URLS: {
37+
ACCOUNT_SETTINGS: `${COMMUNITY_WEBSITE}/settings/account`,
3738
API_BASE: `${COMMUNITY_WEBSITE}/api`,
3839
BLOG_PAGE: `${COMMUNITY_WEBSITE}/blog`,
3940
CHALLENGES_PAGE: `${COMMUNITY_WEBSITE}/challenges`,

src-ts/lib/functions/token-functions/token.functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export async function getAsync(): Promise<TokenModel> {
1515
}
1616

1717
try {
18-
const { handle, roles }: {
18+
const { handle, roles, userId }: {
1919
handle?: string
2020
roles?: Array<string>
21+
userId?: number
2122
} = decodeToken(token)
2223

2324
// if we didn't find the handle, we have a bad token
@@ -26,8 +27,9 @@ export async function getAsync(): Promise<TokenModel> {
2627
return Promise.resolve({})
2728
}
2829

29-
return Promise.resolve({ handle, roles, token })
30+
return Promise.resolve({ handle, roles, token, userId })
3031

32+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3133
} catch (error: any) {
3234
logError(error)
3335
return Promise.resolve({})

src-ts/lib/functions/token-functions/token.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export interface TokenModel {
22
handle?: string
33
roles?: Array<string>
44
token?: string
5+
userId?: number
56
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { updatePasswordAsync as userUpdatePasswordAsync } from './user.functions'
1+
export {
2+
getDiceStatusAsync as userGetDiceStatusAsync,
3+
updatePasswordAsync as userUpdatePasswordAsync,
4+
} from './user.functions'
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
export { patchAsync as userPatchAsync } from './user-xhr.store'
1+
export {
2+
getMfaStatusAsync as userStoreGetMfaStatusAsync,
3+
patchAsync as userStorePatchAsync,
4+
} from './user-xhr.store'
25
export { type UserPatchRequest } from './user-xhr.store'

src-ts/lib/functions/user-functions/user-store/user-xhr.store.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { User } from '../../../../../types/tc-auth-lib'
2-
import { xhrPatchAsync } from '../../xhr-functions'
2+
import { xhrGetAsync, xhrPatchAsync } from '../../xhr-functions'
33

44
import { user as userEndpoint } from './user-endpoint.config'
55

6+
export interface MfaStatusResult {
7+
result: {
8+
content: {
9+
diceEnabled: boolean
10+
mfaEnabled: boolean
11+
}
12+
}
13+
}
14+
615
export interface UserPatchRequest {
716
param: {
817
credential: {
@@ -12,6 +21,10 @@ export interface UserPatchRequest {
1221
}
1322
}
1423

24+
export async function getMfaStatusAsync(userId: number): Promise<MfaStatusResult> {
25+
return xhrGetAsync<MfaStatusResult>(`${userEndpoint(userId)}/2fa`)
26+
}
27+
1528
export async function patchAsync(userId: number, request: UserPatchRequest): Promise<User> {
1629
const url: string = userEndpoint(userId)
1730
return xhrPatchAsync(url, request)

src-ts/lib/functions/user-functions/user.functions.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { userPatchAsync, UserPatchRequest } from './user-store'
1+
import { UserPatchRequest, userStoreGetMfaStatusAsync, userStorePatchAsync } from './user-store'
2+
import { MfaStatusResult } from './user-store/user-xhr.store'
3+
4+
export async function getDiceStatusAsync(userId: number): Promise<boolean> {
5+
const result: MfaStatusResult = await userStoreGetMfaStatusAsync(userId)
6+
return !!result.result.content.mfaEnabled && !!result.result.content.diceEnabled
7+
}
28

39
export async function updatePasswordAsync(userId: number, currentPassword: string, password: string): Promise<void> {
410
const request: UserPatchRequest = {
@@ -9,6 +15,6 @@ export async function updatePasswordAsync(userId: number, currentPassword: strin
915
},
1016
},
1117
}
12-
return userPatchAsync(userId, request)
18+
return userStorePatchAsync(userId, request)
1319
.then(() => undefined)
1420
}

src-ts/lib/global-config.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface GlobalConfig {
2929
CUSTOMER_TOKEN: string
3030
}
3131
TOPCODER_URLS: {
32+
ACCOUNT_SETTINGS: string
3233
API_BASE: string
3334
BLOG_PAGE: string
3435
CHALLENGES_PAGE: string

0 commit comments

Comments
 (0)