123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- /*
- * Copyright 2019 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import * as React from "../../../../common/keycloak/web_modules/react.js";
- import { withRouter } from "../../../../common/keycloak/web_modules/react-router-dom.js";
- import { Badge, Button, DataList, DataListAction, DataListItemCells, DataListCell, DataListItemRow, Stack, StackItem, Title, TitleLevel, DataListItem } from "../../../../common/keycloak/web_modules/@patternfly/react-core.js";
- import { BitbucketIcon, CubeIcon, FacebookIcon, GithubIcon, GitlabIcon, GoogleIcon, InstagramIcon, LinkIcon, LinkedinIcon, MicrosoftIcon, OpenshiftIcon, PaypalIcon, StackOverflowIcon, TwitterIcon, UnlinkIcon } from "../../../../common/keycloak/web_modules/@patternfly/react-icons.js";
- import { AccountServiceContext } from "../../account-service/AccountServiceContext.js";
- import { Msg } from "../../widgets/Msg.js";
- import { ContentPage } from "../ContentPage.js";
- import { createRedirect } from "../../util/RedirectUri.js";
- /**
- * @author Stan Silvert
- */
- class LinkedAccountsPage extends React.Component {
- constructor(props, context) {
- super(props);
- _defineProperty(this, "context", void 0);
- this.context = context;
- this.state = {
- linkedAccounts: [],
- unLinkedAccounts: []
- };
- this.getLinkedAccounts();
- }
- getLinkedAccounts() {
- this.context.doGet("/linked-accounts").then(response => {
- console.log({
- response
- });
- const linkedAccounts = response.data.filter(account => account.connected);
- const unLinkedAccounts = response.data.filter(account => !account.connected);
- this.setState({
- linkedAccounts: linkedAccounts,
- unLinkedAccounts: unLinkedAccounts
- });
- });
- }
- unLinkAccount(account) {
- const url = '/linked-accounts/' + account.providerName;
- this.context.doDelete(url).then(response => {
- console.log({
- response
- });
- this.getLinkedAccounts();
- });
- }
- linkAccount(account) {
- const url = '/linked-accounts/' + account.providerName;
- const redirectUri = createRedirect(this.props.location.pathname);
- this.context.doGet(url, {
- params: {
- providerId: account.providerName,
- redirectUri
- }
- }).then(response => {
- console.log({
- response
- });
- window.location.href = response.data.accountLinkUri;
- });
- }
- render() {
- return React.createElement(ContentPage, {
- title: Msg.localize('linkedAccountsTitle'),
- introMessage: Msg.localize('linkedAccountsIntroMessage')
- }, React.createElement(Stack, {
- gutter: "md"
- }, React.createElement(StackItem, {
- isFilled: true
- }, React.createElement(Title, {
- headingLevel: TitleLevel.h2,
- size: "2xl"
- }, React.createElement(Msg, {
- msgKey: "linkedLoginProviders"
- })), React.createElement(DataList, {
- id: "linked-idps",
- "aria-label": "foo"
- }, this.makeRows(this.state.linkedAccounts, true))), React.createElement(StackItem, {
- isFilled: true
- }), React.createElement(StackItem, {
- isFilled: true
- }, React.createElement(Title, {
- headingLevel: TitleLevel.h2,
- size: "2xl"
- }, React.createElement(Msg, {
- msgKey: "unlinkedLoginProviders"
- })), React.createElement(DataList, {
- id: "unlinked-idps",
- "aria-label": "foo"
- }, this.makeRows(this.state.unLinkedAccounts, false)))));
- }
- emptyRow(isLinked) {
- let isEmptyMessage = '';
- if (isLinked) {
- isEmptyMessage = Msg.localize('linkedEmpty');
- } else {
- isEmptyMessage = Msg.localize('unlinkedEmpty');
- }
- return React.createElement(DataListItem, {
- key: "emptyItem",
- "aria-labelledby": "empty-item"
- }, React.createElement(DataListItemRow, {
- key: "emptyRow"
- }, React.createElement(DataListItemCells, {
- dataListCells: [React.createElement(DataListCell, {
- key: "empty"
- }, React.createElement("strong", null, isEmptyMessage))]
- })));
- }
- makeRows(accounts, isLinked) {
- if (accounts.length === 0) {
- return this.emptyRow(isLinked);
- }
- return React.createElement(React.Fragment, null, " ", accounts.map(account => React.createElement(DataListItem, {
- id: `${account.providerAlias}-idp`,
- key: account.providerName,
- "aria-labelledby": "simple-item1"
- }, React.createElement(DataListItemRow, {
- key: account.providerName
- }, React.createElement(DataListItemCells, {
- dataListCells: [React.createElement(DataListCell, {
- key: "idp"
- }, React.createElement(Stack, null, React.createElement(StackItem, {
- isFilled: true
- }, this.findIcon(account)), React.createElement(StackItem, {
- id: `${account.providerAlias}-idp-name`,
- isFilled: true
- }, React.createElement("h2", null, React.createElement("strong", null, account.displayName))))), React.createElement(DataListCell, {
- key: "badge"
- }, React.createElement(Stack, null, React.createElement(StackItem, {
- isFilled: true
- }), React.createElement(StackItem, {
- id: `${account.providerAlias}-idp-badge`,
- isFilled: true
- }, this.badge(account)))), React.createElement(DataListCell, {
- key: "username"
- }, React.createElement(Stack, null, React.createElement(StackItem, {
- isFilled: true
- }), React.createElement(StackItem, {
- id: `${account.providerAlias}-idp-username`,
- isFilled: true
- }, account.linkedUsername)))]
- }), React.createElement(DataListAction, {
- "aria-labelledby": "foo",
- "aria-label": "foo action",
- id: "setPasswordAction"
- }, isLinked && React.createElement(Button, {
- id: `${account.providerAlias}-idp-unlink`,
- variant: "link",
- onClick: () => this.unLinkAccount(account)
- }, React.createElement(UnlinkIcon, {
- size: "sm"
- }), " ", React.createElement(Msg, {
- msgKey: "unLink"
- })), !isLinked && React.createElement(Button, {
- id: `${account.providerAlias}-idp-link`,
- variant: "link",
- onClick: () => this.linkAccount(account)
- }, React.createElement(LinkIcon, {
- size: "sm"
- }), " ", React.createElement(Msg, {
- msgKey: "link"
- })))))), " ");
- }
- badge(account) {
- if (account.social) {
- return React.createElement(Badge, null, React.createElement(Msg, {
- msgKey: "socialLogin"
- }));
- }
- return React.createElement(Badge, {
- style: {
- backgroundColor: "green"
- }
- }, React.createElement(Msg, {
- msgKey: "systemDefined"
- }));
- }
- findIcon(account) {
- const socialIconId = `${account.providerAlias}-idp-icon-social`;
- if (account.providerName.toLowerCase().includes('github')) return React.createElement(GithubIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('linkedin')) return React.createElement(LinkedinIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('facebook')) return React.createElement(FacebookIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('google')) return React.createElement(GoogleIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('instagram')) return React.createElement(InstagramIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('microsoft')) return React.createElement(MicrosoftIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('bitbucket')) return React.createElement(BitbucketIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('twitter')) return React.createElement(TwitterIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('openshift')) return React.createElement(OpenshiftIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('gitlab')) return React.createElement(GitlabIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('paypal')) return React.createElement(PaypalIcon, {
- id: socialIconId,
- size: "xl"
- });
- if (account.providerName.toLowerCase().includes('stackoverflow')) return React.createElement(StackOverflowIcon, {
- id: socialIconId,
- size: "xl"
- });
- return React.createElement(CubeIcon, {
- id: `${account.providerAlias}-idp-icon-default`,
- size: "xl"
- });
- }
- }
- _defineProperty(LinkedAccountsPage, "contextType", AccountServiceContext);
- ;
- const LinkedAccountsPagewithRouter = withRouter(LinkedAccountsPage);
- export { LinkedAccountsPagewithRouter as LinkedAccountsPage };
- //# sourceMappingURL=LinkedAccountsPage.js.map
|