-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c7196
commit 2c2f598
Showing
183 changed files
with
7,686 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { useGetResponse } from "../_index.ts"; | ||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { ApiUserInfoData } from "../_types.ts"; | ||
import { | ||
authState, | ||
firstAuthState, | ||
isNeedShowCreateProfileDialogAfterLdapRegistrationState, | ||
isRegistrationState, | ||
userInfoDataState, | ||
} from "../_stores.ts"; | ||
import { useSetAtom } from "jotai"; | ||
import useIsJoinLink from "../../lib/useIsJoinLink.ts"; | ||
import { useNavigateDialog, useNavigatePage } from "../../components/hooks.ts"; | ||
|
||
export type ApiFederationLdapAuthTryAuthenticateArgs = { | ||
username: string; | ||
password: string; | ||
}; | ||
|
||
export type ApiFederationLdapAuthTryAuthenticate = { | ||
ldap_auth_token: string; | ||
}; | ||
|
||
export function useApiFederationLdapAuthTryAuthenticate() { | ||
const getResponse = useGetResponse("federation"); | ||
|
||
return useMutation({ | ||
retry: false, | ||
networkMode: "always", | ||
mutationFn: async ({ username, password }: ApiFederationLdapAuthTryAuthenticateArgs) => { | ||
const body = new URLSearchParams({ | ||
username: username, | ||
password: password, | ||
}); | ||
|
||
return await getResponse<ApiFederationLdapAuthTryAuthenticate>("ldap/auth/tryAuthenticate", body); | ||
}, | ||
}); | ||
} | ||
|
||
export type ApiPivotAuthLdapBeginArgs = { | ||
ldap_auth_token: string; | ||
join_link?: string; | ||
}; | ||
|
||
export type ApiPivotAuthLdapBegin = { | ||
authentication_token: string; | ||
need_fill_profile: 0 | 1; | ||
user_info: ApiUserInfoData; | ||
}; | ||
|
||
export function useApiPivotAuthLdapBegin() { | ||
const getResponse = useGetResponse("pivot"); | ||
const setAuth = useSetAtom(authState); | ||
const setFirstAuth = useSetAtom(firstAuthState); | ||
const setUserInfoDataState = useSetAtom(userInfoDataState); | ||
const setIsNeedShowCreateProfileDialogAfterLdapRegistration = useSetAtom( | ||
isNeedShowCreateProfileDialogAfterLdapRegistrationState | ||
); | ||
const setRegistrationState = useSetAtom(isRegistrationState); | ||
const queryClient = useQueryClient(); | ||
const isJoinLink = useIsJoinLink(); | ||
const { navigateToDialog } = useNavigateDialog(); | ||
const { navigateToPage } = useNavigatePage(); | ||
|
||
return useMutation({ | ||
retry: false, | ||
networkMode: "always", | ||
mutationFn: async ({ ldap_auth_token, join_link }: ApiPivotAuthLdapBeginArgs) => { | ||
const body = new URLSearchParams({ | ||
ldap_auth_token: ldap_auth_token, | ||
}); | ||
|
||
if (join_link !== undefined && /join\/[a-zA-Z0-9]+\/?/.test(join_link)) { | ||
body.append("join_link", join_link); | ||
} | ||
|
||
return getResponse<ApiPivotAuthLdapBegin>("auth/ldap/begin", body, {}); | ||
}, | ||
|
||
async onSuccess(response) { | ||
setFirstAuth(true); | ||
if (response.need_fill_profile === 1) { | ||
setRegistrationState(true); | ||
setIsNeedShowCreateProfileDialogAfterLdapRegistration(true); | ||
} | ||
|
||
await queryClient.invalidateQueries({ queryKey: ["global/start"] }); | ||
if (isJoinLink) { | ||
await queryClient.invalidateQueries({ queryKey: ["joinlink/prepare", window.location.href] }); | ||
} | ||
|
||
setAuth(null); | ||
setUserInfoDataState(response.user_info); | ||
|
||
if (response.need_fill_profile === 1) { | ||
navigateToPage("auth"); | ||
navigateToDialog("auth_create_profile"); | ||
} else { | ||
navigateToPage("token"); | ||
navigateToDialog("token_page"); | ||
} | ||
}, | ||
}); | ||
} |
Oops, something went wrong.