LinkedAccountsPage.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. 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; }
  2. /*
  3. * Copyright 2019 Red Hat, Inc. and/or its affiliates.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import * as React from "../../../../common/keycloak/web_modules/react.js";
  18. import { withRouter } from "../../../../common/keycloak/web_modules/react-router-dom.js";
  19. import { Badge, Button, DataList, DataListAction, DataListItemCells, DataListCell, DataListItemRow, Stack, StackItem, Title, TitleLevel, DataListItem } from "../../../../common/keycloak/web_modules/@patternfly/react-core.js";
  20. 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";
  21. import { AccountServiceContext } from "../../account-service/AccountServiceContext.js";
  22. import { Msg } from "../../widgets/Msg.js";
  23. import { ContentPage } from "../ContentPage.js";
  24. import { createRedirect } from "../../util/RedirectUri.js";
  25. /**
  26. * @author Stan Silvert
  27. */
  28. class LinkedAccountsPage extends React.Component {
  29. constructor(props, context) {
  30. super(props);
  31. _defineProperty(this, "context", void 0);
  32. this.context = context;
  33. this.state = {
  34. linkedAccounts: [],
  35. unLinkedAccounts: []
  36. };
  37. this.getLinkedAccounts();
  38. }
  39. getLinkedAccounts() {
  40. this.context.doGet("/linked-accounts").then(response => {
  41. console.log({
  42. response
  43. });
  44. const linkedAccounts = response.data.filter(account => account.connected);
  45. const unLinkedAccounts = response.data.filter(account => !account.connected);
  46. this.setState({
  47. linkedAccounts: linkedAccounts,
  48. unLinkedAccounts: unLinkedAccounts
  49. });
  50. });
  51. }
  52. unLinkAccount(account) {
  53. const url = '/linked-accounts/' + account.providerName;
  54. this.context.doDelete(url).then(response => {
  55. console.log({
  56. response
  57. });
  58. this.getLinkedAccounts();
  59. });
  60. }
  61. linkAccount(account) {
  62. const url = '/linked-accounts/' + account.providerName;
  63. const redirectUri = createRedirect(this.props.location.pathname);
  64. this.context.doGet(url, {
  65. params: {
  66. providerId: account.providerName,
  67. redirectUri
  68. }
  69. }).then(response => {
  70. console.log({
  71. response
  72. });
  73. window.location.href = response.data.accountLinkUri;
  74. });
  75. }
  76. render() {
  77. return React.createElement(ContentPage, {
  78. title: Msg.localize('linkedAccountsTitle'),
  79. introMessage: Msg.localize('linkedAccountsIntroMessage')
  80. }, React.createElement(Stack, {
  81. gutter: "md"
  82. }, React.createElement(StackItem, {
  83. isFilled: true
  84. }, React.createElement(Title, {
  85. headingLevel: TitleLevel.h2,
  86. size: "2xl"
  87. }, React.createElement(Msg, {
  88. msgKey: "linkedLoginProviders"
  89. })), React.createElement(DataList, {
  90. id: "linked-idps",
  91. "aria-label": "foo"
  92. }, this.makeRows(this.state.linkedAccounts, true))), React.createElement(StackItem, {
  93. isFilled: true
  94. }), React.createElement(StackItem, {
  95. isFilled: true
  96. }, React.createElement(Title, {
  97. headingLevel: TitleLevel.h2,
  98. size: "2xl"
  99. }, React.createElement(Msg, {
  100. msgKey: "unlinkedLoginProviders"
  101. })), React.createElement(DataList, {
  102. id: "unlinked-idps",
  103. "aria-label": "foo"
  104. }, this.makeRows(this.state.unLinkedAccounts, false)))));
  105. }
  106. emptyRow(isLinked) {
  107. let isEmptyMessage = '';
  108. if (isLinked) {
  109. isEmptyMessage = Msg.localize('linkedEmpty');
  110. } else {
  111. isEmptyMessage = Msg.localize('unlinkedEmpty');
  112. }
  113. return React.createElement(DataListItem, {
  114. key: "emptyItem",
  115. "aria-labelledby": "empty-item"
  116. }, React.createElement(DataListItemRow, {
  117. key: "emptyRow"
  118. }, React.createElement(DataListItemCells, {
  119. dataListCells: [React.createElement(DataListCell, {
  120. key: "empty"
  121. }, React.createElement("strong", null, isEmptyMessage))]
  122. })));
  123. }
  124. makeRows(accounts, isLinked) {
  125. if (accounts.length === 0) {
  126. return this.emptyRow(isLinked);
  127. }
  128. return React.createElement(React.Fragment, null, " ", accounts.map(account => React.createElement(DataListItem, {
  129. id: `${account.providerAlias}-idp`,
  130. key: account.providerName,
  131. "aria-labelledby": "simple-item1"
  132. }, React.createElement(DataListItemRow, {
  133. key: account.providerName
  134. }, React.createElement(DataListItemCells, {
  135. dataListCells: [React.createElement(DataListCell, {
  136. key: "idp"
  137. }, React.createElement(Stack, null, React.createElement(StackItem, {
  138. isFilled: true
  139. }, this.findIcon(account)), React.createElement(StackItem, {
  140. id: `${account.providerAlias}-idp-name`,
  141. isFilled: true
  142. }, React.createElement("h2", null, React.createElement("strong", null, account.displayName))))), React.createElement(DataListCell, {
  143. key: "badge"
  144. }, React.createElement(Stack, null, React.createElement(StackItem, {
  145. isFilled: true
  146. }), React.createElement(StackItem, {
  147. id: `${account.providerAlias}-idp-badge`,
  148. isFilled: true
  149. }, this.badge(account)))), React.createElement(DataListCell, {
  150. key: "username"
  151. }, React.createElement(Stack, null, React.createElement(StackItem, {
  152. isFilled: true
  153. }), React.createElement(StackItem, {
  154. id: `${account.providerAlias}-idp-username`,
  155. isFilled: true
  156. }, account.linkedUsername)))]
  157. }), React.createElement(DataListAction, {
  158. "aria-labelledby": "foo",
  159. "aria-label": "foo action",
  160. id: "setPasswordAction"
  161. }, isLinked && React.createElement(Button, {
  162. id: `${account.providerAlias}-idp-unlink`,
  163. variant: "link",
  164. onClick: () => this.unLinkAccount(account)
  165. }, React.createElement(UnlinkIcon, {
  166. size: "sm"
  167. }), " ", React.createElement(Msg, {
  168. msgKey: "unLink"
  169. })), !isLinked && React.createElement(Button, {
  170. id: `${account.providerAlias}-idp-link`,
  171. variant: "link",
  172. onClick: () => this.linkAccount(account)
  173. }, React.createElement(LinkIcon, {
  174. size: "sm"
  175. }), " ", React.createElement(Msg, {
  176. msgKey: "link"
  177. })))))), " ");
  178. }
  179. badge(account) {
  180. if (account.social) {
  181. return React.createElement(Badge, null, React.createElement(Msg, {
  182. msgKey: "socialLogin"
  183. }));
  184. }
  185. return React.createElement(Badge, {
  186. style: {
  187. backgroundColor: "green"
  188. }
  189. }, React.createElement(Msg, {
  190. msgKey: "systemDefined"
  191. }));
  192. }
  193. findIcon(account) {
  194. const socialIconId = `${account.providerAlias}-idp-icon-social`;
  195. if (account.providerName.toLowerCase().includes('github')) return React.createElement(GithubIcon, {
  196. id: socialIconId,
  197. size: "xl"
  198. });
  199. if (account.providerName.toLowerCase().includes('linkedin')) return React.createElement(LinkedinIcon, {
  200. id: socialIconId,
  201. size: "xl"
  202. });
  203. if (account.providerName.toLowerCase().includes('facebook')) return React.createElement(FacebookIcon, {
  204. id: socialIconId,
  205. size: "xl"
  206. });
  207. if (account.providerName.toLowerCase().includes('google')) return React.createElement(GoogleIcon, {
  208. id: socialIconId,
  209. size: "xl"
  210. });
  211. if (account.providerName.toLowerCase().includes('instagram')) return React.createElement(InstagramIcon, {
  212. id: socialIconId,
  213. size: "xl"
  214. });
  215. if (account.providerName.toLowerCase().includes('microsoft')) return React.createElement(MicrosoftIcon, {
  216. id: socialIconId,
  217. size: "xl"
  218. });
  219. if (account.providerName.toLowerCase().includes('bitbucket')) return React.createElement(BitbucketIcon, {
  220. id: socialIconId,
  221. size: "xl"
  222. });
  223. if (account.providerName.toLowerCase().includes('twitter')) return React.createElement(TwitterIcon, {
  224. id: socialIconId,
  225. size: "xl"
  226. });
  227. if (account.providerName.toLowerCase().includes('openshift')) return React.createElement(OpenshiftIcon, {
  228. id: socialIconId,
  229. size: "xl"
  230. });
  231. if (account.providerName.toLowerCase().includes('gitlab')) return React.createElement(GitlabIcon, {
  232. id: socialIconId,
  233. size: "xl"
  234. });
  235. if (account.providerName.toLowerCase().includes('paypal')) return React.createElement(PaypalIcon, {
  236. id: socialIconId,
  237. size: "xl"
  238. });
  239. if (account.providerName.toLowerCase().includes('stackoverflow')) return React.createElement(StackOverflowIcon, {
  240. id: socialIconId,
  241. size: "xl"
  242. });
  243. return React.createElement(CubeIcon, {
  244. id: `${account.providerAlias}-idp-icon-default`,
  245. size: "xl"
  246. });
  247. }
  248. }
  249. _defineProperty(LinkedAccountsPage, "contextType", AccountServiceContext);
  250. ;
  251. const LinkedAccountsPagewithRouter = withRouter(LinkedAccountsPage);
  252. export { LinkedAccountsPagewithRouter as LinkedAccountsPage };
  253. //# sourceMappingURL=LinkedAccountsPage.js.map